Install drupal on subdirectory with laravel and nginx- how to

Submitted by lwinmaungmaung on
Image by teru_teru from Pixabay

Installing drupal in a directory is one of the most headache things in configuring. If you are using with Nginx and want to use together with Laravel or some framework which is a bit tricky to use with public folders, working together with Drupal and Laravel is the most tricky all around the table. For now, we will install drupal subdirectory laravel nginx.

Before start working with install Drupal in a subdirectory, We have to work with Laravel and Drupal Project Mix. Laravel is working with a public folder then we have to set up working with public folder first.

Our setup will undergo the followings:

  1. Setup Main Laravel Website with public folder extension
  2. Install Drupal on a different folder
  3. soft-linking (shortcut) back to Main Laravel Website
  4. configure NGINX to final work

Requirement

In this tutorial, I have used VPS and have ssh access to your server. If you have already installed Laravel, you should add a link to the public folder.

The folder of the structure will be as follows:

  • Your public_html folder
    • Laravel directory
      • public
        • blog folder (symbolic link)
    • Your blog

I'll skip something in this post. Install Laravel and Your blog inside your VPS.

  1. Install Laravel in your directory
  2. Install blog in the same level directory of your home

If you install in /home/user, your folders should be /home/user/$laravel and /home/user/$blog.

So, we are now soft linking your blog to your laravel installation to smooth drupal subdirectory laravel nginx. We run the following command:

ln -s /home/user/$laravel/public/blog /home/user/$blog/

When you view the folder, you will see the blog in the public folder. We store the blog under public folder because Laravel will run under the public folder. The routes are under the public directory then we have to put our symbolic link under the public folder to work properly.

 

NGINX configuration

We should configure nginx as follows to work drupal subdirectory laravel nginx:

rewrite ^/blog/core/authorize.php/core/authorize.php(.*)$ /blog/core/authorize.php$1;

 

        location /blog/{

                index index.html index.htm index.php;

                autoindex_exact_size off;

                autoindex_localtime on;

                try_files $uri /blog/index.php?$query_string;

                #try_files $uri $uri/ /blog/index.php?$args;

                location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {

                        try_files $uri @rewrite;

                        expires max;

                        log_not_found off;

                }

                location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7

                        try_files $uri @rewrite;

                }

        }

install drupal subdirectory laravel nginx

Installing drupal under subdirectory using laravel and then configuration of nginx will be easy for now. If you have some problem, you can reach us via ABOUT SECTION of our website. Thank you for your time.

Category