Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

whitenoize's avatar

Laravel on shared hosting PHP version problem

Hi, this is my first time on the forum, so I hope I'm posting the question the right way.

Does anyone have a solution how to deploy Laravel application on a shared hosting. I know it's not generally recommended, but for now this is the only way to go for me. I am using a shared CPanel based hosting on hostgator. My directory structure looks something like this:

home mywebsite - folder that has everything except for laravel public folder public_html mywebsite - contents of laravel public folder

I've been struggling to upgrade the PHP version since hostgator is still stuck on v7.4. They do have an option to switch to a newer version, but that only affects the contents of the public_html directory. Since most of my files, including the artisan, are located outside of it, that change does not affect my application. I've been told by their customer service that they cannot set the php version for my home directory itself. I don't see any solution other than to put all files under public_html folder, but that would then expose my private files (.env etc). Is there anything else I could try?

0 likes
3 replies
whitenoize's avatar
  • home
    • mywebsite - everything except laravel public folder
    • public_html
      • mywebsite - contents of laravel public folder
Webforward's avatar

Home Directory

Ideally, you want your host to change your public path to public_html/public and then place your entire Laravel application in the public_html directory. I think the new versions of cPanel allow you to do this in domain management unless your host has this disabled.

PHP

Typically, shared hosting platforms run multiple versions of PHP but have a default version set. As far as I am aware, distributions like Ubuntu support multiple versions to be installed, but the command php can only represent one version system-wide.

Instead of running a command like php artisan ..., you would run the specific version of PHP you require.

For example, on cPanel, it is something like this: /opt/cpanel/ea-php83/bin/php artisan ...

As for running composer, you would write something like /opt/cpanel/ea-php83/bin/php /usr/local/bin/composer install

You also switch the site to PHP 8.3.

hammamzarefa's avatar

You can change php version by add this line to htaccess AddHandler application/x-httpd-php81 .php

change php8.1 to your version

Please or to participate in this conversation.