Deploying a Laravel App on Shared Hosting — Part One
I’ve read about security issues with hosting a Laravel application on a shared server but frankly, some of us don’t have the money to buy a dedicated server.
I will be going over how I installed Laravel on a shared hosting and how to make sure there aren’t any security issues with your hosting.
Let’s get started!
I am assuming that you have built your project on your machine and it’s time to host it. So I won’t be going through setting it up on localhost.
What you’ll need.
- FTP or other form of folder access to the server
- Softaculous (not required)
Steps.
First, you follow the guide to install Laravel on your local machine and then when you have it, you can transfer the files to your server using FTP or whatever else that suits you.
If you are lucky, your server doesn’t raise permissions errors when you try to deploy on your server. However, if it does and you have tried changing permissions but are unable to get it to work, you will need stuff like Softaculous to directly install the Laravel application on your server. You can only access Softaculous if you have cPanel access to your server.
Login to cPanel, scroll to “Softaculous Apps Installer” and click on “Frameworks”
You should see a new page, the Softaculous home page. Search for Laravel and begin the installation process by setting the location of installation and clicking on install.
This should very easily install the latest version of Laravel in the specified directory.
Getting it to work securely.
The following steps apply for both installation processes, Softaculous or composer.
Now you have Laravel installed on your server, you’ll need to ftp into the directory you installed it in, hopefully you installed it somewhere in the “public_html” or “www” directory. When you get in, you will see that your directory structure is something like this:
In your “laravel_folder” in “public_html” or just “public_html” — depends on which directory you chose, you will see that there is a dummy “index.php” file which is useless, you should delete it (this happens is if you use Softaculous).
Go into your “laravel_folder” and then into your public folder, copy out the “index.php” and “.htaccess” files you have there and put them in the “laravel_folder” so that they are where the index file you initially deleted was.
Next step is to create a new folder on the same level as “public_html” and “tmp” folders so you have something like:
After doing this, copy out all the files you have in your “laravel_folder” except the “index.php” and “.htaccess” and move these files to the new folder you just created. You are moving these files because if you don’t people can access your important files like “.env” by just typing “http://yourserver.com/.env” and that is bad news.
I’ll stop here for now. The next part will show you how to edit your files so that your installation works as expected.
Consider following me on twitter @THEozmic