nginx实现fastcgi反向代理,搭建wordpress

1)安装软件包 nginx php-fpm php-mysql

[root@nginx ~]#yum install nginx php-fpm php-mysql -y

2)修改 php-fpm 配置文件,把启动用户和组改为nginx,启动服务

root@nginx ~]#vim /etc/php-fpm.d/www.conf

user = nginx

group = nginx

启动php-fpm
[root@nginx ~]#systemctl start php-fpm.service 

3)创建放php程序的目录,创建测试页面

[root@nginx ~]#mkdir /data/php

[root@nginx ~]#vim /data/php/index.php

<?php
phpinfo();
?>

4)修改nginx配置文件

[root@nginx ~]#vim /etc/nginx/conf.d/test.conf 

server_tokens off;
server {
   listen 80;
   server_name  www.xingyu.com;
    root  /data/test1;
    index index.php index.html;
    location ~* \.php$ {
        root /data/php;                  #调用root目录
        fastcgi_pass 127.0.0.1:9000;        #后端php-fpm服务器IP:9000
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #fastcgi_param SCRIPT_FILENAME /data/php$fastcgi_script_name;
        include fastcgi_params;
    }

    
}

5)启动nginx,测试

[root@nginx ~]#nginx
image.png

成功!

6)安装数据库,启动数据库,创建数据库和账户

[root@mysql ~]#yum install mariadb-server -y

启动数据库
[root@mysql ~]#systemctl start mariadb

创建wordpress数据库
[root@mysql ~]#mysql -e 'create database wordpress'

创建用户并授权wordpress数据库
[root@mysql ~]#mysql -e 'grant all on wordpress.* to wpuser@"192.168.8.%" identified by "xingyu"'

7)测试链接数据库

[root@test ~]#mysql -uwpuser -pxingyu -h192.168.8.102

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.65-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               |
| wordpress          |
+--------------------+
3 rows in set (0.00 sec)


8)把wordpress程序放到创建好的php目录里和默认站点的目录里,修改wordpress配置文件

[root@nginx ~]#ls
anaconda-ks.cfg  wordpress-5.0.9-zh_CN.tar.gz

[root@nginx ~]#tar xf wordpress-5.0.9-zh_CN.tar.gz 
[root@nginx ~]#cd wordpress/

[root@nginx wordpress]#cp -a * /data/php/
[root@nginx wordpress]#cp -a * /data/test1/



把这个范例拷贝成wordpress的配置文件
[root@nginx php]#cp wp-config-sample.php wp-config.php 


填写数据库,用户名,密码,数据库主机
[root@nginx php]#vim wp-config.php 

/** WordPress数据库的名称 */
define('DB_NAME', 'wordpress');

/** MySQL数据库用户名 */
define('DB_USER', 'wpuser');

/** MySQL数据库密码 */
define('DB_PASSWORD', 'xingyu');

/** MySQL主机 */
define('DB_HOST', '192.168.8.102');

把属组和属主改为root
[root@nginx php]#chown -R root.root .

9)测试


image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。