Install WordPress Locally With Vagrant

Posted 11 months ago     957      wordpress vagrant virtualbox

Creating A Server Configuration

curl -L -o '' && curl -L -o 'Vagrantfile' && vagrant up

This command boots up the server. First time will take anywhere between 5-20 minutes.

  • You can reach the local environment via
  • The html folder within the installation directory is your root directory
  • Access to your MySQL database is as follows: Username: root, Password: root and Host: localhost.
  • Use the terminal to go to the folder you’ve installed your virtual machine in and type vagrant ssh
  • You can type mysql -uroot -p to gain access to MySQL, type root when prompted for the password

All we need is a simple empty database for WordPress which we’ll create with the following command: CREATE DATABASE wordpress

Next, go to the WordPress download page and grab the latest version. Extract it into the html directory (the root directory) and make sure to move all the files from the created wordpress sub-directory a level up.

In the end you should see the two WordPress directories (wp-admin, wp-includes) and the default WordPress files right inside your html directory.

Thanks to Hongkiat for this post

Multiple Sites?

The key to this lies in the site configuration file, the same file we used to change the ServerName. Let’s create two virtual hosts now.

First, go to the directory you created the virtual machine in and create two sub-directories: blog and store. Your original html directory should still be there as well.

Next, SSH into the server and navigate to the /etc/apache2/sites-available directory.

Next, SSH into the server and navigate to the /etc/apache2/sites-available directory.

Create two new files by copying the default config file:

cp 000-default.conf blog.conf;
cp 000-default.conf store.conf

Edit the shop.conf file using the method we discussed previously. Make sure the ServerName is set to and set the DocumentRoot directive to /var/www/shop — this is the directory we created just now.

Do the same with the blog.conf file, using the correct values.

Use the sudo a2ensite blog and sudo a2ensite shop commands to enable these sites and use the sudo service apache2 restart command to restart the server and quit the SSH connection by using the exit command.

Now edit the hosts file to make sure our computer knows how to resolve the virtual hosts:

Now you have two more sites to work with: one can be reached by typing in the URL bar and the root directory of this site will be the blog directory. The other is the site which uses the shop directory as its root.


There are no comments yet.

You need to be logged in to post comments.

Welcome to Snippet Repo!

Discover, share and save useful code snippets.

Join our community over over 2,000 members! Currently a 48% acceptance rate. Apply for membership →