Skip to main content

Command Palette

Search for a command to run...

Deploy Laravel project to CPanel / Shared Hosting

Published
2 min read

Laravel is one of the most popular PHP Frameworks, the Laravel usage is mostly handled by bash command that you run in a terminal, it's called artisan, you can easily make a controller, database model, etc.

But how if we want to deploy this kind of project to a server with limited features such as CPanel or Shared Hosting? it is possible but a bit tricky, in summary, we just need to separate the public folder with the whole Laravel project files then fix the path in the code, the main thing is the public folder is shown to the visitor and the rest is in somewhere that inaccessible by visitor.

For example, I have a laravel project inside MyApp, which would be like this:

MyApp
├── app
├── bootstrap
├── config
├── database
├── public
├── resources
...

Step

  1. Create a new folder with any name, for example, we use laravel then move whole files except the public folder to the laravel folder that we just created.

  2. Rename your public folder name to fit with the server's public directory name, mostly they are named public_html and sometimes htdocs.

  3. Open file index.php inside the public folder then fix the path by replacing from /../ to /../laravel/, note that the laravel folder is the same folder we already created before in step 1.

I mean you should replace each path that contains /.../ with the proper location, here is the more obvious example:

From A PHP code highlighting path that contains "/../"

To A PHP code highlighting path that contains "/../laravel/"

That's it, you're done. Don't forget to configure the .env file.