How to Install WordPress Multisite on Centos with Nginx

In our previous article, we explained how to install Multisite WordPress on your CentOS equipped with an Apache web server.

Today we are going to show you how to set up Multisite WordPress on your CentOS, but with a web server. Nginx

Let’s start.

First, stop and remove Apache from startup:

/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 that the system architecture is correct and enable the EPEL repository accordingly:

uname -m

– 32-bit VPS (i686):

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

– 64-bit 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

Modifying the main Nginx 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 folders inside the / etc / nginx directory:

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

Configure the nginx virtual host directive. Replace mydomain.ru.conf with your own domain:

vim /etc/nginx/sites-available/mydomain.ru.conf

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

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

client_max_body_size 5m;
client_body_timeout 60;

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

root /var/www/html/mydomain.ru/;
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; }
}

Include the virtual host directive:

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

Check your Nginx configuration for errors & typos:

nginx -t

Reload Nginx:

/etc/init.d/nginx restart

Add Nginx to your system boot:

chkconfig nginx on

Install PHP-FPM. If you want to know a detailed and optimized WordPress configuration, find it here.

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

Change the main PHP config file and make sure the date.timzeone is correct:

vim /etc/php.ini

cgi.fix_pathinfo=0
date.timezone = "your timezone"

PHP-FPM setup. Back up the original:

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

Then create a new pool configuration file as shown below:

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 system boot:

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

Download the latest version and install WordPress. For tar.gz:

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

or, for a .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 multi_my_DB;
mysql> grant all on multi_my_DB.* to [email protected] identified by ‘sEcReT_pASsWoRd’;
mysql> q

Now back up the config file and fill in the required 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’, ‘multi_my_DB’);

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

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

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

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

Open your domain in a browser to complete the installation:

Site name: yourdomain.ru

This step is very important for the future use of the multisite network. If you want sites to be created as subdomains (site1.yourdomain.ru, site2.yourdomain.ru, etc.), then fill in this field with only the domain (without the “www” in front of it, because you probably won’t like it if our site URLs are something like site1.www.yourdomain.ru).

Click the Install button.

WordPress installation is now complete. Login to the address: //yourdomain.com/wp-admin and set up the multisite site:

Go to Tools >> Network Configuration

Select your preferred address. is he can not to be changed later.

Note: For the “subdomains” option, you need a wildcard DNS record for your domain.

Fill in the rest of the fields and click the button Install

Complete the file configuration step.

We have just installed Multisite WordPress on your Centos server. Click on the link To come into log in again.

The creation of new sites can be done: My Sites >> Network Admin >> Dashboard.

Sidebar