Lurn.Cloud

Host Multiple WordPress URL(s) in Apache Server

Apache has the advantage of hosting more than one website at a time; however, setting this can be somewhat confusing at first. The outcome of the article will show you take advantage of some of the hidden features within Apache Server.

SSH into Linux Server

Site 1: example1.com
sudo mkdir -p /var/www/example1.com/html
sudo mkdir -p /var/www/example1.com/log

Site 2: example2.com
sudo mkdir -p /var/www/example2.com/html
sudo mkdir -p /var/www/example2.com/log
(This creates the necessary directories to distinguish example1.com from example2.com)

Enable Multi Site: (two Folders)
sudo mkdir /etc/httpd/sites-available /etc/httpd/sites-enabled

Next edit http.conf file to accept this:
sudo nano /etc/httpd/conf/httpd.conf

Insert: (@end of file-line below) ^x to save/exit

IncludeOptional sites-enabled/*.conf

(This enables the feature needed to allow apache route 2 separate sites)

Now Create file: for example1.com) this will direct to WP site Domain!
sudo nano /etc/httpd/sites-available/example1.com.conf

# VirtualHost example1.com WP site
<VirtualHost *:80>
     ServerName example1.com
     ServerAlias www.example1.com
     DocumentRoot /var/www/example1.com/html
     ErrorLog /var/www/example1.com/log/error.log
     CustomLog /var/www/example1.com/log/requests.log combined
</VirtualHost>

Next, create a file: for example2.com this will direct to WP site Domain!
sudo nano /etc/httpd/sites-available/example2.com.conf

# VirtualHost example2.com WP site
<VirtualHost *:80>
     ServerName example2.com
     ServerAlias www.example2.com
     DocumentRoot /var/www/example2.com/html
     ErrorLog /var/www/example2.com/log/error.log
     CustomLog /var/www/example2.com/log/requests.log combined
</VirtualHost>

Last, we need to make a Shortcut or Symbolic Link for: /etc/httpd/sites-enabled

sudo ln -s /etc/httpd/sites-available/example1.com.conf /etc/httpd/sites-enabled/example1.com.conf
sudo ln -s /etc/httpd/sites-available/example2.com.conf /etc/httpd/sites-enabled/example2.com.conf

The final step is to allow WordPress to change permalinks.

sudo nano /etc/httpd/conf/httpd.conf

Locate: <Directory “/var/www/html”>, since our URL path does not follow this path we will copy this section as follows.

example1.com

<Directory “/var/www/example1.com/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

# http://httpd.apache.org/docs/2.4/mod/core.html#options

# 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

 

#

# Controls who can get stuff from this server.

#

Require all granted

example2.com

<Directory “/var/www/example2.com/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

# http://httpd.apache.org/docs/2.4/mod/core.html#options

# 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

 

#

# Controls who can get stuff from this server.

#

Require all granted

Now save everything in nano by crl^X

I want to note that this issue took me quite a while to figure out WordPress’s default permalink structure is not SEO friendly so getting this solved was quite a relief. It was solved by a thought that flashed into my mind tried it, and we’ll it worked! Simple, but it’s amazing how we sometimes we overlook things.

To allow WordPress to work correctly, we need to change the file permissions as follows.

sudo chown -R apache /var/www
sudo chgrp -R apache /var/www

sudo chmod 2775 /var/www
find /var/www -type d -exec sudo chmod 2775 {} \;

find /var/www -type f -exec sudo chmod 0664 {} \;

sudo systemctl restart httpd
or
sudo systemctl start httpd

Enable Event MPM in Apache:

The main reason for doing this is to improve the overall performance of your WordPress Site, ie. Load times and allow Apache to show off its multitasking ability. Edit the following configuration file below.

sudo nano /etc/httpd/conf.modules.d/00-mpm.conf

Comment out “LoadModule mpm_event_module modules/mod_mpm_event.so”

Below is what is it should look like before the LoadModule mpm_prefork_module modules/mod_mpm_prefork.so was un”#.”

LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

#LoadModule mpm_worker_module modules/mod_mpm_worker.so

#LoadModule mpm_event_module modules/mod_mpm_event.so

Now swap the # as shown below.

#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

#LoadModule mpm_worker_module modules/mod_mpm_worker.so

LoadModule mpm_event_module modules/mod_mpm_event.so

Now restart Apache for the changes to take effect.

sudo systemctl restart httpd

Now, as a final check, do the following to ensure Apache has changed the module. 

httpd -V | grep MPM

You should get “Server MPM:     event”

Kevin Harrigan

AWS Certified

Hi there, I Hope I can Help. Showcasing AWS Cloud Tutorials 

Search
Topics
New Posts

Host Multiple WordPress URL(s) in Apache Server Apache has the advantage of hosting more than one website at a time; however, setting …

How to setup AWS Site to Site VPN with a $50 Router! So after passing my AWS Architect Associate exam, I noticed …

Using AWS ElastiCache Memcached with WordPress Nearly 30 percent of your website ranking according to Google SEO is determined by your website …

How To Use CloudFront with WordPress What is CloudFront:  “Amazon CloudFront is a content delivery network operated by Amazon Web Services. Content …