How to Install WordPress on Nginx on CentOS 7

Hi there,

This tutorial will show you how to install WordPress using Nginx on CentOS 7. You will need the following commands to follow along with this tutorial.

First we’ll need to install additional repos that include php71 and then install php71. The commands to do so are:

  • sudo wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
  • sudo rpm -Uvh remi-release-7.rpm
  • sudo yum install yum-utils -y
  • sudo yum-config-manager –enable remi-php71
  • sudo yum –enablerepo=remi,remi-php71 install php-fpm php-common
  • sudo yum yum –enablerepo=remi,remi-php71 install php-opcache php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongodb php-pecl-redis php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml

 

Next we will download WordPress, place it in the directory that we want and then correct the permissions for that folder.

  • sudo wget https://wordpress.org/latest.tar.gz
  • sudo mv latest.tar.gz /usr/share/nginx/htm
  • cd /usr/share/nginx/htm
  • sudo tar -zxvf latest.tar.gz
  • sudo chown -R nginx:nginx /usr/share/nginx/html/wordpress
  • sudo chmod -R 755 /usr/share/nginx/html/wordpress
  • sudo setenforce 0

Now lets set up a config file for our wordpress site. Run the command below and then copy and paste the text into your file, insuring that you enter your IP address into the file.

  • sudo vi /etc/nginx/conf.d/default.conf
server {
 listen 80;
 server_name YOURIPADDRESS;
 
 # note that these lines are originally from the "location /" block
 root /usr/share/nginx/html/wordpress;
 index index.php index.html index.htm;
 
 location / {
 try_files $uri $uri/ =404;
 }
 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;
 }
}

Next make some final changes to your php configuration. Run the command:

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

Make the following changes to this file.

  • user = apache to user = nginx
  • group = apache to group = nginx
  • listen.owner = nobody to listen.owner = nginx
  • listen.group = nobody to listen.group = nginx
  • Finally append under  this line listen = 127.0.0.1:9000
    • listen = /var/run/php-fpm/php-fpm.sock

Now restart all relevant services and ensure that they are all configured to start when the server boots.

  • sudo service php-fpm restart
  • sudo service nginx restart
  • sudo chkconfig php-fpm on
  • sudo chkconfig nginx on

Now lets do the DB settings needed.

  • mysql -u root -p
  • CREATE DATABASE wordpress;
  • GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY ‘password123’;
  • FLUSH PRIVILEGES

This entry was posted in CentOS, Databases, learning, linux, mysql, nginx, web server and tagged , , , , , . Bookmark the permalink.

6 Responses to How to Install WordPress on Nginx on CentOS 7

  1. Vu Tuan Anh says:

    I see your video on youtube. I liked , you so smart, thanks u.

  2. Pingback: How to Install WordPress on Nginx on CentOS 7 (LEMP) – Install WordPress La Fontaine Shop

  3. Pingback: How to Install WordPress on Nginx on CentOS 7 (LEMP) – My blog

  4. Pingback: How to Install WordPress on Nginx on CentOS 7 (LEMP) | Host your Website

  5. rootninja says:

    A few minor edits:

    original
    –enablerepo
    change to
    –enablerepo

    also you reference htm in the path however you call for html in both command and default.conf file

    lastly the single quotes character set around db password caused me problems, easy fix was to manually type in ‘YourSuperSecretPasswd’ -vs- ‘password123’

Leave a Reply

Your email address will not be published. Required fields are marked *