Centos7 Nginx+Mysql+Php build a WordPress site

One, install Nginx

1.1 Install Nginx related dependencies

# 安装gcc
yum install gcc-c++
# 安装 pcre-devel 
yum install -y pcre pcre-devel
# 安装zlib  
yum install -y zlib zlib-devel
# 安装OpenSSL  
yum install -y openssl openssl-devel 

Some rely on a number of modules nginx lib library, before installing nginx, lib must install these libraries, there are dependencies g++, gcc, openssl-devel, pcre-develand zlib-devel. nginx compilation requires `gcc', gzip module needs zlib library, rewrite module needs pcre library, and ssl function needs openssl library.

1.2 Install Nginx

# 创建 nginx.repo文件
vi /etc/yum.repos.d/nginx.repo   
# 然后写入配置:
[nginx]  
name=nginx repo  
baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/  
gpgcheck=0  
enabled=1 

Here to add manually configure the library source Nginx, to baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/the OSreplaced centos(depending on your system), with 7replacement (depending on your version) OSRELEASE, that is baseurl=http://nginx.org/packages/centos/7/$basearch/, and then :wqsave and exit.
run:

yum install nginx

1.3 Start Nginx and visit through the browser

# 启动 nginx
cd /usr/sbin
./nginx
# 打开防火墙 80 端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
# 重启防火墙  
firewall-cmd --reload

Browser access server IP, display
Insert picture description here

1.4 Common commands for Nginx operations

# 启动nginx
 /usr/sbin/nginx    
# 停止 nginx    
 /usr/sbin/nginx -s stop    
# 从容停止 nginx
 /usr/sbin/nginx -s quit   
# 重启 nginx
 /usr/sbin/nginx -s reload  
# 查看nginx进程
ps aux | grep nginx

1.5 regular firewall operations

Centos7 comes with firewall firewall

systemctl start firewalld # 启动
systemctl enable firewalld # 开机启动
systemctl stop firewalld # 关闭
systemctl disable firewalld # 取消开机启动

The firewall manages specific rules through firewall-cmd:

$ firewall-cmd --help
1. 查看规则
# 查看运行状态
firewall-cmd --state
# 查看已被激活的 Zone 信息
firewall-cmd --get-active-zones
# 查看指定接口的 Zone 信息
firewall-cmd --get-zone-of-interface=eth0
# 查看指定级别的接口
firewall-cmd --zone=public --list-interfaces
# 查看指定级别的所有信息,譬如 public
firewall-cmd --zone=public --list-all
# 查看所有级别被允许的信息
firewall-cmd --get-service
# 查看重启后所有 Zones 级别中被允许的服务,即永久放行的服务
firewall-cmd --get-service --permanent
firewall-cmd --panic-on # 丢弃
firewall-cmd --panic-off # 取消丢弃
firewall-cmd --query-panic # 查看丢弃状态
firewall-cmd --reload # 更新规则,不重启服务
firewall-cmd --complete-reload # 更新规则,重启服务
# 添加某接口至某信任等级,譬如添加 eth0 至 public,再永久生效
firewall-cmd --zone=public --add-interface=eth0 --permanent
# 设置 public 为默认的信任级别
firewall-cmd --set-default-zone=public

2. 管理端口
# 列出 dmz 级别的被允许的进入端口
firewall-cmd --zome=dmz --list-ports
# 允许 tcp 端口 8080 至 dmz 级别
firewall-cmd --zone=dmz --add-port=8080/tcp
# 允许某范围的 udp 端口至 public 级别,并永久生效
firewall-cmd --zome=public --add-port=5060-5059/udp --permanent

3. 管理服务
# 添加 smtp 服务至 work zone
firewall-cmd --zone=work --add-service=smtp
# 移除 work zone 中的 smtp 服务
firewall-cmd --zone=work --remove-service=smtp

4. 配置 ip 地址伪装
# 查看
firewall-cmd --zone=external --query-masquerade
# 打开伪装
firewall-cmd --zone=external --add-masquerade
# 关闭伪装
firewall-cmd --zone=external --remove-masquerade

5. 端口转发
# 要打开端口转发,则需要先
# firewall-cmd --zone=external --add-masquerade
# 然后转发 tcp 22 端口至 3753
firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toport=3753
-----------------------------------
# 转发 22 端口数据至另一个 ip 的相同端口上
firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toaddr=192.168.1.100
# 转发 22 端口数据至另一 ip 的 2055 端口上
firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toport=2055:toaddr=192.168.1.100

Two, MySQL installation and configuration

2.1 Install Mysql

Under no centos7 yum install mysql-serverinstallation method, whereby, following installation method:

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum update
yum install mysql-server
# 启动mysql
systemctl start mysqld

2.2 MySQL initialization settings

# 运行下面命令进入初始化设置
mysql_secure_installation
2.2.1 Modify Mysq default password

The first is to set the root password, which is blank by default when you log in for the first time. Just click Enter and enter the new root password twice

Insert picture description here

2.2.2 Delete anonymous users

Subsequently, you will choose whether to delete anonymous users (you can log in to mysql without an account), select y, as shown in the figure
Insert picture description here

2.3.4 Allow remote connection

By default, the root user is only allowed to connect localhost, which can prevent other users from logging in to root remotely. Choose here according to your own situation. In the project, you need to log in to the root user remotely. This is selected n, as shown in the figure:
Insert picture description here

2.3.5 Delete test database

To delete the test database, select y:

Insert picture description here

2.3.6 Real-time update of database timing

Finally, select the database timing update, select y:
Insert picture description here

2.4 Create Mysql user

# root用户登录
mysql -u root -p
create database wordpress charset utf8;
# 列出数据库(如下图)
show databases;
# 退出数据库
exit;
# 重启数据库
systemctl restart mysqld 

Insert picture description here

Three, PHP, Vsftpd installation configuration

3.1 Configure PHP

#  先安装 php-mysql 和 php-fpm,如果已有,则跳过
yum –y install php-mysql
yum –y install php-fpm
# 运行
yum -y install php* --skip-broken
# 编辑 php 配置文件
vim /etc/php.ini
# 添加
extension=mysql.so
# 找到 extension_dir  并设为
extension_dir = "/usr/lib64/php/modules"
# 重启 php 服务
systemctl restart php-fpmmv

3.2 Vsftpd installation and configuration

# 安装
yum -y install vsftpd
# 启动服务
systemctl start vsftpd 
# 新建 ftp home 目录
mkdir  /ftpuserdata
# 为 ftp 创建用户 ftpuser,指定目录 /ftpuserdata/www/
useradd ftpuser -d /ftpuserdata/www/ -s /sbin/nologin
# 设置密码
passwd ftpuser
# 编辑 FTP 配置文件
vim /etc/vsftpd/vsftpd.conf
# 将匿名登录禁用
anonymous_enable=NO
# 保存退出后,给 www 目录设置读写权限
chmod -R 777 /ftpuserdata/www/
# 重启
systemctl restart vsftpd

Four, Wordpress installation and related configuration

4.1 Install wordpress

# 安装
# 进入目录
cd /ftpuserdata/www/
#下载
wget https://wordpress.org/latest.zip
# 解压
unzip latest.zip

4.2 Configure WordPress

Modify WordPress configuration file

 vim /ftpuserdata/www/wordpress/wp-config-sample.php 

Insert picture description here

Save and exit, rename the WordPress configuration file

mv /ftpuserdata/www/wordpress/wp-config-sample.php /ftpuserdata/www/wordpress/wp-config.php 

4.3 Modify wp related configuration

Modify the nginx configuration according to the WordPress directory and the cgi settings of php:

vim /etc/nginx/conf.d/default.conf

Insert picture description here

After modification, restart related services.

systemctl restart vsftpd
systemctl restart php-fpm
systemctl restrat nginx

Open the IP address in the browser and you can go to the WordPress initialization interface. Such a WordPress website is set up.
Insert picture description here

5. Related issues and solutions

When changing the theme, there is no write permission of the upper-level directory

WordPress create directory wp-content/uploads/2018/11.

solve

cd /ftpuserdata/www 
mkdir wordpress/wp-content/
chmod 777 wordpress/wp-content/uploads/

【Related Links】

Guess you like

Origin blog.csdn.net/qq_36148847/article/details/84113149