Multiple WordPress sites on a Ubuntu LAMP

I have been running a WordPress Testing/Development site on a Ubuntu LAMP stack. It is embarrassing how many times I broke something and reinstalled everything from the ground up. If you want to run a singe WordPress install you can read my WordPress on Ubuntu blog post. If like me you reached the point where I need to have multiple WordPress sites running locally for testing and learning this is the blog post for you.

I will be creating 3 different WordPress sites with the following steps:

  • Make three directories to store the site data
  • Start the terminal (CTRL+ALT+T)
  • $ cd /var/www
    • This will select the path for the directories
  • $ ls
    • This will show the contents of the current directory
    • Note – this command uses a lower case “L”
  • $ sudo mkdir site1 site2 site2
    • This will create three directories
  • $ ls
    • Confirm the directories were created
  • $ sudo mkdir wordpress_files
    • This is creating the directory I will use to hold the downloaded WordPress files
  • $ cd wordpress_files
    • This adds wordpress_files to the path
  • $ sudo wget https://wordpress.org/latest.tar.gz
    • This will download the latest version of WordPress from the WordPress website.
    • Note – I uses sudo because the /var/www/ path requires permission to write data.
  • $ sudo tar – xzvf latest.tar.gz
    • This will uncompress the file and create a wordpress directory to hold the WordPress files
  • $ sudo cp -r wordpress /var/www/site1
    • This will copy the wordpress directory from the current path to the site1 directory in the /var/www/site1 path
    • I have been using the files utility to confirm the steps are working correctly
  • $ sudo cp -r wordpress /var/www/site2
    • This is repeating the last step for site2.
    • Note – to do this I used the up arrow to recall the last command then backspace to delete the 1 and replace it with a 2
  • $ sudo cp -r wordpress /var/www/site3
  • $ cd ..
    • This will navigate up the path to /var/www
  • $ sudo chown www-data:www-data site1 site2 site3
    • This will change the owner of the directories
  • $ sudo chmod 755 site1 site2 site3
    • This changes file premissions for the directories
  • $ sudo mysql -u root -p
    • This will start mySQL so you can create the databases that WordPress needs.
    • The following lines are mySQL commands.
    • Note – The sudo command is needed to access the mySQL root user (at least when using Ubuntu)
  • > create database site1_db;
  • > grant all privileges on site1_db.* to ‘site1_admin’@’localhost’ identified by ‘site1_pass’;
  • > flush privileges;
  • > create database site2_db;
  • > grant all privileges on site2_db.* to ‘site2_admin’@’localhost’ identified by ‘site2_pass’;
  • > flush privileges;
  • > create database site3_db;
  • > grant all privileges on site3_db.* to ‘site3_admin’@’localhost’ identified by ‘site3_pass’;
  • > flush privileges;
  • > exit;
    • This created 3 databases with 3 users and 3 passwords
  • $ cd
    • This will return you to the home directory
  • $ cd /etc/apache2/sites-available
    • Ths will change the directorey to the location that apache2 stores the web site configuratoin files.
  • $ ls
    • This will list the configurations for the existing web sites.
  • $ sudo cp 000-default.conf site1.conf
    • This copies the default configuration file to a site1 one file so it can be edited.
  • $ ls
    • Confirm the file was created.
  • $ sudo nano site1.conf
    • This launches a text editor so the site1.conf file can be modified. The configuration file cold be edited in other ways for example Atom would work. For this post I am doing as much as possible through the terminal.
    • The following lines are the edits to the conf file.
  • ServerAdmin karl@site1.com
    • Update the Server Admin email address. This is a fake email that I don’t expect will be used however if it ever does get used having the site name here will help me trouble shoot when the email fails.
  • ServerName site1.com
    • Add the Server Name line
  • SeverAlias www.site1.com
    • Add the Server Alias line
  • DocumentRoot /var/www/site1
    • Update the Document Root line
  • CTRL+X
    • Use this command to exit
  • Y
    • This will save to the buffer
  • ENTER
    • This will exit nano
  • $ sudo cp site1.conf site2.conf
    • This will copy the configuration file that was just created so it can be edited for the next site.
  • $ sudo nano site2.conf
    • This opens nano to edit the second configuration file.
    • Edit this file the sme as the first file.
    • Copy and edit as many files as needed.
  • $ sudo a2ensite site1.conf
    • The a2ensite command will enable the site.
  • $ sudo a2ensite site2.conf
  • $ sudo a2ensite site3.conf
  • $ sudo a2enmod rewrite
    • This enables Apache’s rewrite module. I don’t know if this step was needed or not. I was in trouble shooting mode when I used this command. I was unalbe to start the WordPress installation because I couldn’t find the correct path.
  • $ sudo systemctl restart apache2
    • This will restart the web server
  • $ sudo nano /etc/hosts
    • This will open the hosts file for editing.
    • Add lines to the file for your sites as follows
  • 127.0.0.1 www.site1.com
  • 127.0.0.1 www.site2.com
  • 127.0.0.1 www.site3.com
  • CTRL+X
  • Y
  • ENTER

This was a long set of instruction but you should now be ready to install WordPress on your Ubuntu LAMP. The final step is to use a browser to launch the installation. In a browser enter the file path for the index.php file. That path should look like this. If the following doesn’t work keep reading.

www.site1.com/wordpress/index.php

I was not able to access the WordPress install with the above path. I have no clue why. What worked for me was using www.site1.com to access the files in that directory. I did this using Firefox. The only file listed was wordpress. Clicking on the file launched the WordPress installation program.

Just click on the Let’s go! button and follow the installation steps.

Hopefully this was helpful. Please contact me with any questions or comments.

karl@karlsclipboard.com