华为云ECS搭建wordpress+nginx+mysql+php环境

运行环境搭建

WordPress基于PHP开发的,相信是大家最熟悉也是最容易部署的Web项目了。环境准备:lnmp([linux](https://www.centos.bz/tag/linux/)+[nginx](https://www.centos.bz/category/web-server/nginx/)+[mysql](https://www.centos.bz/tag/mysql-2/)+php)或者lamp(linux+[apache](https://www.centos.bz/category/web-server/apache/)+mysql+php),大同小异,本文推荐使用[nginx](https://www.centos.bz/tag/nginx-2/)作为Web服务器。
为了避免不必要的麻烦先关闭防火墙和selinux。

更新yum

yum -y  update

1.安装nginx

安装nginx,默认情况Centos7中无Nginx的源,可以如下执行命令添加源,Centos其他版本或者RHEL查看官方教程(教程链接https://www.nginx.com/resources/wiki/start/topics/tutorials/install/):

vi /etc/yum.repos.d/nginx.repo

写入

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

安装nginx:

yum  -y install nginx 

2.安装php和mariadb

yum install php-fpm php-mysql mariadb-server unzip

注意centos6有的没有mariadb-server镜像源,安装过程注意查看是否是可用包,如无,按以下步骤配置安装源

创建安装源文件

#vim /etc/yum.repos.d/mariadb.repo

配置如下:

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

保存退出

然后直接使用yum install -y mariadb-server,如果下载时出现错误:No package mariadb-server available.,

请执行:

yum clear metadata

删除yum可用的元数据文件,会强制让yum下次运行时下载所有的元数据

然后再执行安装

yum install -y mariadb-server
/etc/init.d/mysql start 
lsof -i :3306  #查看是否启动成功

3.修改配置文件

将/etc/nginx目录下的nginx.conf.default文件拷贝一份到conf.d文件夹

修改/etc/nginx/conf.d/default.conf中下面两断内容:

vi /etc/nginx/conf.d/default.conf

更改前:

location / {
    root   /usr/share/nginx/html;
    index  index.html index.htm;
}

更改后:

    root   /usr/share/nginx/html;
    index  index.html index.htm index.php;
location / {
    try_files $uri $uri/ /index.php$is_args$args;
}

更改前:

#location ~ \.php$ {
#    root           html;
#    fastcgi_pass   127.0.0.1:9000;
#    fastcgi_index  index.php;
#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
#    include        fastcgi_params;
#}

更改后:

location ~ \.php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $request_filename;
    include        fastcgi_params;
}

修改/etc/php-fpm.d/www.conf配置:

vi /etc/php-fpm.d/www.conf

user = [apache](https://www.centos.bz/tag/apache/)改为user = nginx,将group = apache改为group = nginx

4.开启服务

systemctl start nginx.service
systemctl start mariadb.service
systemctl start php-fpm.service

5.设置开机自启

systemctl enable nginx mariadb php-fpm

安装WorePress

1.移除/usr/share/nginx/html内所有文件:

cd /usr/share/nginx/html
rm 50x.html index.html

2.下载WordPress并解压,到官网复制最新版链接(跳转链接https://cn.wordpress.org/download/):

yum install wget -y
wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.zip
unzip wordpress-4.9.4-zh_CN.zip

3.将Web文件移动到根目录并删除没用文件夹:

mv wordpress/* .
rmdir wordpress
rm wordpress-4.9.4-zh_CN.zip

4.权限设置

chown nginx.nginx -R .

5.创建数据库wordpress:

mysql
create database wordpress;
exit

接下来输入你的ip地址就可以安装WordPress了!

你可能感兴趣的:(华为云ECS搭建wordpress+nginx+mysql+php环境)