3

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?

prakashchhetri
  • 1,806
  • 4
  • 36
  • 61

1 Answers1

0

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.

Trevor
  • 1,111
  • 2
  • 18
  • 30
  • can I simply just modify the root path for my subdomain and would that work? – prakashchhetri Jul 01 '19 at 05:02
  • Is there anyway I can do it without changing the virtual hosts file? My hosting provider is recommending against it. – prakashchhetri Jul 01 '19 at 05:18
  • @prakashchhetri modifying the root path should do the trick. That's what the configuration is doing - the DocumentRoot directive. – Trevor Jul 01 '19 at 09:24
  • I've provided an alternative method however depends on if the hosting provider allows .htaccess overrides. Try modifying the root path first as per the DocumentRoot directive first. – Trevor Jul 01 '19 at 09:26
  • @prakashchhetri How did you go with this? – Trevor Jul 05 '19 at 06:55
  • It did not work. My hosting provider is advising me against modifying virtual hosts file, and changes to the .htaccess file did not solve the deployment issue with the staging server. – prakashchhetri Jul 08 '19 at 03:02
  • @prakashchhetri there is not a lot you can do. It seems very strange to recommend against changing a virtual host conf file. Maybe try a different hosting provider. – Trevor Jul 11 '19 at 04:26