当我们购买一台VPS之后,需要为服务器安装网站环境才能安装WordPress,通常情况下,建议新手直接安装宝塔面板,如果服务器只打算安装一个网站,或者说服务器配置较低,建议大家直接安装不带面板的LNMP环境,也就是Linux+Nginx+MySQL+PHP。
本文将以Debian 12为例子为大家介绍如何手动安装LNMP环境,并且安装好WordPress网站。
一、购买VPS
想要安装LNMP环境,我们需要购买一台VPS才行,可以选腾讯云、阿里云、华为云等等,方法都一样,只需要确保VPS系统是Debian 12就可以了。
二、连接VPS
连接VPS我们依然是需要用到SSH软件,这里推荐的是putty,如果你是Mac用户,可以直接使用系统自带的终端功能。
三、开始安装LNMP环境
连接上VPS之后,我们先更新一下系统组件,使用下面的命令。
apt update -y && apt upgrade -y
接着输入下面的命令安装PHP和相关组件
apt install php-fpm php-mysql php-gd php-cli php-curl php-mbstring php-zip php-opcache php-xml php-mysqli -y
接着安装NGINX
apt install nginx -y
接着安装MariaDB,网上一些资料说MariaDB与MySQL相比,它的性能更高,复制速度更快,安全措施更好,还有额外的存储引擎。
apt install mariadb-server -y
使用mysql_secure_installation脚本来提高数据库安全性。
mysql_secure_installation
输入这个命令后,有一些英文的引导提示,首先按回车,然后带有[Y/n]的提示都按Y即可。
如果你不认识英文,只需要记住下面这里是让你设置新数据库密码。
Change the root password? [Y/n] y
New password:
输入的密码信息不会显示,自己要记住别忘了。
创建数据库
接下来我们就要为安装WordPress做准备了,首先创建一个数据库。
mysql -uroot -p
输入上面的命令之后,需要验证数据库管理员密码。然后进入输入命令的界面,依次输入下面的命令。
CREATE DATABASE XX_db;
CREATE USER db_user@localhost IDENTIFIED BY 'password';
GRANT ALL ON XX_db.* TO db_user@localhost;
FLUSH PRIVILEGES;
这些代码中,XX_db是你要创建的数据库名字,db_user是你创建的数据库用户名,password是数据库密码。根据自己需要修改。
配置NGINX
首先,为我们的网站创建一个存放文件的目录,也就是网站根目录文件夹。
mkdir -p /var/www/html/wordpress
创建虚拟主机配置文件
vi /etc/nginx/sites-available/wordpress
接着按i,把下面的内容粘贴进去之后,按ESC键输入:wq保存
server {
listen 80;
server_name _;
root /var/www/html/wordpress;
index index.html;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ =404;
}
location ~* \.php$ {
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
include snippets/fastcgi-php.conf;
}
}
创建软连接
ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
删除默认站点
rm /etc/nginx/sites-enabled/default
验证NGINX配置
nginx -t
重启NGINX
systemctl restart nginx
配置SSL安全证书
这个时候,在浏览器打开你的网站,会出现下面这个截图,我们先安装好安全证书之后再去安装WordPress。
首先安装snapd
apt install snapd -y
后面时间久了如果需要更新snapd,则使用下面的命令
snap install core; snap refresh core
安装 Certbot
snap install --classic certbot
运行certbot申请SSL安全证书
/snap/bin/certbot --nginx -d test.com
输入命令后,需要你输入一个邮箱地址,回车之后几个提示直接按Y回车。
后面需要为SSL续签的时候,运行下面的命令
certbot renew
申请完毕后,打开网站就可以看到是一把小锁了。
四、安装WordPress网站程序
切换到网站根目录
cd /var/www/html/wordpress/
wget下载wordpress安装包文件
wget https://wordpress.org/latest.zip
解压安装包
unzip latest.zip
如果提示命令不存在,先安装apt install unzip -y
进入解压出来的文件夹,移动所有文件到上级目录,切换到上级目录。
cd wordpress
mv * ..
cd ..
修改文件权限
chmod -R 755 /var/www/html/test.com/public_html
chown -R www-data:www-data /var/www/html/test.com/public_html
打开你网址进入WordPress安装界面。
五、配置伪静态规则
如果你会vi编辑器,可以直接vi /etc/nginx/sites-available/wordpress
替换掉下图中框出来的部分代码。
location / { index index.php index.html index.htm; try_files $uri $uri/ /index.php?$args; } # Add trailing slash to */wp-admin requests. rewrite /wp-admin$ $scheme://$host$uri/ permanent;
保存之后上传到服务器覆盖原文件。
接着putty终端里面输入systemctl restart nginx
重启完毕后,刷新你网页,伪静态就起作用了。
以上就是纯手工安装LNMP环境然后安装WordPress的方法了
六、其他相关命令
如何重启php?
首先输入php -v查看你的php版本,提示如下:
php -v
PHP 8.2.20 (cli) (built: Jun 17 2024 13:33:14) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.20, Copyright (c) Zend Technologies
with Zend OPcache v8.2.20, Copyright (c), by Zend Technologies
证明安装的是php8.2版本,那么则输入下面命令重启PHP
systemctl restart php8.2-fpm
PHP.INI文件在什么位置?
/etc/php/你php版本号文件夹/fpm/php.ini
怎么重启数据库?
systemctl restart mariadb
文章评论
Watch the best product video reviews, for better understanding.
bush river books & video reviews <a href=https://movies-and-reviews.com/shopaholics-guide-reviews-of-top-global-retailers/>https://movies-and-reviews.com/shopaholics-guide-reviews-of-top-global-retailers/</a> .
popular brands and style,
brands similar to west elm <a href=exlinecountrystore.com>exlinecountrystore.com</a> .
Top 20 famous brands for your style, that will help you stand out from the crowd.
american life style <a href=https://jimgrayonline.com>https://jimgrayonline.com</a> .
The role of creativity in problem-solving, inspiring creativity in the workplace, Techniques for enhancing creative thinking, Creativity as a path to fulfillment, The transformative power of creativity, how to define creativity for yourself.
creativity coach <a href=http://www.brus-online.com/collaboration-and-creativity-harnessing-the-power-of-teamwork/>http://www.brus-online.com/collaboration-and-creativity-harnessing-the-power-of-teamwork/</a> .
Inmolux Group Costa del Sol: favorable terms for buying and selling, invest smartly with us.
property project management <a href=https://traffic-arbitrage.com/en/services/project-management/>property project management</a> .
Reliable service for maintaining heating and cooling systems, guaranteeing comfort in your home.
heating unit maintenance <a href=https://www.bestweddingcinema.com/heating-services/heating-maintenance.html>https://www.bestweddingcinema.com/heating-services/heating-maintenance.html</a> .
Будьте уверены в гладкой коже, профессиональная эпиляция лазером.
эпиляция рук цена <a href=http://www.octoclick-tizer.com/lazernaya-kosmetologiya/lazernaya-epilyaciya/ruki>http://www.octoclick-tizer.com/lazernaya-kosmetologiya/lazernaya-epilyaciya/ruki</a> .
An unforgettable experience with car rental,
g wagen rental <a href=https://www.bestwedding-video.com/cars/g63>https://www.bestwedding-video.com/cars/g63</a> .
Revolutionary new products that will shape tomorrow, futuristic gadgets you'll want to get your hands on.
new inventions <a href=washingtondchotelsonline.com>washingtondchotelsonline.com</a> .
Stay ahead with breaking news from around the world, click here for more.
Important global news stories you need to know, click to read more.
Stay informed on international events that affect you, find out now.
Be the first to know with global news alerts, click here for more.
global news articles 2024 <a href=http://www.pick-news.com>http://www.pick-news.com</a> .
Rent a car for a day, a week, or longer, Rent a car quickly and easily, Discover affordable car rental near me, Get a rental car from a nearby location, Get a quality rental car for your trip, Save money on your rental car booking.
toyota vitz rental <a href=http://www.best-carrental.com/our-cars/?view=cardetails&carid=7>http://www.best-carrental.com/our-cars/?view=cardetails&carid=7</a> .
Car rental for special occasions
rent mercedes benz g63 <a href=http://www.trafficarbitration.com/cars/g63/>http://www.trafficarbitration.com/cars/g63/</a> .
Efficient maintenance of heating and air conditioning systems, The best specialists in heating and air conditioning
air conditioning unit maintenance <a href=best-lip-filler.com>best-lip-filler.com /air-conditioning-services/air-conditioning-maintenance.html</a> .
Exclusive coins for commanders, that should be added to the collection.
The significance of command coins, and how they help strengthen team spirit.
personalized challenge coin <a href=https://command-coins.com/>personalized challenge coin</a> .
Improve your home with products from Republic Windows and Doors, that will provide you with quality windows and doors for many years.
Choose quality and style with Republic Windows and Doors, to give your home a special charm and style.
door & window company <a href=finexmolicense.com>finexmolicense.com</a> .
Купить сервер HP Proliant недорого, Надежный сервер HP Proliant с гарантией качества
серверы hp купить <a href=https://www.servera-hp-proliant.ru>https://www.servera-hp-proliant.ru</a> .
Business opportunities in real estate on the Costa del Sol.
real estate redevelopment <a href=https://villas-in-spain.com/projects/>real estate redevelopment</a> .