Laravel and WordPress Integration – Installation

Laravel and WordPress Integration – Installation

install-wordpress-with-laravel-in-same-domain-in-folder-blog

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 headstart. 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.

Share this Post:

About Raunak Gupta

I'm an expert Laravel, WooCommerce, WordPress theme and plugin developer, over the time I have developed several sites and applications. I like to help the upcoming developer, So I share my experience through this blog.  

Related Posts:

Leave a Comment

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


*