Laravel deployment via Envoyer to Cpanel

497 Views Asked by At

I have a VPS running WHM and Cpanel. I have multiple domains hosted there. Say one of them is example.com

What I am intending to do is have two versions of the application. Production: example.com > /public_html/ Development: staging.example.com > /public_html/staging/

Right now, I am trying to deploy my application to the development environment, i.e to the staging folder.

Envoyer, with a lot of struggle with my hosting provider, is working fine. It's uploading the files as expected. The only issue now is the symbolic link current

Right now the folder structure is:

-staging
    - releases
        -release1
        -release2
    - current

My subdomain clearly points out to the staging folder, which will lead it to display all the contents of the folder rather than the application.

Since the application is inside the release folder, how do I make sure that my application runs when we hit the subdomain.

Do I have to modify my virtual hosts file in Apache?

1

There are 1 best solutions below

7
On

Laravel requires the root for the domain (configured in the relevant apache vhost conf file) to be it's 'public' folder. This is where it's entry point index.php is.

Edit the apache vhosts conf file as per below

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot "/home/user/public_html/public"
    <Directory "/home/user/public_html/public">
        Options Indexes FollowSymLinks
        AllowOverride all
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName staging.example.com
    DocumentRoot "/home/user/public_html/staging/public"
    <Directory "/home/user/public_html/staging/public">
        Options Indexes FollowSymLinks
        AllowOverride all
        Allow from all
        Require all granted
    </Directory>
</VirtualHost>

For example.com you install your laravel application into /home/user/public_html folder.

As part of the laravel install it will create the 'public' folder.

For staging.example.com you install your laravel application into /home/user/public_html/staging folder.

Don't forget to restart the web server so it picks up the new configuration.

If you do not have the ability to change the vhost configuration mentioned above, you can use .htaccess file in your public_html folder (note the leading full stop which makes it a hidden file). The following is dependant on your hosting provider allowing .htaccess overrides.

Add the following to the .htaccess file:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

If domain has been set up correctly by the host to point to /home/username/public_html when entering http://example.com then it should automatically call public/index.php.

You will need to do the same in public_html/staging folder.