Cloud Operations: Deploying on a VPS
Deploying a Laravel application to Hostinger shared hosting requires a few specific adjustments, as shared environments differ from local development setups.
Deploying Your Laravel Application
Prepare Files: Upload your project files (excluding the
vendorfolder) to your domain’s root directory (e.g.,/domains/yourdomain.com/public_html).Move Public Content: Laravel expects requests to hit the
public/directory, but web servers typically serve frompublic_html/.Move the contents of your
public/directory intopublic_html/.Update the
index.phpfile inpublic_html/to point to the correct paths for yourautoload.phpandbootstrap/app.phpfiles (usually by updating the../path references).
Environment Configuration: Copy
.env.exampleto.envand update your database credentials,APP_URL, and other necessary variables.Dependencies: Use the terminal/SSH to navigate to your project directory and run:
composer install --no-dev --optimize-autoloader
Running Artisan Commands with a Specific PHP Version
When working in a shared hosting environment, simply running php artisan may use the server's default PHP version, which might not match the version required by your application.
To force a specific version for Artisan commands, you must use the absolute path to the desired PHP binary.
Find the Binary Path: You can usually find the available paths by checking the PHP configuration in hPanel, or by running
ls /usr/local/bin/php*in your SSH terminal. You will see paths like/usr/local/bin/ea-php82or/usr/local/bin/lsphp83.Execute the Command: Use the full path instead of the
phpalias:Bash
/opt/cloudlinux/alt-php84/root/usr/bin/php artisan migrate
Note: If you are unsure which binary to use, check your current PHP version on the command line by typing
php -v. If it is incorrect, use the path identified in Step 1 to run your commands.