【Linux】nginx部署wordpress

gengboxb 688 0

1、安装MariaDB 数据库

安装指令 yum -y install mariadb mariadb-server、

启动 systemctl start mariadb

设置开机启动 systemctl enable mariadb

设置数据库密码 mysql_secure_installation,接下来除了设置密码其它都可以回车略过。

测试登录 mysql -u '数据库用户名' -p,然后输入你设置的数据库密码

systemctl start mariadb.service #启动MariaDB

systemctl stop mariadb.service #停止MariaDB

systemctl restart mariadb.service #重启MariaDB

systemctl enable mariadb.service #设置开机启动

创建数据库

[root@localhost ~]# mysql 
MariaDB[(none)]> create database wordpress;

可能会遇到的问腿:

1.设置数据库密码报错:
使用下面方法

[root@localhost ~]# mysql
MariaDB[(none)]> SET password=PASSWORD('newpassward');

2.mariadb 启动时报错Job for mariadb.service failed because the control process exited with error code. Se

解决办法:

[root@localhost log]# cp /usr/share/mysql/my-huge.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y
[root@localhost log]# systemctl start mariadb.service

2、安装PHP

yum默认安装的版本比较低,会造成无法访问php文件,使用安装高一点的版本,我采用的是5.6的php版本

1.检查当前安装的PHP包

yum list installed | grep php

2.如果有安装的PHP包,先删除他们

yum remove php.x86_64 php-cli.x86_64 php-common.x86_64 php-gd.x86_64 php-ldap.x86_64 php-mbstring.x86_64 php-mcrypt.x86_64 php-mysql.x86_64 php-pdo.x86_64

3.更换rpm源

Centos 5.X:
    rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm
CentOs 6.x:
    rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
CentOs 7.X:
    rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
    rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

4.如果想删除上面安装的包,重新安装

rpm -qa | grep webstatic
rpm -e  上面搜索到的包即可

5.运行yum install

php5.5

yum install php55w.x86_64 php55w-cli.x86_64 php55w-common.x86_64 php55w-gd.x86_64 php55w-ldap.x86_64 php55w-mbstring.x86_64 php55w-mcrypt.x86_64 php55w-mysql.x86_64 php55w-pdo.x86_64

php5.6

yum install php56w.x86_64 php56w-cli.x86_64 php56w-common.x86_64 php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64

php7.0

yum install php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-mysql.x86_64 php70w-pdo.x86_64

6.安装PHP FPM

yum install php55w-fpm 
yum install php56w-fpm 
yum install php70w-fpm
systemctl enable php-fpm.service【开机自启动】

3、安装Nginx

可用菜鸟教程的方法安装

https://www.runoob.com/linux/nginx-install-setup.html

配置nginx

    # 下面是server虚拟主机的配置
    server {
        # 监听端口
        listen 80;
        # 域名
        server_name localhost;
	index index.html index.htm index.php;
	# 站点目录
        root /usr/local/webserver/nginx/html/wordpress;

       location / {
        # WordPress固定链接URL重写
        if (!-e $request_filename) {
            rewrite (.*) /index.php;
        }
    }

    # PHP配置
    location ~ \.php$ {
        root  /usr/local/webserver/nginx/html/wordpress; #wordpress目录
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;        
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$
        {
           expires 30d;
           # access_log off;
        }
   
	location ~ .*\.(js|css)?$
        {
          expires 15d;
        }
        access_log off;
    }

4、启动nginx在页面上访问

ip地址或者域名/wp-admin/install.php

如:www.xxx.com/wp-admin/install.php

进入安装页面

发表评论 取消回复
表情 图片 链接 代码

分享