How to install Nginx + PHP + MariaDB or Nginx + PHP + MySQL to build a WordPress web server environment on Centos 7?
WordPress as the most popular free CMS to build website, and WordPress is also the first option to build a website.
The Nginx + PHP + MySQL or Nginx + PHP + MariaDB is the most popular solution to build a web server environment on the Linux system.
In the following content, we will show the steps to build a WordPress web server environment on CentOS 7.
Operating environment
WordPress is based on PHP. Environment preparation: Linux + Nginx + MySQL + PHP or linux + apache + mysql + php
In order to avoid unnecessary trouble, first, turn off the firewall and SELinux.
1. How to install Nginx?
By default, there is no Nginx source in Centos7. You can add it by executing the command as follows. The other versions of Centos or RHEL to view the official tutorial, the link.
vi /etc/yum.repos.d/nginx.repo
Write
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
Using yum command to install Nginx:
yum install nginx -y
2. How to install PHP and MariaDB?
Use yum Linux command to install PHP, MariaDB or MySQL.
yum install php-fpm php-mysql mariadb-server unzip
3. Modify the configuration file
Modify the following two breaks in /etc/nginx/conf.d/default.conf:
vi /etc/nginx/conf.d/default.conf
Before the change:
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
After the change:
root /usr/share/nginx/html;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
Before the change:
#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;
#}
After the change:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
Modify the /etc/php-fpm.d/www.conf configuration:
vi /etc/php-fpm.d/www.conf
Change user = apache to user = Nginx and group = apache to group = Nginx.
4. Open the service
systemctl start nginx.service
systemctl start mariadb.service
systemctl start php-fpm.service
5. Set the Nginx/MariaDB/PHP boot from the start
systemctl enable nginx mariadb php-fpm
How install WordPress on CentOS?
1. Remove all files in /usr/share/nginx/html:
cd /usr/share/nginx/html
rm 50x.html index.html
2. Download WordPress and extract it.
yum install wget -y
wget https://wordpress.org/latest.zip
unzip latest.zip
3. Move the web file to the root directory and delete the unused folder:
mv wordpress/* .
rmdir wordpress
rm latest.zip
4. Permission settings
chown nginx.nginx -R .
5. Create a database WordPress:
mysql
create database wordpress;
exit
Now, open a browser, such as Google Chrome, enter the IP of the server, follow the guidance to install WordPress.