基础环境搭建

配置ip,VMNET8,192.168.200.0/24,关闭防火墙,关闭SElinux

配置yum

[root@xserver1 ~]# mv /etc/yum.repos.d/* /home/yumback/
[root@xserver1 ~]# vi /etc/yum.repos.d/local.repo
[lnmp]
name=lnmp's yum
baseurl=file:///root/lnmp
gpgcheck=0
enabled=1
[centos]
name=centos7
baseurl=file:///opt/centos
gpgcheck=0
enabled=1
[root@xserver1 ~]# yum clean all
[root@xserver1 ~]# yum makecache
[root@xserver1 ~]# yum install -y vim bash-completion net-tools

安装环境

#安装所需软件
#nginx
[root@localhost ~]# yum install -y nginx
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# systemctl enable nginx
#php
[root@xserver1 ~]# yum install -y php php-cli php-common php-devel php-fpm php-mysql php-pdo
[root@xserver1 ~]# systemctl start php-fpm
[root@xserver1 ~]# systemctl enable php-fpm
#数据库
[root@xserver1 ~]# yum install -y mariadb mariadb-server
[root@xserver1 ~]# systemctl start mariadb
[root@xserver1 ~]# systemctl enable mariadb
#MARIADB初始化设置:
[root@xserver1 ~]# mysql_secure_installation
回车,y,输入密码000000,确认密码000000,剩下的都y
#放开远程访问权限:
[root@xserver1 ~]# mysql -uroot -p000000
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* to 'root'@'192.168.200.11' identified by '000000';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exi

测试环境

测试php

1、在nginx服务中创建测试站点,站点目录为/usr/share/nginx/test:

[root@localhost ~]# mkdir /usr/share/nginx/test

2、创建测试php环境页面

[root@localhost ~]# vim /usr/share/nginx/test/index.php
<?php
phpinfo();
?>

3、在nginx服务中配置一个测试虚拟主机:

[root@localhost ~]# vim /etc/nginx/conf.d/test.conf
server {
        listen 8080;
        server_name 192.168.200.11:8080;
        location / {
            root /usr/share/nginx/test;
            index index.php index.html;
        }
        location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME    /usr/share/nginx/test$fastcgi_script_name;
        include        fastcgi_params;
        }
}

4、重启nginx:

[root@localhost ~]# systemctl restart nginx

打开浏览器,在地址栏输入http://192.168.200.11:8080

测试php是否能连接数据库

1、在上述测试站点目录中创建连接数据库测试页面:

[root@localhost ~]# vim /usr/share/nginx/test/mysqltest.php
<?php $link=mysql_connect('192.168.200.11','root','000000');
if($link)
echo "mysql-link-ok";
else
echo "mysql-link-faile";
mysql_close();
?>

2、重启nginx:

[root@localhost ~]# systemctl restart nginx

打开浏览器,地址栏输入http://192.168.200.11:8080/mysqltest.php,回车之后打开的页面中显示"mysql-link-ok",说明php连接数据库没问题

安装WordPress

1、安装unzip

[root@localhost ~]# yum install unzip –y

2、解压缩

[root@localhost ~]# unzip wordpress-4.7.3-zh_CN.zip

3、将解压后的文件复制到站点目录下:

mkdir /usr/share/nginx/wordpress
cp  -r  /root/wordpress/*  /usr/share/nginx/wordpress/

4、放开站点目录权限

[root@localhost ~]# chmod  777  -R  /usr/share/nginx/wordpress/

5、登录mysql,创建数据库WordPress

[root@localhost ~]# mysql -uroot -p000000
mysql> create database wordpress;
mysql> show databases;
mysql> exit

6、创建mywordpress虚拟主机:

[root@localhost ~]# vim /etc/nginx/conf.d/mywordpress.conf
server {
        listen 80;
        server_name 192.168.200.11;
        location / {
            root /usr/share/nginx/wordpress;
            index index.php index.html;
        }
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  app.php;
  fastcgi_param  SCRIPT_FILENAME    /usr/share/nginx/wordpress$fastcgi_script_name;
        include        fastcgi_params;
    }
}

7、重启nginx

[root@localhost ~]# systemctl restart nginx

8、打开浏览器,地址栏输入http://192.168.200.11,回车后打开wordpress界面

最后修改:2021 年 06 月 28 日
如果觉得我的文章对你有用,请随意赞赏