How to add a new virtual host on Ubuntu and Apache cheat sheet

Configure the domain name

Configure and test that your domain name really points to your server.




Create the MySQL database on Amazon RDS

A fast and easy tool to create a new MySQL database on Amazon RDS is the free MySQL Workbench




Create root folder

NB: Replace with your domain

cd /var/www/

Then create the domain


Change to the root folder

cd /var/www/




Create Apache virtual host

cd /etc/apache2/sites-available

Use a old config file as a template

sudo cp

Open the new config file to edit

sudo nano

Replace all occurrences of with

Activate the new configuration file

sudo a2ensite

Restart Apache to activate the new virtual host

sudo service apache2 restart




Install WordPress

Update WP-CLI

wp cli update

Download wordpress

wp core download

Generate the config file named wp-config.php

NB: Replace: dbname, user, dbpassword and dbhost with your values.

wp core config --dbname=wordpress --dbuser=user --dbpass=password --dbprefix=wp_ --skip-check

Install WordPress

NB: Replace URL, Blog Title, adminuser, password, and e-mail with your values.

wp core install --url="" --title="Blog Title" --admin_user="adminuser" --admin_password="password" --admin_email=""




Change file and folder permissions

NB: Replace “/var/www/html/” with the path to your root folder.

sudo chown -R www-data /var/www/html/ && sudo chgrp -R www-data /var/www/html/ && sudo find /var/www/html/ -type f -exec chmod 644 {} \; && sudo find /var/www/html/ -type d -exec chmod 755 {} \; && sudo chown www-data:www-data -R /var/www/html/ && sudo usermod -aG www-data ubuntu && sudo chmod -R g+w /var/www/html/ && sudo chmod 660 /var/www/html/wp-config.php

Test that everything works correctly.