|

How To Install WordPress on Laravel Homestead

How To Install WordPress on Laravel Homestead

The homestead virtual machine box for vagrant is a great way to set up your local testing and sandbox development environments. The cool thing about homestead is that not only can you use it for all of your Laravel specific development, but you can also make use of it for other projects like Slim, Symfony, Drupal, or WordPress. In this tutorial, we will set up WordPress on an existing homestead installation using composer.


Remind yourself of shared folder locations

Typically you have a directory on the host machine which contains all of your various projects you may be working on. For example, in our tutorial, we have a directory that lives at C:\localdev> (/c/localdev in a git client) where we place our projects. This corresponds to some settings that we will configure in the Homestead.yaml file later on. Your local directory very well may be different, just know that this is where we will install WordPress.


Use composer to install WordPress

Now that we know where we want to store the WordPress files, we can use composer to download the latest version of WordPress. Manually downloading software is so yesterday! At the command prompt navigate into your local folder and type this command.

composer create-project johnpbloch/wordpress wordpresstutorial

This installs all the files we need for WordPress with the root directory for the installation living at /c/localdev/wordpresstutorial/wordpress on the host machine. The guest machine has these files located in /home/vagrant/Code/wordpresstutorial/wordpress. Here, we open the local files in PHP Storm:
wordpress files on host machine of vagrant environment


Set a local domain in hosts file

In this step, you can choose any name you like to work with your local WordPress installation. We will use the name of wordpresstutorial.dev. Find your hosts file located in C:\Windows\System32\drivers\etc and open the file using notepad with Administrator privileges. For the domain you choose, go ahead and add the following line to the hosts file and save it.

192.168.10.10   wordpresstutorial.dev

Update Hometead.yaml

The yaml file is the way you configure the Homestead box to tell the system what ip address to use, how much memory the virtual machine should have, how many cpu’s the vm has, and which hypervisor to use among other things. The two main things we want to make note of in this tutorial are the folders section and the sites section of the yaml file. Like we discussed earlier, we can see how folders on the host machine map to the guest machine. For our installation, files in /c/localdev on the house map to /home/vagrant/Code on the guest. Great.

Under the sites section, we specify which domain maps to what location on the virtual machine. So when we type wordpresstutorial.dev into our web browser, requests will be sent to /home/vagrant/Code/wordpresstutorial/wordpress on the virtual machine. These two lines are highlighted in the yaml file below.


run vagrant provision

We’re not ready just yet! With our configuration updated, we need to now re provision our running homestead box. This tutorial assumes you already have your development environment set up for using homestead. Navigate to your /c/homestead directory from the command prompt and type

vagrant provision

You may see something like this on your screen.
vagrant provision wordpress


Create a database for WordPress

In a prior tutorial we had set up the homestead database to work with an installation of Laravel. In that tutorial we also configured a fresh install of phpMyAdmin so that we could make use of a simple graphical user interface to easily work with the database rather than the command line. Check out that tutorial if you would like to set up the same. Here we will go ahead and set up a new database named wordpresstutorial for our WordPress Installation.
create wordpress database on homestead


Visit wordpresstutorial.dev

With all of this in place, we should now be able to visit wordpresstutorial.dev in our broswer and go through the standard initial WordPress set up. Let’s try it out.

first time visit to wordpresstutorialdev

Upon clicking continue, we get this helpful message:

Welcome to WordPress. Before getting started, we need some information on the database. You will need to know the following items before proceeding.

Database name
Database username
Database password
Database host
Table prefix (if you want to run more than one WordPress in a single database)
We’re going to use this information to create a wp-config.php file. If for any reason this automatic file creation doesn’t work, don’t worry. All this does is fill in the database information to a configuration file. You may also simply open wp-config-sample.php in a text editor, fill in your information, and save it as wp-config.php. Need more help? We got it.

In all likelihood, these items were supplied to you by your Web Host. If you don’t have this information, then you will need to contact them before you can continue. If you’re all ready…
welcome to wordpress step 0
We know that the database name in our case is wordpresstutorial, the database username is homestead, the password is secret, the host is localhost, and we will use wp_ as the table prefix. We click Let’s Go.
wordpress enter database connection details step 1
Here we make a few small edits to match the configuration information we just spoke about and click on Submit. We get the cool message of “All right, sparky! You’ve made it through this part of the installation. WordPress can now communicate with your database. If you are ready, time now to…”
wordpress can now communicate with your database step 2

After clicking on Run The Install, we get a message of “Welcome to the famous five-minute WordPress installation process! Just fill in the information below and you’ll be on your way to using the most extendable and powerful personal publishing platform in the world.” Let’s fill out the basic information and then click on Install WordPress.
famous five minute wordpress installation

Once we click to install WordPress, if things go right we should get a message that says “Success! WordPress has been installed. Thank you, and enjoy!”
wordpress has been installed thank you

We can now sign in to this WordPress installation.
wordpress dashboard of fresh installation

As well as view the homepage of our new WordPress Installation.
wordpress twenty seventeen theme


How To Install WordPress on Laravel Homestead Summary

Installing WordPress on the Homestead virtual machine was pretty easy. In this tutorial we showed you exactly how to do it. We configured our shared folders, used composer to install the WordPress files, set up a local domain name, configured the yaml file, provisioned our vagrant environment, and set up a database for WordPress. Finally, we followed the navigation to go through the standard install process of WordPress once database connectivity has been established. We can see that it went quite well so great work!