To deploy a Laravel application on a live server where the root folder is public_html, you should indeed place your Laravel project one level above public_html. Here are the steps to achieve this:
-
Upload Your Laravel Project: Upload your entire Laravel project to the server, placing it one level above the
public_htmldirectory. Your directory structure should look something like this:/home/yourusername/ ├── your-laravel-project/ └── public_html/ -
Move the
publicFolder Contents: Move the contents of thepublicfolder from your Laravel project to thepublic_htmldirectory. This includes theindex.phpfile and any other assets like CSS, JavaScript, and images. -
Update
index.php: You need to update the paths in theindex.phpfile to point to the correct locations of the Laravel bootstrap and autoload files. Open theindex.phpfile in thepublic_htmldirectory and modify the following lines:require __DIR__.'/../your-laravel-project/vendor/autoload.php'; $app = require_once __DIR__.'/../your-laravel-project/bootstrap/app.php';This tells Laravel to look for the autoload and bootstrap files in the correct directory.
-
Set Permissions: Ensure that the storage and cache directories are writable by the web server. You can set the permissions using the following commands:
chmod -R 775 /home/yourusername/your-laravel-project/storage chmod -R 775 /home/yourusername/your-laravel-project/bootstrap/cache -
Environment Configuration: Make sure your
.envfile is correctly configured for the live environment, including database settings, app URL, and any other environment-specific configurations. -
Web Server Configuration: Ensure your web server (Apache, Nginx, etc.) is configured to serve the
public_htmldirectory. For Apache, you might have a configuration like this in your.htaccessfile:<IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews -Indexes </IfModule> RewriteEngine On # Redirect Trailing Slashes If Not A Folder... RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ / [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] # Handle Authorization Header RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] </IfModule>
By following these steps, you should be able to deploy your Laravel application to a live server with the root folder as public_html. If you encounter any issues, make sure to check the server error logs for more details.