
前言:WordPress安装及初始化,安装 Nginx 和 PHP。
Tips:以下命令为centos7为例
yum -y update
yum -y install epel-release
yum -y install nginxnginx -v显示:
nginx version: nginx/1.20.1systemctl start nginxyum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum -y install yum-utils
yum-config-manager --enable remi-php74
yum install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-jsonvim /etc/nginx/nginx.confserver部分中添加以下内容设置默认首页。location / {
index index.php index.html index.htm;
}
location ~ .php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}这段Nginx配置块是用来处理PHP文件的。
location ~ .php$ {: 此行指定了一个location块,用于匹配以.php结尾的所有请求。~表示进行正则表达式匹配。
root /usr/share/nginx/html;: 指定了Nginx在服务器上查找文件的根目录。在这个例子中,根目录是/usr/share/nginx/html。这是你之前解压WordPress文件的地方。
fastcgi_pass 127.0.0.1:9000;: 指定了FastCGI服务器的地址和端口。这是PHP-FPM(FastCGI Process Manager)的地址和端口,Nginx通过FastCGI协议与PHP-FPM通信来处理PHP脚本。
fastcgi_index index.php;: 指定了默认的索引文件,当请求目录时,Nginx会尝试查找index.php文件。
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;: 设置FastCGI参数,告诉PHP解释器当前脚本的文件路径。
include fastcgi_params;: 包含fastcgi_params文件中定义的其他FastCGI参数。这个配置块的目的是将与PHP相关的请求传递给PHP解释器,以便执行PHP脚本。确保这个配置块在你的Nginx主配置文件或虚拟主机配置中正确设置,以确保Nginx正确地与PHP-FPM通信并解析PHP文件
如图所示:

Enter键,保存文件并返回。index.php测试文件,验证环境是否安装成功。vim /usr/share/nginx/html/index.php<?php echo phpinfo(); ?> #phpinfo()会展示PHP的所有配置信息Enter键,保存文件并返回。nginx -tnginx -s reloadsystemctl start php-fpmhttp://<IP地址>/,回显如下,表示PHP环境配置成功。
cd /usr/share/nginx/htmlwget https://wordpress.org/latest.tar.gztar -xzvf latest.tar.gzcd /usr/share/nginx/html/wordpresscp wp-config-sample.php wp-config.phpvi wp-config.php/** The name of the database for WordPress */
define('DB_NAME', 'MySQL的名称');
/** MySQL database username */
define('DB_USER', 'MySQL的用户名');
/** MySQL database password */
define('DB_PASSWORD', 'MySQL用户密码');
/** MySQL hostname */
define( 'DB_HOST', 'MySQL的地址' );
/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );
/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );Enter键,保存文件并返回。在本地浏览器中输入http://<IP地址>/wordpress访问WordPress网站。
回显如下,表示WordPress搭建完成。

填写网站基本信息,单击“安装WordPress”按钮。
信息 | 说明 |
|---|---|
站点标题 | WordPress网站的名称。 |
用户名 | 登录WordPress网站的用户名。 |
密码 | 登录WordPress网站的密码。 |
您的电子邮箱地址 | 用于接收通知的电子邮件地址。 |
http://<IP地址>/wordpress/http://<IP地址>/wordpress/wp-admin/原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。