How to install WordPress Multisite on Centos VPS with Nginx

how-to-install-wordpress-multisite-on-your-centos-vps-with-nginxIn our previous article we explained how to install WordPress Multisite on your CentOS VPS equipped with an Apache Web Server.

Today, we will see the steps to set up a WordPress Multisite on your CentOS VPS but with an nginx web server installed.

Let’s begin, then.

 

First, stop and remove Apache from autostart:

# /etc/init.d/httpd stop
# chkconfig httpd off

If you don’t plan on using it, remove it:

# yum remove httpd

Install Nginx. First, check for the correct system architecture and enable the epel repository accordingly. Type:

# uname -m

- 32bit VPS (i686):

# rpm -Uvh http://mirror.pnl.gov/epel/6/i386/epel-release-6-8.noarch.rpm

- 64bit VPS (x86_64):

# rpm -Uvh http://mirror.itc.virginia.edu/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm

Update the system:

# yum update

Install nginx:

# yum install nginx -y

Edit the Nginx main configuration file:

# vim /etc/nginx/nginx.conf

user nginx;
worker_processes 2;

error_log  /var/log/nginx/error.log;

pid        /var/run/nginx.pid;

events {
worker_connections  1024; }

http {
include       /etc/nginx/mime.types;
default_type  application/octet-stream;

log_format  main  ‘$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for”‘;

access_log  /var/log/nginx/access.log  main;

sendfile        on;

keepalive_timeout  30;
server_tokens off;

gzip on;
gzip_disable “MSIE [1-6]\.(?!.*SV1)”;
gzip_http_version 1.1;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js;

# enabled sites
include /etc/nginx/sites-enabled/*;

}

Create the sites-enabled and sites-available directories inside the /etc/nginx directory:

# mkdir /etc/nginx/sites-{available,enabled}

Set-up an nginx vhost directive. Replace mydomain.tld.conf with your own domain:

# vim /etc/nginx/sites-available/mydomain.tld.conf

server {
listen 80;
server_name mydomain.tld;
rewrite ^(.*) http://www.mydomain.tld$1 permanent; }

server {
listen 80;
server_name www.mydomain.tld;

client_max_body_size 5m;
client_body_timeout 60;

access_log /var/log/nginx/mydomain.tld-access;
error_log /var/log/nginx/mydomain.tld-error error;

root /var/www/html/mydomain.tld/;
index  index.html index.php;

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

error_page 403 =404;
location ~ /\. { access_log off; log_not_found off; deny all; }
location ~ ~$ { access_log off; log_not_found off; deny all; }
location ~* wp-admin/includes { deny all; }
location ~* wp-includes/theme-compat/ { deny all; }
location ~* wp-includes/js/tinymce/langs/.*\.php { deny all; }
location /wp-includes/ { internal; }
location ~* ^/wp-content/uploads/.*.(html|htm|shtml|php)$ {
types { }
default_type text/plain; }

#  location ~* wp-admin {
#      allow <YOUR_IP>;
#      allow 127.0.0.1;
#      deny all; }

location = /robots.txt { access_log off; log_not_found off; }
location = /favicon.ico { access_log off; log_not_found off; }

location ~ \.php?$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass unix:/var/run/php-wordpress.socket;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_hide_header X-Powered-By; }
}

Enable the vhost directive:

# cd /etc/nginx/sites-enabled
# ln -s /etc/nginx/sites-available/mydomain.tld.conf

Test the nginx configuration for errors & typos:

# nginx -t

Restart nginx:

# /etc/init.d/nginx restart

Add nginx to your system startup:

# chkconfig nginx on

Install php-fpm. If you want a detailed and optimized wordpress configuration, find it here.

# yum install php-fpm php-mysql php-gd php-mcrypt -y

Edit the main php configuration file and make sure the following is in place (match date.timzeone to yours):

# vim /etc/php.ini

cgi.fix_pathinfo=0
date.timezone = America/New_York

Set up a php-fpm pool. Make a backup copy of the original:

# mv -v /etc/php-fpm.d/www.conf{,.bak}

Then create a new pool config file as shown:

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

[wordpress]
listen = /var/run/php-wordpress.socket
user = nginx
group = nginx
request_slowlog_timeout = 5s
slowlog = /var/log/php-fpm/blog.log
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 10
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 4
pm.max_requests = 400
listen.backlog = -1
pm.status_path = /status
request_terminate_timeout = 120s
rlimit_files = 131072
rlimit_core = unlimited
catch_workers_output = yes
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session
php_admin_value[error_log] = /var/log/php-fpm/wp-error.log
php_admin_flag[log_errors] = on

Now restart the php-fpm service and add it to the system startup:

# /etc/init.d/php-fpm restart
# chkconfig php-fpm on

Download the latest version of wordpress and set it up. For tar.gz:

# wget http://wordpress.org/latest.tar.gz && tar xf latest.tar.gz -C /var/www/html/

or, for the .zip file:

# wget http://wordpress.org/latest.zip && unzip latest.zip -d /var/www/html/

Set the owner of the root directory:

# chown -R nginx: /var/www/html/wordpress/

Create a new database:

# mysql -uroot -p

mysql> create database multiDB;
mysql> grant all on multiDB.* to WPuser@localhost identified by ‘sEcReT_pASsWoRd’;
mysql> \q

Now, back up the config file and enter the necessary information:

# cd /var/www/html/wordpress/ && cp -pv wp-config-sample.php wp-config.php

# vim /var/www/html/wordpress/wp-config.php

/** The name of the database for WordPress */
define(‘DB_NAME’, ‘multiDB’);

/** MySQL database username */
define(‘DB_USER’, ‘multi’);

/** MySQL database password */
define(‘DB_PASSWORD’, ‘sEcReT_pASsWoRd’);[/GREEN]

Above the /* That’s all, stop editing! Happy blogging. */ line, add:

/* My multisite config starts here */
define(‘WP_ALLOW_MULTISITE’, true);

Open your domain in a browser to finish the installation:

Site Title: yourdomain.tld

NOTE: For a Sub-domains setup, (site1.yourdomain.tld, site2.yourdomain.tld etc) insert here your domain only (you might not like it if the websites’ urls are something like site1.www.yourdomain.tld). For a subdirectory setup, you can enter www.yourdomain.tld as the user websites will have the url www.yourdomain.tld/site1)

Click Install.

The WordPress installation is over. Log in at http://yourdomain.tld/wp-admin to install the multisite feature:

Go to Tools >> Network Setup

Select the preferred address option. This can not be changed later.

NOTE: For the ‘Sub-domains’ option, you will need a wildcard DNS record for your domain. Please contact us (or your provider) if you don’t know how to set the wildcard DNS record.

Fill the rest of the fields and click Install.

Finish the file configuration step.

We have just installed WordPress Multisite on your Centos VPS server. Click on the Log In link again to log in and you’re ready to go!

Creating new sites can be done at My Sites >> Network Admin >> Dashboard.

Of course you don’t have to do any of this if you use one of our linux vps services, in which case you can simply ask our expert Linux admins to install this for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a thank you note below. Thanks.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>