How to Install Laravel in Plesk using SSH

In plesk, to install laravel, we need to do two prerequisites first.

  1. Enable SSH for the Plesk User:

2. Add default PHP binary to Plesk Shell to allow using Composer:

Once the above steps are done, now, you may install the laravel installer with the following:

[elastic-keldysh@pl1 ~]$ composer global require laravel/installer
Changed current directory to /var/www/vhosts/elastic-keldysh.139-99-24-82.plesk.page/.composer
Using version ^4.0 for laravel/installer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 12 installs, 0 updates, 0 removals
  - Installing symfony/polyfill-php80 (v1.18.1): Downloading (100%)
  - Installing symfony/process (v5.1.6): Downloading (100%)
  - Installing symfony/polyfill-mbstring (v1.18.1): Downloading (100%)
  - Installing symfony/polyfill-intl-normalizer (v1.18.1): Downloading (100%)
  - Installing symfony/polyfill-intl-grapheme (v1.18.1): Downloading (100%)
  - Installing symfony/polyfill-ctype (v1.18.1): Downloading (100%)
  - Installing symfony/string (v5.1.6): Downloading (100%)
  - Installing psr/container (1.0.0): Downloading (100%)
  - Installing symfony/service-contracts (v2.2.0): Downloading (100%)
  - Installing symfony/polyfill-php73 (v1.18.1): Downloading (100%)
  - Installing symfony/console (v5.1.6): Downloading (100%)
  - Installing laravel/installer (v4.0.5): Downloading (100%)
symfony/service-contracts suggests installing symfony/service-implementation
symfony/console suggests installing symfony/event-dispatcher
symfony/console suggests installing symfony/lock
symfony/console suggests installing psr/log (For using the console logger)
Writing lock file
Generating autoload files
10 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
[elastic-keldysh@pl1 ~]$

Once this is done, you may try to install laravel using the laravel command:

[elastic-keldysh@pl1 ~]$ laravel new blog
-bash: laravel: command not found

But, as you can see it is failed. It’s because the laravel binary is installed in the following path:

/var/www/vhosts/elastic-keldysh.139-99-24-82.plesk.page/.composer/vendor/bin

which doesn’t exist in our $PATH variable. Now you may add the above command to your PATH variable using the following tutorial:

I believe, you have already figured it out, it is as simple as the following command:

PATH=$PATH:/var/www/vhosts/elastic-keldysh.139-99-24-82.plesk.page/.composer/vendor/bin

Now, you may run the following to install laravel:

[elastic-keldysh@pl1 ~]$ laravel new blog

 _                               _
| |                             | |
| |     __ _ _ __ __ ___   _____| |
| |    / _` | '__/ _` \ \ / / _ \ |
| |___| (_| | | | (_| |\ V /  __/ |
|______\__,_|_|  \__,_| \_/ \___|_|

Creating a "laravel/laravel" project at "./blog"
Installing laravel/laravel (v8.0.3)
  - Installing laravel/laravel (v8.0.3): Downloading (100%)

So, yeah, as laravel says, Application ready! Build something amazing.

How to run Composer in Plesk User Shell / Plesk PHP

There are couple of ways you can run composer with Plesk Shell. My favorite one is to add php to your PATH variable, and it will automatically add the composer as well. You may follow through the following to modify your shell path variable to use Plesk PHP:

Once done, now you may run composer command and it shall work:

[elastic-keldysh@pl1 ~]$ composer -V
Composer version 1.10.5 2020-04-10 11:44:22
[elastic-keldysh@pl1 ~]$

The other way, is to directly use the composer.phar given from Plesk 9.0 library. This file is available under the following location:

/usr/lib64/plesk-9.0/composer.phar

So, you may run this using the following:

[elastic-keldysh@pl1 ~]$ /opt/plesk/php/7.4/bin/php /usr/lib64/plesk-9.0/composer.phar -V
Composer version 1.10.13 2020-09-09 11:46:34

This should work too. You may choose any, and it shall work for you. Good luck.

How to Fix /usr/bin/env: ‘php’: Permission denied in Plesk

If you are seeing an error like the following in your Plesk:

bash-4.4$ laravel
/usr/bin/env: ‘php’: Permission denied

Your binary to php is probably being used through redirection like .bashrc file and an alias is hooked for your php command to work. A better way to do this, is to hook the php binary to your PATH variable. You may do this and fix the error by following this tutorial:

Hope this helps. Thanks.

How to Add PHP in Default Path for Plesk / How to Fix -bash: php: command not found for Plesk User

If you have added SSH access to your plesk user using the following tutorial:

and then, tried to run php command like the following:

[elastic-keldysh@pl1 ~]$ php -v
-bash: php: command not found

You might have encountered the above error. This is because plesk do not store the php binary in your PATH variable locations. You may check your existing path variables here:

[elastic-keldysh@pl1 ~]$ echo $PATH
/usr/share/Modules/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin

Plesk stores it’s php binaries for different versions here:

/opt/plesk/php/

So, for example if you are trying to use PHP 7.4 binary, this would be like the following:

[elastic-keldysh@pl1 php]$ /opt/plesk/php/7.4/bin/php -v
PHP 7.4.10 (cli) (built: Sep  4 2020 03:49:35) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with the ionCube PHP Loader + ionCube24 v10.4.2, Copyright (c) 2002-2020, by ionCube Ltd.
    with Zend OPcache v7.4.10, Copyright (c), by Zend Technologies

So, to use only php -v, you need to add this bin path to your path variable. You may do that by running the following command:

PATH=$PATH:/opt/plesk/php/7.4/bin/

Now, you may run the following and it will work:

[elastic-keldysh@pl1 php]$ php -v
PHP 7.4.10 (cli) (built: Sep  4 2020 03:49:35) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with the ionCube PHP Loader + ionCube24 v10.4.2, Copyright (c) 2002-2020, by ionCube Ltd.
    with Zend OPcache v7.4.10, Copyright (c), by Zend Technologies

Now, we need to remember, this will only sustain for the existing session, if we log out and re login, this would be lost. To keep this permanent on each login, we need to put this in the .profile file. You may do this by running the following:

echo "PATH=$PATH:/opt/plesk/php/7.4/bin/" >> .profile

Once done, now you may try to login back again and see php -v is still working:

[elastic-keldysh@pl1 ~]$ exit
logout
[root@pl1 ~]# su - elastic-keldysh
Last login: Thu Oct  1 13:42:13 IST 2020 on pts/0
[elastic-keldysh@pl1 ~]$ php -v
PHP 7.4.10 (cli) (built: Sep  4 2020 03:49:35) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with the ionCube PHP Loader + ionCube24 v10.4.2, Copyright (c) 2002-2020, by ionCube Ltd.
    with Zend OPcache v7.4.10, Copyright (c), by Zend Technologies
[elastic-keldysh@pl1 ~]$

How to Enable SSH in Plesk User Domain

After you have created the domain from Plesk panel, go to Websites & Domains List, click on your domain to view details of your domain settings.

Now click on FTP access, and from the List click on the main username. In the FTP details for the user page, you will see an option says ‘Access to the server over SSH’ with a drop down that primarily says ‘Forbidden’. You may select the kind of SSH, you would like to give to your user. If you are familiar with the ‘jailshell’ in Cpanel, then it is the option that says ‘/bin/bash (chrooted)’, or you may select /bin/bash to give them normal shell.

Now, you may press ‘Apply’ to set SSH access to the user.