Deploy Laravel 9 project in a normal hosting manually
Good morning. I have finished my project in Laravel 9, and I have many doubts to deploy it in production environment. I have watched many tutorials and videos, each one explaining it differently, and none of them fits what I want. I don't use Forge, nor Vapor, nor Nginx, nor CPanel, I just want to upload the Laravel website to a normal apache hosting.
What to do with the .env file? Currently it has all the project settings: email, database, app key, google key.... Git ignores the file with gitignore, is it supposed to copy it manually, create a new one on the server, or move it to another folder?
What files and folders should I copy to the server, do I have to load libraries and components with composer from terminal?
I appreciate any help, video or reference site that can guide me. Regards
If the Apache server is properly set up with the document root set to /public , then you don't need to do anything. Just make sure that the env isn't accessible.
If you don't have the /public document root, then you need to handle with a htaccess file and redirect all requests to /public.
I have shared a working htaccess here several times.
@Tray2 thanx for the answer. I have a problem. It is a shared hosting, so I don't have access to SSH terminal. In the hosting I have the old version of the web. Because I want both to be running, I have created a subdomain called test.mydomain.com, in a root folder called "v2", and I have uploaded the Laravel project there.
The problem is that when I open test.mydomain.com in the browser, I get a blank page. It does not give errors of any kind. Do I need an htaccess ? My .env right now is:
@narachamus A blank page used to mean that you don't have write access to the storage directory, but in your case I don't think that that is the problem. Yes you might need a proper htaccess to handle you issues.
I use something like this in my shared hosting.
#Rewrite everything to subfolder
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public
Rewriterule ^(.*)$ public/ [L]
Yes, you will create a .env file on the server with production settings
You should ideally deploy the code from a repo such as github or bitbucket
And run composer on the server to pull in all the vendor libraries.
I you are compiling your front end assets you may also need node and npm in order to compile on the server. I don't, I compile locally, commit the assets to version control and pull them in on the server.
Under Apache create a host (or virtual host) that points to the laravel public folder.
You don't want forge or cpanel so I assume you are familiar with setting all this up and setting the correct file system permissions etc?