Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

muuucho's avatar
Level 11

Delpoying Laravel on a Live server

I want to push my Laravel app to a live server and connect it to a domain like example.com The root folder on the server is public_html Is it correct that I shall push the project to one level above public_html? If yes, then I have to move the file index.php to the public_html folder. How do I tell Laravel to search in that folder to find the file?

0 likes
1 reply
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

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:

  1. Upload Your Laravel Project: Upload your entire Laravel project to the server, placing it one level above the public_html directory. Your directory structure should look something like this:

    /home/yourusername/
        ├── your-laravel-project/
        └── public_html/
    
  2. Move the public Folder Contents: Move the contents of the public folder from your Laravel project to the public_html directory. This includes the index.php file and any other assets like CSS, JavaScript, and images.

  3. Update index.php: You need to update the paths in the index.php file to point to the correct locations of the Laravel bootstrap and autoload files. Open the index.php file in the public_html directory 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.

  4. 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
    
  5. Environment Configuration: Make sure your .env file is correctly configured for the live environment, including database settings, app URL, and any other environment-specific configurations.

  6. Web Server Configuration: Ensure your web server (Apache, Nginx, etc.) is configured to serve the public_html directory. For Apache, you might have a configuration like this in your .htaccess file:

    <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.

1 like

Please or to participate in this conversation.