Deploy your Laravel app on Plesk.

Before I started writing this article, I read at least 15 different articles about it. Unfortunately, none of them have the complete guide. I am going to write down every piece of information here so that one can start and finish deploying his project without thinking twice.

Follow all the steps below. You don’t need to use SSH. All can be set through the Plesk interface whether it is shared hosting or not.

Step: 1. Determine your website or web app requirements –

  • Are you migrating an existing Laravel website? – then make sure you’ve all the files or FTP access.
  • Do your website or web app is going to have a database?

Let’s start knowing how to deploy or migrate an existing Laravel website in Plesk.

  1. Login to Plesk interface. Add a domain. Click “Domains” > “add a domain“.
  2. Go to “Schedule Tasks” > Select “Run a command” > and copy and paste this command  cd httpdocs/ && /opt/plesk/php/7.1/bin/php /usr/lib64/plesk-9.0/composer.phar create-project laravel/laravel –prefer-dist . Only replace the PHP version. For example – if PHP version is 7.2.21, replace 7.1 with 7.2
  3. Nothing else need to change, just click “ok” and then “Run Now”. This will install the Laravel project folders inside httpdocs/laravel.
  4. Go inside the “laravel” folder and select all and move all folders and files inside “httpdocs”. I can be done in two ways. Using the “move” button in plesk navigation or by archiving > downloading and then uploading the zip into httpdocs.
  5. Once all folders are in httpdocs/ . Go to “Hosting settings“, change the public folder like this. /httpdocs/public
  6. Then Go to ” Web hosting access” > Access to the server over SSH > /bin/bash (This step is not needed for some who have access to phpmyadmin.)
  7. Create database and keep record of DB_name, user and password.
  8. Change the db credentials here . httpdocs/config/database.php
  9. Make sure if you are migrating an existing website that .htaccess and index.php file has the following codes –
#.htaccess
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
#index.hph
<?php
define('LARAVEL_START', microtime(true));
require __DIR__.'/../vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);

You are good to go. Cheers!

Leave a Reply