Step 1: install Apache2
sudo apt install apache2
start Apache and have it run on system boot:
sudo systemctl enable --now apache2
We’re not accessing this externally, so no need for any firewall stuff.
Step 2: Install MySQL database server
sudo apt install mysql-server
The installation output tells us that the mysqld will log errors to /var/log/mysql/error.log.
Check the server is running with:
sudo mysql
This will connect to the MySQL server as the administrative database user root, which is inferred by the use of sudo when running this command. To exit the MySQL console, type ‘exit’.
Step 3: Install PHP
sudo apt install php libapache2-mod-php php-mysql
Step 4: Create databases
Logon to the mysql server:
sudo mysql
Then:
CREATE DATABASE databaseName1db; CREATE DATABASE databaseName2db;
Now create the database users and passwords:
CREATE USER 'wp_user1'@'localhost' IDENTIFIED BY 'user1_password'; CREATE USER 'wp_user2'@'localhost' IDENTIFIED BY 'user2_password'; GRANT ALL PRIVILEGES ON databaseName1db.* TO 'wp_user1'@'localhost'; GRANT ALL PRIVILEGES ON databaseName2db.* TO 'wp_user2'@'localhost'; FLUSH PRIVILEGES; exit;
Step 5: create Apache server blocks
Now create a server block for each website:
sudo nano /etc/apache2/sites-available/site1.com.conf sudo nano /etc/apache2/sites-available/site2.com.conf
Here’s an example of the content of each .conf file:
<VirtualHost *:80> ServerAdmin admin@example.com DocumentRoot /var/www/example.com/ ServerName example.com ServerAlias www.example.com <Directory /var/www/example.com/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
Next, enable the server blocks:
sudo a2ensite site1.com.conf sudo a2ensite site2.com.conf
Step 6: create document root folder for each site
sudo mkdir -p /var/www/site1.com sudo mkdir -p /var/www/site2.com
When done, copy the latest WordPress into each folder.
Step 9: configure WordPress database settings
To create WordPress wp-config.php for each domain:
sudo cp /var/www/site1.com/wp-config-sample.php /var/www/site1.com/wp-config.php sudo cp /var/www/site2.com/wp-config-sample.php /var/www/site2.com/wp-config.php
Then open each wp-config.php file and edit the database connection info.
Step 10: Permissions, etc
Modify the directory permissions:
sudo chown -R www-data:www-data /var/www/ sudo chmod -R 755 /var/www/
Check Apache settings, enable rewrite module and restart server:
sudo apachectl configtest sudo a2enmod rewrite sudo systemctl restart apache2.service
Step 11: set up local hosts file
We need to redirect requests to serve our locally hosted sites to the local Apache server, rather than have them go out to the external internet. This is done by adding two entries to the /etc/hosts file:
sudo nano /etc/hosts
Add a line for each of our local sites:
127.0.0.1 localhost 127.0.1.1 QPC-ATTIC [XXX.XXX.XXX.XXX = IP address of local server] local_site_1.com [XXX.XXX.XXX.XXX = IP address of local server] local_site_2.com