Laravel

How to Deploy a Laravel app to Ecenica

To deploy a Laravel app on your Ecenica web hosting account you can follow these general steps:

  1. Log in to your cPanel.
  2. Ensure your account PHP version is set to the PHP version your Laravel app requires. See How to change PHP version
  3. From cPanel, open the Terminal or use SSH Access to gain shell access to your account.
  4. Navigate to the web directory of your domain. This is typically the public_html folder for the primary domain, or a sub-folder for addon domains.
  5. Remove all existing files and directories in the web folder to avoid git ‘existing files’ errors.
  6. Clone your Laravel project. For example, we will clone the base Laravel project repository using the Git command below. But you’d use your own repository, whether it’s on Github or Bitbucket. Alternatively you can upload your Laravel app using FTP or the cPanel File Manager.
    git clone https://github.com/laravel/laravel.git .
  7. Install the project dependencies using the Composer command:
        composer install --no-dev
        
  8. Create a new MySQL database in your cPanel account.
  9. Navigate back to your Laravel project directory, copy the .env.example file to .env and update the database credentials in the file:
        cp .env.example .env
        nano .env
        
  10. Generate a new application key using the following command:
        php artisan key:generate
        
  11. Migrate the database using the following command:
        php artisan migrate
        
  12. Create a .htaccess file in your project directory and add the following lines to strip /public/ from the URL:
    <IfModule mod_rewrite.c>
        RewriteEngine On
    
        # Handle Authorization Header
        RewriteCond %{HTTP:Authorization} .
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    
        # Prevent direct access to directories and files
        RewriteCond %{REQUEST_FILENAME} -d [OR]
        RewriteCond %{REQUEST_FILENAME} -f
        RewriteRule ^ - [L]
    
        # Redirect requests for static files to the public directory
        RewriteCond %{REQUEST_URI} (.w+$) [NC]
        RewriteRule ^(.*)$ public/$1 [L]
    
        # Redirect all other requests to index.php
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
    </IfModule>
    
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>
        
  13. Create a file index.php at the project directory root to point traffic to /public/:
    <?php
    
    /**
     * Laravel - A PHP Framework For Web Artisans
     *
     * @package  Laravel
     * @author   Taylor Otwell <taylor@laravel.com>
     */
    
    $uri = urldecode(
        parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
    );
    
    // This file allows us to emulate Apache's "mod_rewrite" functionality from the
    // built-in PHP web server. This provides a convenient way to test a Laravel
    // application without having installed a "real" web server software here.
    /*if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
        return false;
    }*/
    require_once __DIR__.'/public/index.php';
    

That’s it! Your Laravel app should now be successfully deployed on your Ecenica web hosting account.

Was this guide helpful?

Need help with this?

Open a ticket and link to this guide so our team can see what you have tried.

View support tickets

Power your business with Ecenica Hosting

Built for WordPress and serious websites. Fast, secure and supported by real people in the UK.

Ecenica hosting services represented by a connected red route across London