Deploy Laravel project to CPanel / Shared Hosting
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
Create a new folder with any name, for example, we use
laravelthen move whole files except thepublicfolder to thelaravelfolder that we just created.Rename your public folder name to fit with the server's public directory name, mostly they are named
public_htmland sometimeshtdocs.Open file
index.phpinside the public folder then fix the path by replacing from/../to/../laravel/, note that thelaravelfolder 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

To

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