How to host multiple sites in a single Wordpress installation on CentOS 7

This document describes how to install and configure multiple WordPress sites with the latest WordPress version on CentOS 7 in a single wordpress instance. WordPress started in 2003 with a single bit of code to enhance the typography of everyday writing and with fewer users than you can count on your fingers and toes. Since then it has grown to be the largest self-hosted blogging tool in the world, used on millions of sites and seen by tens of millions of people every day. This tutorial explains the process of installing WordPress 4.0 on CentOS 7.0 in the form of a simple-to-follow guide.

1 Preliminary Note

This tutorial is based on CentOS 7.0 server, so you should set up a basic CentOS 7.0 server installation before you continue with this tutorial. The system should have a static IP address. I use as my IP address in this tutorial and as the hostname.  You must have a LAMP server installed in CentOS 7.0 as mentioned in the tutorial to continue further.

2 Database initialization

I will create  the database for the WordPress 4.0 as follows:

mysql -u root -p

Here we are adding database=wordpressdb user=wordpressuser and password=wordpresspassword:

CREATE DATABASE wordpressdb;
CREATE USER [email protected] IDENTIFIED BY 'wordpresspassword';
GRANT ALL PRIVILEGES ON wordpressdb.* TO [email protected];

Further moving ahead:


Restart services

service httpd restart
service mariadb restart

  Further you need to allow the Firewall-cmd to http and https as follows:

firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

3 Installation of WordPress 4.0

We will first make a directory temp in which I will the download the latest version of the WordPress as follows:

mkdir temp
cd temp
yum install wget unzip net-tools


Further moving ahead if you  wish to work with images, install plugins and site updation with SSH credentials then we will install:

yum install php-gd
service httpd restart

unzip the Wordpress 4.0 zip file in the folder:

unzip -q -d /var/www/html/

Now give appropriate permissions in the directory

chown -R apache:apache /var/www/html/wordpress
chmod -R 755 /var/www/html/wordpress

Further we need to manually create the uploads directory beneath the wp-content directory at our document root. This will be the parent directory of our content: 

mkdir -p /var/www/html/wordpress/wp-content/uploads

We need to allow the web server itself to write to this directory. We can do this by assigning group ownership of this directory to our web server. This will allow the web server to create files and directories under this directory, which will permit us to upload content to the server. Proceed like this:

chown -R :apache /var/www/html/wordpress/wp-content/uploads

Now we need the sample configuration file,to copy it to the default configuration file to get WordPress to recognize the file. The sample configuration file is available at /var/www/html/wordpress:

cd /var/www/html/wordpress/

cp wp-config-sample.php wp-config.php

nano wp-config.php


// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'wordpressdb'); /** MySQL database username */ define('DB_USER', 'wordpressuser'); /** MySQL database password */ define('DB_PASSWORD', 'wordpresspassword');


Change values as you gave at the time of database initialization.

3.1 Multiple site configuration

Now we will proceed with the multiple site configuration, for this we need to add these lines to our wp-config.php file just above the /* That’s all, stop editing! Happy blogging. */ line.

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

/* Multisite */
define('WP_ALLOW_MULTISITE', true);
/* That's all, stop editing! Happy blogging. */


3.2 Apache Rewrite

We will modify the apache virtual host file for WordPress to get it allowed for .htaccess overrides. For this we will edit the virtual host file and add the entries as:

nano /etc/httpd/conf/httpd.conf

# Further relax access to the default document root: <Directory "/var/www/html"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride All

Change the value from AllowOverride None to AllowOverride All, next restart the service:

service httpd restart

3.3  Create an .htaccess File

Now we will create .htaccess file in document root, it will allow Apache to rewrites:

touch /var/www/html/wordpress/.htaccess

We need the web server to be the group owner though, so we should adjust the ownership as follows:

chown apache /var/www/html/wordpress/.htaccess

If you want WordPress to automatically update this file with rewrite rules, you can ensure that it has the correct permissions to do so by using:

chmod 664 /var/www/html/wordpress/.htaccess

If you want to update this file manually for the sake of a small security gain, you can allow the web server only read privileges by typing:

chmod 644 /var/www/html/wordpress/.htaccess

In my case I am using permissions 644.

3.4 Webinstallation

Now proceed to the web installation of WordPress 4.0. Go to the URL

Select language and press Continue:



Now give the values as I gave in my case

Site Title = Wordpress-testsite
Admin Email = [email protected]
Username = admin
Admin password = howtoforge
Confirm Admin Password = howtoforge

The above values will differ in you case, you can give any values of your choice. After giving the values press InstallWordpress:


Now we will proceed towards the login page by pressing LogIn:

Give the credentials as you selected at the time of web WordPress installation:


This will be your default welcome window of WordPress. We can check the WordPress version in browser as:

3.5 Multiple sites configuration 

Now goto Tools-->Network setup


Give the entries as follows

Network Title = Wordpress-testsite multisite
Network admin email = [email protected]

and press Install

It will yield the following window:

Add the following to your wp-config.php file in /var/www/html/wordpress/ above the line reading /* That’s all, stop editing! Happy blogging. */:

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

Give the entries as per the your output after the multisite installation. In my case it was:

/* Multisite */ define('WP_ALLOW_MULTISITE', true); define('MULTISITE', true); define('SUBDOMAIN_INSTALL', false); define('DOMAIN_CURRENT_SITE', ''); define('PATH_CURRENT_SITE', '/wordpress/'); define('SITE_ID_CURRENT_SITE', 1); define('BLOG_ID_CURRENT_SITE', 1);
 /* That's all, stop editing! Happy blogging. */

Note: In my case I am using which will be different in your case

Add the following entries to your .htaccess file in /var/www/html/wordpress/, replacing other WordPress rules:

nano /var/www/html/wordpress/.htaccess

RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

After Apache restart

systemctl restart httpd.service

Now relogin to the WordPress. After successfully setting up the Multisite Network, you need to switch to the Network Dashboard to configure network settings, add new sites, and do lots of other things. Take your mouse over to My Sites menu in the admin toolbar, a flydown popup will appear. Click on Network Admin-->Dashboard.

It will direct you to the Dashboard of the WordPress multisite.

Now you can create new site by clicking Sites-->Add New

Just add the values as per your requirement.

Congratulations! You now have a fully functional WordPress 4.0 instance with multiple site network on your CentOS 7.0 :)

Share this page:

1 Comment(s)

Add comment


From: CertDepot

Assuming that you are not executing 'setenforce 0', your website will not correctly work with your tutorial.

You need to apply 'restorecon -R /var/www/html/wordpress' and 'setsebool -P httpd_unified 1'.

Also, you should change the wordpress database prefix as a security measure.