How to add a WordPress Blog to your Laravel Application

Laravel WordPress Integration

If you have a custom built Laravel Application and would like to add a WordPress Blog on the same domain, you’re in luck because this is pretty easy to do if you follow a few simple guidelines. Of course you have the option of building an entire blog system yourself right in Laravel, but it would be a lot of work to do it right, and why reinvent the wheel? WordPress is trusted and rock solid as a blogging platform, so let’s just install it alongside our Laravel Application. We will assume use of a LEMP stack for this example of laravel and wordpress together.


1. Download A Copy of WordPress

Head on over to https://wordpress.org/download/ and download the latest copy of the software available. When you download the file, it will be in a zipped package. Place it anywhere you like, we will unzip the files and install them in the correct location in the next step.


2. Create a Blog Directory For The WordPress Files

For this Laravel and WordPress integration, we will configure things so that when you visit the Laravel application that currently lives on the root domain, you will be able to add a /blog to the domain and reach your blog. For example, if your Laravel domain is http://laravelapp.io, we will configure the ability to visit http://laravelapp.io/blog with full support for pretty URLs, administration control, and all the other bells and whistles of WordPress without disturbing the existing Laravel application. This is how to complete the laravel wordpress integration.

  • Create a blog directory within the public directory of your Laravel Install
  • Place all the WordPress Files in the blog directory
  • Create a new database on your server to support the new WordPress install
  • Update your nginx configuration to support WordPress and Laravel Simultaneously
  • Restart the nginx service
  • Install WordPress

notes: Again, we make a few assumptions for this tutorial. One being that you have your own VPS, and two being that it is a LEMP stack. LEMP is Linux, Nginx, MySQL, and PHP. Your own VPS gives you the ability to create an additional database easily. It’s a good idea to keep the database from your main application and the WordPress database separate. If you we’re looking to combine the two, there are ways to do that, but not in this tutorial.

The index.php file in the public directory is the entry into your Laravel application. You will load the WordPress files into the public/blog directory such that the index.php file for WordPress exists in blog. This is the entry into your WordPress blog.


3. Create a database for the WordPress install

If you have a GUI tool such as phpmyadmin installed, this will be a cinch. If not, you can still ssh into your VPS and create the new database from the command line without too much trouble. For our example, we used the name wordpress as the new database name.


4. Update The Nginx Configuration

This is an example configuration that should work. Replace the example domain name with your own.

Once you have updated the nginx configuration file, found in /etc/nginx/sites-available, be sure to restart the nginx service via sudo service nginx restart.


5. Configure wp-config.php

Set up your database configuration for the blog by renaming wp-config-sample.php to wp-config.php and fill in the credentials to connect to the new database you created in step 3. A snippet of that configuration file might look a bit like this.


6. Run Through the WordPress Install

With all of the legwork out of the way, you can now point a browser to http://laravelapp.io/blog and you will be greeted with the familiar install screen of a WordPress installation. Fill out the fields as needed and submit the data, and you should now have your working blog right alongside your Laravel application on the same domain.

How to add a WordPress Blog to your Laravel Application Summary

Well there you have it, you now know how to combine laravel and wordpress together so you can have a custom laravel application running on the same domain as a blog which may be used to support your Laravel service. Have fun!