To deploy a Laravel app on your Ecenica web hosting account you can follow these general steps:
- Log in to your cPanel.
- Ensure your account PHP version is set to the PHP version your Laravel app requires. See How to change PHP version
- From cPanel, open the Terminal or use SSH Access to gain shell access to your account.
- 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.
- Remove all existing files and directories in the web folder to avoid git ‘existing files’ errors.
- 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 .
- Install the project dependencies using the Composer command:
composer install --no-dev
- Create a new MySQL database in your cPanel account.
- 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
- Generate a new application key using the following command:
php artisan key:generate
- Migrate the database using the following command:
php artisan migrate
- Create a .htaccess file in your project directory and add the following lines to strip /public/ from the URL:
<ifmodule mod_rewrite.c> </ifmodule><ifmodule mod_negotiation.c> Options -MultiViews </ifmodule> RewriteEngine On # Handle Authorization Header RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteCond %{REQUEST_FILENAME} -d [OR] RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^ ^$1 [N] RewriteCond %{REQUEST_URI} (\.\w+$) [NC] RewriteRule ^(.*)$ public/$1 RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php
- 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.