Skip to main content

Installing Laravel on an Apache server was going to be a no fuss process said no developer!  Research done.  Documentation looks good and easy to follow.  Time to load Laravel.

 

The set-up

The install notes on Laravel are easy to follow.  Beginning with checking that your server is able to install Laravel.

Using shell commands check that your server has the minimum requirements.  To do this run the command php -m

-bash-4.1# php -m
[PHP Modules]
bcmath
ctype
fileinfo
json
mbstring
PDO
pdo_mysql
PDO_ODBC
pdo_pgsql
pdo_sqlite
tokenizer
xml
xmlreader
xmlrpc
xmlwriter

This list has been edited from the actual output.  If you require more information for each extension type php -i.  For these extensions it will state that it has been enabled.  Others will provide more granular details as to the current settings for the respective extension.

ctype functions => enabled

All of the extensions noted above are loaded and running their respective correct versions.  PHP has a version of 7.3.20 which you can check through running the command php -v.  

-bash-4.1# php -v
PHP 7.3.20 (cli) (built: Jul 24 2020 13:12:45) ( NTS )

So we are ready to go.

 

Using the Laravel Installer

First, download the Laravel installer using Composer:

composer global require laravel/installer

This will set-up Laravel on your server.  Next go to the home path of the domain that you will install a new Laravel instance.

cd /var/www/vhosts/{example.com}/{dir}

From this directory run

export PATH="$PATH:$HOME/.composer/vendor/bin"

To check it is working type laravel.  If the installer did its job you will see the following:

Laravel Installer 2.3.0

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  help  Displays help for a command
  list  Lists commands
  new   Create a new Laravel application

Otherwise, if Laravel wasn't installed you will see

-bash-4.1# laravel: command not found

Okay, I'm not seeing the not found command message.  However, there is an issue I wasn't expecting - version 2.3.0 rather than 3.x.  So I went back to root and ran the following command to force Laravel 3.x to be installed.

-bash-4.1# composer global require laravel/installer:3.

 

Welcome to error land

[InvalidArgumentException]                                                                       
Package laravel/installer at version 3.x has a PHP requirement incompatible with your PHP version (7.1.33)  

Wait... what PHP 7.1.33.  But when I ran php -v it is stating 7.3.20.  Somewhere it is pointing to 7.1.33.  Just need to find out where.

By the way, if you attempt to install 2.3.0 whilst PHP 7.1.33 is coming up you will receive a screen full of errors.  See the following:

  Problem 1
    - This package requires php ^7.2.5 but your PHP version (7.1.33) does not satisfy that requirement.
  Problem 2
    - Installation request for doctrine/inflector 2.0.3 -> satisfiable by doctrine/inflector[2.0.3].
    - doctrine/inflector 2.0.3 requires php ^7.2 || ^8.0 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 3
    - Installation request for doctrine/lexer 1.2.1 -> satisfiable by doctrine/lexer[1.2.1].
    - doctrine/lexer 1.2.1 requires php ^7.2 || ^8.0 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 4
    - Installation request for laravel/framework v7.24.0 -> satisfiable by laravel/framework[v7.24.0].
    - laravel/framework v7.24.0 requires php ^7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 5
    - Installation request for laravel/tinker v2.4.1 -> satisfiable by laravel/tinker[v2.4.1].
    - laravel/tinker v2.4.1 requires php ^7.2 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 6
    - Installation request for monolog/monolog 2.1.1 -> satisfiable by monolog/monolog[2.1.1].
    - monolog/monolog 2.1.1 requires php >=7.2 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 7
    - Installation request for psr/event-dispatcher 1.0.0 -> satisfiable by psr/event-dispatcher[1.0.0].
    - psr/event-dispatcher 1.0.0 requires php >=7.2.0 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 8
    - Installation request for ramsey/collection 1.0.1 -> satisfiable by ramsey/collection[1.0.1].
    - ramsey/collection 1.0.1 requires php ^7.2 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 9
    - Installation request for ramsey/uuid 4.1.0 -> satisfiable by ramsey/uuid[4.1.0].
    - ramsey/uuid 4.1.0 requires php ^7.2 || ^8 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 10
    - Installation request for symfony/console v5.1.3 -> satisfiable by symfony/console[v5.1.3].
    - symfony/console v5.1.3 requires php >=7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 11
    - Installation request for symfony/css-selector v5.1.3 -> satisfiable by symfony/css-selector[v5.1.3].
    - symfony/css-selector v5.1.3 requires php >=7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 12
    - Installation request for symfony/error-handler v5.1.3 -> satisfiable by symfony/error-handler[v5.1.3].
    - symfony/error-handler v5.1.3 requires php >=7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 13
    - Installation request for symfony/event-dispatcher v5.1.3 -> satisfiable by symfony/event-dispatcher[v5.1.3].
    - symfony/event-dispatcher v5.1.3 requires php >=7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 14
    - Installation request for symfony/event-dispatcher-contracts v2.1.3 -> satisfiable by symfony/event-dispatcher-contracts[v2.1.3].
    - symfony/event-dispatcher-contracts v2.1.3 requires php >=7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 15
    - Installation request for symfony/finder v5.1.3 -> satisfiable by symfony/finder[v5.1.3].
    - symfony/finder v5.1.3 requires php >=7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 16
    - Installation request for symfony/http-foundation v5.1.3 -> satisfiable by symfony/http-foundation[v5.1.3].
    - symfony/http-foundation v5.1.3 requires php >=7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 17
    - Installation request for symfony/http-kernel v5.1.3 -> satisfiable by symfony/http-kernel[v5.1.3].
    - symfony/http-kernel v5.1.3 requires php >=7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 18
    - Installation request for symfony/mime v5.1.3 -> satisfiable by symfony/mime[v5.1.3].
    - symfony/mime v5.1.3 requires php >=7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 19
    - Installation request for symfony/process v5.1.3 -> satisfiable by symfony/process[v5.1.3].
    - symfony/process v5.1.3 requires php >=7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 20
    - Installation request for symfony/routing v5.1.3 -> satisfiable by symfony/routing[v5.1.3].
    - symfony/routing v5.1.3 requires php >=7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 21
    - Installation request for symfony/service-contracts v2.1.3 -> satisfiable by symfony/service-contracts[v2.1.3].
    - symfony/service-contracts v2.1.3 requires php >=7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 22
    - Installation request for symfony/string v5.1.3 -> satisfiable by symfony/string[v5.1.3].
    - symfony/string v5.1.3 requires php >=7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 23
    - Installation request for symfony/translation v5.1.3 -> satisfiable by symfony/translation[v5.1.3].
    - symfony/translation v5.1.3 requires php >=7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 24
    - Installation request for symfony/translation-contracts v2.1.3 -> satisfiable by symfony/translation-contracts[v2.1.3].
    - symfony/translation-contracts v2.1.3 requires php >=7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 25
    - Installation request for symfony/var-dumper v5.1.3 -> satisfiable by symfony/var-dumper[v5.1.3].
    - symfony/var-dumper v5.1.3 requires php >=7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 26
    - Installation request for facade/ignition 2.3.5 -> satisfiable by facade/ignition[2.3.5].
    - facade/ignition 2.3.5 requires php ^7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 27
    - Installation request for mockery/mockery 1.4.1 -> satisfiable by mockery/mockery[1.4.1].
    - mockery/mockery 1.4.1 requires php ^7.3 || ^8.0 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 28
    - Installation request for nunomaduro/collision v4.2.0 -> satisfiable by nunomaduro/collision[v4.2.0].
    - nunomaduro/collision v4.2.0 requires php ^7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 29
    - Installation request for phpdocumentor/reflection-common 2.2.0 -> satisfiable by phpdocumentor/reflection-common[2.2.0].
    - phpdocumentor/reflection-common 2.2.0 requires php ^7.2 || ^8.0 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 30
    - Installation request for phpdocumentor/reflection-docblock 5.2.0 -> satisfiable by phpdocumentor/reflection-docblock[5.2.0].
    - phpdocumentor/reflection-docblock 5.2.0 requires php ^7.2 || ^8.0 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 31
    - Installation request for phpdocumentor/type-resolver 1.3.0 -> satisfiable by phpdocumentor/type-resolver[1.3.0].
    - phpdocumentor/type-resolver 1.3.0 requires php ^7.2 || ^8.0 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 32
    - Installation request for phpspec/prophecy 1.11.1 -> satisfiable by phpspec/prophecy[1.11.1].
    - phpspec/prophecy 1.11.1 requires php ^7.2 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 33
    - Installation request for phpunit/php-code-coverage 7.0.10 -> satisfiable by phpunit/php-code-coverage[7.0.10].
    - phpunit/php-code-coverage 7.0.10 requires php ^7.2 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 34
    - Installation request for phpunit/phpunit 8.5.8 -> satisfiable by phpunit/phpunit[8.5.8].
    - phpunit/phpunit 8.5.8 requires php ^7.2 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 35
    - Installation request for sebastian/global-state 3.0.0 -> satisfiable by sebastian/global-state[3.0.0].
    - sebastian/global-state 3.0.0 requires php ^7.2 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 36
    - Installation request for sebastian/type 1.1.3 -> satisfiable by sebastian/type[1.1.3].
    - sebastian/type 1.1.3 requires php ^7.2 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 37
    - Installation request for theseer/tokenizer 1.2.0 -> satisfiable by theseer/tokenizer[1.2.0].
    - theseer/tokenizer 1.2.0 requires php ^7.2 || ^8.0 -> your PHP version (7.1.33) does not satisfy that requirement.
  Problem 38
    - symfony/http-foundation v5.1.3 requires php >=7.2.5 -> your PHP version (7.1.33) does not satisfy that requirement.
    - facade/flare-client-php 1.3.4 requires symfony/http-foundation ^3.3|^4.1|^5.0 -> satisfiable by symfony/http-foundation[v5.1.3].
    - Installation request for facade/flare-client-php 1.3.4 -> satisfiable by facade/flare-client-php[1.3.4].

They all point to PHP being the wrong version of 7.1.33 rather than ^7.2.5.  However, you might have noted that mockery requires ^7.3.  Seeing that, make sure you scan through the errors and not glance over after the first few.  As it can help save an error later on.

Back on the PHP issue... the php -v is showing the correct PHP version.  You can see which PHP is being used by using the command which php

-bash-4.1# which php
alias php='/opt/plesk/php/7.3/bin/php'
  /opt/plesk/php/7.3/bin/php

Okay so it is pointing to the correct php being 7.3.

Back inside the home directory, have a look in the composer.json file.  We can tell Composer what version of PHP we are supporting with our site by using the platform configuration in our composer.json file.  Find the config area and you'll find something similar to 

"config": {
    "optimize-autoloader": true,
    "preferred-install": "dist",
    "sort-packages": true
},

There is no reference to php in the config area.  However, you will see a notation in require noting php ^7.2.25.  Back to the config, you can either edit the file directly or exit it and enter the command line to input the php version.

Edit directly using vi composer.json:

"platform": {
    "php": "7.3.20"
}

So it will look like

"config": { 
   "optimize-autoloader": true, 
   "preferred-install": "dist", 
   "sort-packages": true, 
   "platform": { 
      "php": "7.3.20" 
   }
},

Or via command line:

composer config platform.php 7.3.20

This will set the platform option in the composer.json file for us.  In this example it would add PHP 7.3.20 to the JSON file.  You can also use the -g flag to set this globally.

With composer.json file updated, run composer update again.

This time a little progression, however, a new error 

PHP Fatal error:  Declaration of Carbon\Translator::setLocale($locale) must be compatible with Symfony\Contracts\Translation\LocaleAwareInterface::setLocale(string $locale) in {your/path/to/domain/vendor/nesbot/carbon/src/Carbon/Translator.php on line 18

Declaration of Carbon\Translator::setLocale($locale) must be compatible with Symfony\Contracts\Translation\LocaleAwareInterface::setLocale(string $locale)

The fix found for this was to force the version for two plugins.... by adding the following to the composer.json file:

"require": {
    "php": "^7.2.25",
    "fideloper/proxy": "^4.2",
    "fruitcake/laravel-cors": "^2.0",
    "guzzlehttp/guzzle": "^6.3",
    "laravel/framework": "^7.24",
    "laravel/tinker": "^2.0",
    "symfony/translation": "^5.1.0",
    "symfony/translation-contracts": "^2.1.2"
 },

You will see that symphony/translation and symphony/translation-contracts were added.

Save and run composer update again.

Up and running.

We got there in the end.  Laravel 2.3 is running off 7.2.25.  I know the server is at 7.3.20 and I'll investigate how come this isn't running as anticipated.  For now let's celebrate the win of getting through the errors and having Laravel 2.3 running.  Development time.

Laravel home screen