In this post, we are going post to explain installing nginx, PHP-fpm, mariadb on Centos 7. As a bouns, gonna add information on how to install wordpress on the host.

Installation:

Mariadb Installation:

Let’s start with adding mariadb repository. Create a MariaDB.repo on /etc/yum.repos.d directory with the below content.

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

# MariaDB 10.1 CentOS repository list – created 2016-08-25 16:09 UTC
[mariadb]
name = MariaDB
gpgcheck=1
Install the mariadb server and enable the service on startup.

 

yum install MariaDB-server MariaDB-client
systemctl enable mariadb
systemctl start mariadb

 

Nginx Installation:

Create a nginx repo on /etc/yum.repos.d/nginx.repo

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

[nginx]
name=nginx repo
gpgcheck=0
enabled=1

Install nginx and enable to system startup.

yum install nginx
systemctl enable nginx
systemctl start nginx
Install php-fpm and Dependencies:

Let’s install php-fpm and other php dependencies to run a php application on the host.

yum install php-fpm php-cli php-mysql php-gd php-ldap php-odbc php-pdo php-pecl-memcache php-pear php-mbstring php-xml php-xmlrpc php-mbstring php-snmp php-soap

As a part of security, make expose_php to off on php.ini.

vi /etc/php.ini

expose_php = Off

Website on Nginx:

We had done all the dependency installation. Now, its time to create a website on nginx. Starts with User creation.

useradd wordpress -d /var/www/wordpress

Uncomment the line listen = 127.0.0.1:9000 on /etc/php-fpm.d/www.conf

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

listen = 127.0.0.1:9000

Uncomment/add the following line on /etc/nginx/conf.d/default.conf

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

location ~ \.php$ {
        root           /var/www/wordpress/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
Create a new folder /var/www/wordpress/html and change the ownership to wordpress(in our case)
mkdir -p /var/www/wordpress/html
chown -R wordpress.wordpress /var/www/wordpress/html
Add the following line on /etc/nginx/nginx.conf inside ‘http‘ section
vi /etc/nginx/nginx.conf
include /etc/nginx/sites-enabled/*.conf;
Create a new file ‘domain.conf‘ on the directory /etc/nginx/sites-enabled/ with the below content.
vi /etc/nginx/sites-enabled/domain.conf
server {
  listen       80;
  server_name sites.tldwww.sites.tld;
  location / {
    root   /var/www/wordpress/html;
    index  index.php index.html index.htm;
    try_files $uri $uri/ =404;
    }
  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
    root   /var/www/wordpress/html;
  }
  location ~ \.php$ {
        root           /var/www/wordpress/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}
Restart the nginx and php-fpm service.
systemctl restart nginx
systemctl restart php-fpm
All Done 🙂 Now, its time to install wordpress on the host.
WordPress installation:

Download wordpress latest version to domain documentroot

cd /var/www/wordpress/html

wget http://wordpress.com/latest.tar.gz

tar -xzf latest.tar.gz
cp -pr wordpress/* .
Create a new database, new user and provided access to user. Access mysql prompt ‘mysql’  and run the following command.

 

create database wordpress;
grant all privileges on wordpress.* to wordpress@localhost identified by <password>;
flush privileges;
Access the domain.tld in browser and complete the installation.
Comment your queries in this post incase if you face any issues.

Leave a Reply