Laravel and WordPress Integration – Installation

[PHP] Checkout what happens when world best CMS meets with the most popular MVC framework. It is a series of the tutorial where you can learn how to integrate WordPress and Laravel.

Laravel is one of the highly used, open-source modern web application frameworks to designs customized web applications quickly and easily. Developers prefer Laravel over to other frameworks because of the performance, features, scalability it offers, and on the other hand, WordPress is one of the most popular open source content management applications to develop Blog, Forum, and news feed, because of it vertical features and available plugin bank.
So today we thought why not get our hands dirty with this two together, and help our readers to give good head-start. In this series, we will be explaining how to install WordPress inside a Laravel application and get the WordPress post into Laravel.

Assuming we have a Laravel website running on example.com and its physical path is /public_html/. Now we want to create a Blog using WordPress as example.com/blog/, so we need to install WordPress in /public_html/blog/. Upload all the WordPress files in /blog/ directory. Now we have have edit the .htaccess of both the application so that Laravel should escep blog request for WordPress to process it.

.htaccess for Laravel

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On
    RewriteCond $1 !^(blog) #<-- Add this line
    # Redirect Trailing Slashes If Not A Folder…
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller…
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

.htaccess for WordPress

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/ #<- this line is modified.
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L] #<- this line is modified.
</IfModule>
# END WordPress

Now we can directly access example.com/blog/wp-admin/ to install WordPress and set the permalink structure to Post name or any other beautiful URL structure.

In Next tutorial we'll be learning as how to access WordPress post in Laravel.

Raunak Gupta

Raunak Gupta

I'm Raunak Gupta, a seasoned software developer with over 9 years of experience in a wide range of programming languages, frameworks, and tools. I started my journey as a WordPress & CakePHP developer in 2014, diving deep into the world of OOPs, Request handling, and SEO. Along the way, I crafted numerous dazzling WooCommerce stores, tamed payment gateways, optimized for full filament functionality, and achieved ultra-low latency for lightning-fast load times. My expertise extends to BI tools, website builders, DevOps, and team leadership. I like to help upcoming developers, so I share my experience through this blog and by assisting fellow developers on Stack Overflow, where I've earned a stellar reputation with over 10k+ points of recognition.

Articles: 29

Leave a Reply

Your email address will not be published. Required fields are marked *