1、使用yum安装Nginx
yum install nginx
2、启动Nginx服务
systemctl start nginx
注:此时浏览器访问IP即可访问Nginx默认页面
3、使用yum安装php
yum install php
4、使用yum安装php相关扩展
yum install php-fpm php-mysql php-xml php-mbstring php-openssl php-gd php-pecl-zip
5、使用yum安装mysql
rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
yum install mysql-community-server
yum install mysql-community-client
6、配置Nginx
学习 vi 的基本操作
使用vi编辑/etc/nginx/conf.d/default.conf文件
vi /etc/nginx/conf.d/default.conf
在最上面添加如下代码并保存:
<pre>
server
{
listen 80;
#listen 443 ssl;
server_name 127.0.0.1 localhost;
index index.php index.html index.htm default.php default.htm default.html;
root /www/website/public; #设置网站根目录,根据网站位置,自行修改
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
#ssl_certificate /etc/letsencrypt/live/core.admin.bchalo.com/fullchain.pem;
#ssl_certificate_key /etc/letsencrypt/live/core.admin.bchalo.com/privkey.pem;
#if (\$server_port !~ 443){
# rewrite ^(/.*)\$ https://\$host$1 permanent;
#}
#error_page 497 https://\$host\$request_uri;
#SSL-END
#ERROR-PAGE-START 错误页配置,可以注释、删除或修改
#error_page 404 /404.html;
#error_page 502 /502.html;
#ERROR-PAGE-END
#跨域请求设置
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'accept, content-type,UserToken,Flag';
#Thinkphp的URL重写规则
if (!-e \$request_filename) {
rewrite ^(.*)\$ /index.php?s=/\$1 last;
break;
}
#PHP-INFO-START PHP引用配置,可以注释或修改
#include enable-php-71.conf;
location ~ [^/]\.php(/|\$)
{
try_files \$uri =404;
# fastcgi_pass unix:/tmp/php-cgi-71.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# FastCGI
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
fastcgi_param QUERY_STRING \$query_string;
fastcgi_param REQUEST_METHOD \$request_method;
fastcgi_param CONTENT_TYPE \$content_type;
fastcgi_param CONTENT_LENGTH \$content_length;
fastcgi_param SCRIPT_NAME \$fastcgi_script_name;
fastcgi_param REQUEST_URI \$request_uri;
fastcgi_param DOCUMENT_URI \$document_uri;
fastcgi_param DOCUMENT_ROOT \$document_root;
fastcgi_param SERVER_PROTOCOL \$server_protocol;
fastcgi_param HTTPS \$https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/\$nginx_version;
fastcgi_param REMOTE_ADDR \$remote_addr;
fastcgi_param REMOTE_PORT \$remote_port;
fastcgi_param SERVER_ADDR \$server_addr;
fastcgi_param SERVER_PORT \$server_port;
fastcgi_param SERVER_NAME \$server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
# PATHINFO
set \$real_script_name \$fastcgi_script_name;
if (\$fastcgi_script_name ~ "^(.+?\.php)(/.+)\$") {
set \$real_script_name \$1;
set \$path_info \$2;
}
fastcgi_param SCRIPT_FILENAME \$document_root\$real_script_name;
fastcgi_param SCRIPT_NAME \$real_script_name;
fastcgi_param PATH_INFO \$path_info;
}
#PHP-INFO-END
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)\$
{
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?\$
{
expires 12h;
access_log off;
}
access_log /www/nginx/log/$1.log;
}
</pre>
7、运行PHP
systemctl restart nginx
systemctl start php-fpm
systemctl start mysqld
8、MySql初始设置
使用cat /var/log/mysqld.log查看Root初始化密码
登入MySQL:
mysql -uroot -p
使用以下命令设置root密码:
SET GLOBAL validate_password_policy=0;
SET GLOBAL validate_password_length=4;
SET PASSWORD = PASSWORD('新密码');
为MySQL的root用户添加远程登录授权:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;
重启MySQL:
systemctl restart mysqld
9、根据以上内容,自行配置WordPress程序