Create CentOS 7 VM & Update

sudo -i

yum update -y
yum install epel-release yum-utils -y
yum clean install

Install Nginx

yum install nginx -y
service nginx start
*browser to VM’s public IP to test 
sudo systemctl enable nginx
sudo systemctl start nginx

Install MariaDB

yum install mariadb-server -y
service mariadb start
mysql_secure_installation

MariaDB will ask you for the root password, however, since this is initial installation, you don’t have any, so just press enter. Next prompt will ask if you want to set a root password, enter Y and follow the instructions:

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorization.

New password: password
Re-enter new password: password
Password updated successfully!
Reloading privilege tables..
 ... Success!

You can safely click ENTER key and accept default settings for all other questions. After you complete the setup, proceed further to PHP installation.

Create WordPress DB

mysql -u root -p
CREATE DATABASE wordpress;
CREATE USER wordpressuser@localhost IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
exit

Install PHP7.2

sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm


rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
rpm -Uvh http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
sudo yum install yum-utils -y

sudo yum-config-manager –enable remi-php72
sudo yum install php-cli php-fpm php-mysql php-json php-opcache php-mbstring php-xml php-gd php-curl
Configure PHP 7 by modify the config file of php. Make sure to uncomment & change the ;cgi.fix_pathinfo=1 to cgi.fix_pathinfo=0.
# vi /etc/php.ini
cgi.fix_pathinfo=0
Open php-fpm configuration file and modify the lines same as below.
# vi /etc/php-fpm.d/www.conf
user = nginx
group = nginx

listen = /var/run/php-fpm/php-fpm.sock
 
listen.owner = nginx
listen.group = nginx

service php-fpm restart

sudo systemctl enable php-fpm
sudo systemctl start php-fpm

echo “<?php phpinfo(); ?>” > phpversion.php

Note: Php 7.1 installation  – verified:

Php7.3 installation (Not Verified):

#先把php版本升级为7
yum install php73-php-fpm php73-php-mysql

#安装nginx和mysql

# 启动PHP-FPM 

systemctl start php73-php-fpm 
# 开机启动 
systemctl enable php73-php-fpm 
# 启动mysql 
systemctl start mysqld

# 回车输入密码即可
mysql -u root -p
# 创建名字为wordpress的数据库
create database wordpress;

# 创建数据库用户,用户名wordpress,密码wordpress@2019
grant all privileges on wp.* to ‘wordpress’@’%’ identified by ‘wordpress@2019’;

# 刷新授权
flush privileges;

#下载最新版本的wordpress
# 目录为 /opt/application
wget https://cn.wordpress.org/latest-zh_CN.tar.gz
tar -xvf latest-zh_CN.tar.gz

# 用模板复制修改配置文件
cp wp-config-sample.php wp-config.php
#修改wp-config.php为如下
// ** MySQL 设置 – 具体信息来自您正在使用的主机 ** //
/** WordPress数据库的名称 */
define( ‘DB_NAME’, ‘wordpress’ );
/** MySQL数据库用户名 */
define( ‘DB_USER’, ‘wordpress’ );
/** MySQL数据库密码 */
define( ‘DB_PASSWORD’, ‘wordpress@2019’ );
/** MySQL主机 */
define( ‘DB_HOST’, ‘localhost’ );
/** 创建数据表时默认的文字编码 */
define( ‘DB_CHARSET’, ‘utf8’ );
/** 数据库整理类型。如不确定请勿更改 */
define( ‘DB_COLLATE’, ” );

#配置文件默认在/usr/local/nginx/conf/nginx.conf

server {
  # 监听的端口
  listen 80;
  # 域名
  server_name www.javashitang.com;
  index index.html index.php;
  # 访问日志目录
  access_log /var/log/nginx/blog_access.log main;
  # 网站根目录
  root /opt/application/wordpress;

  location / {
    root /data/www;
  }

  location ~ \.php$ {
  # php程序启动的端口
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
  }
}

Configure Nginx 

Php7.2

Create a new configuration file called wordpress under folder /etc/nginx/sites-available

sudo nano /etc/nginx/sites-available/wordpress



Then copy and paste the content below into the file and save it. Replace example.com with your own domain name. You might also want to add your wordpress site’s public ip into servername list for your testing before you switched to domain.

server {
    listen 80;
    listen [::]:80;
    root /var/www/html/wordpress;
    index  index.php index.html index.htm;
    server_name  54.32.104.91 51sec.org www.51sec.org;

     client_max_body_size 100M;

    location / {
        try_files $uri $uri/ /index.php?$args;        
    }

    location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass             unix:/var/run/php/php7.2-fpm.sock;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

Php7.1

sudo vi /etc/nginx/conf.d/wordpress.conf

server {
    listen   80;
    server_name  140.238.157.42 www.51sec.org 51sec.org;

    # note that these lines are originally from the "location /" block
    root   /var/www/html/wordpress;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Install WordPress

yum install wget
cd /tmp && wget https://wordpress.org/latest.tar.gz
tar -zxvf latest.tar.gz

sudo mv wordpress /var/www/html/wordpress

sudo chown -R nginx: /var/www/html/wordpress
sudo chmod -R 755 /var/www/html/wordpress/
sudo mv /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php

Configure WordPress

Change configuration to connect to your local new MariaDB server:

sudo nano /var/www/html/wordpress/wp-config.php


// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wordpressuser');

/** MySQL database password */
define('DB_PASSWORD', 'password1234');

/** MySQL hostname */
define('DB_HOST', 'localhost');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

References

By Jonny

Leave a Reply