Create a Local Server with Vagrant for WordPress

 

It is a great method to have a server on your website without dirtying your computer. The bad thing is that if a problem arises you have to have advanced knowledge to fix it.

We will always have MAMP y ServerPress 😉

To configure Vagrant you need to follow these steps:

Install virtual Box 

Install Vagrant

I'm going to explain how to do it on MAC, on linux I guess it's the same and on windows I'm not sure 🙂

Now we open a console terminal and put:

git clone git@github.com:10up/varying-vagrant-vagrants.git wordpress

This will cause us to clone the repository to the wordpress folder

In our host file (/etc/hosts) we have to add the following line:

192.168.50.4 local.wordpress.dev local.wordpress-trunk.dev

We go to the folder we have created called wordpress and put:

vagrant up

It will take a while (especially the first time) and it will create a virtual machine so that we can use our computer as a server to work on wordpress locally.

Once it finishes we can write in our browser: local.wordpress.dev and if everything has gone well we have our wordpress working 🙂

More information here (In English)

Add more wordpress installations in the same virtual machine.

The first thing we do is go to the /config/nginx-config/sites folder

In this folder you will see several .conf files, copy any of them, put the name of the domain you want to use local.tuweb.com.conf and edit it:

You have to edit two lines:

1- server_name local.yourweb.com;

2- www directory: root /srv/www/yourweb;

Now you go back to the root directory and enter the database directory and copy the file init-custom.sql.sample and give it the name init-custom.sql

And for each wordpress you want to install you create a database as follows:

CREATE DATABASE IF NOT EXISTS `database`; GRANT ALL PRIVILEGES ON `database`.* TO 'user'@'localhost' IDENTIFIED BY 'password';

We return to the root folder, enter the www folder and copy the entire wordpress folder to a new folder with the name we put in point 2 above: tuweb

We can copy all the content in the following way:

cp -rv wordpress-default/ tuweb

We enter the new folder and delete the wp-config.php file:

rm -rf tuweb/wp-config.php

Add the following line to the /etc/hosts file:

192.268.50.4 local.yourweb.com

Now we just need to go back to the root directory and write:

vagrant up

If we write local.tuweb.com we should see our new wordpress

If the new website does not work for you, try typing:

vagrant provision

Sometimes when you add new websites you need to add provision for the changes to take effect.

 

regards

Oscar

1 comment on “Create a Local Server with Vagrant for WordPress”

Leave a comment