Skip to main content

Installing Laravel on a server with FASTPANEL

The installation is done using composer. The domain used as an example is example.com and the user of the site is user.

Preparation

Installing Composer

Install composer in FASTPANEL® in the "Applications" section

Applications management menu in FASTPANEL

Installing composer in FASTPANEL

Creating a website

Create a website in FASTPANEL® and specify the public subdirectory in the site settings in the "Site Directory" section.

Specifying the public subdirectory

Creating a project

To create a project, you need to connect to the server via SSH using the data of the site owner. The site owner is shown in the site card in FASTPANEL

Checking the site owner in FASTPANEL

After SSH connection is established, you should clear the site directory using the following command example (instead of example.com specify your site name)

rm -rf /var/www/user/data/www/example.com/*

Then go to the site directory

cd /var/www/user/data/www/example.com

And create a project

composer create-project laravel/laravel ./
Example of output in case of correct installation

73 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package fruitcake/laravel-cors is abandoned, you should avoid using it. No replacement was suggested.
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/sail
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
76 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi --force
No publishable resources for tag [laravel-assets].
Publishing complete.
No security vulnerability advisories found
> @php artisan key:generate --ansi
Application key set successfully.

Installing a specific version of Laravel

To install a specific version, when creating a project, you must specify the version at the end of the command in quotation marks

composer create-project laravel/laravel ./ "5.8.*"

Database connection

  • For artisan specify the data to connect to the database in the file.env in the site directory
  • For the site, specify the data to connect to the database in the file ./config/database.php

To edit the .env file you may use a text editor called nano via SSH:

nano .env
Example of .env

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=site_db
DB_USERNAME=db_user
DB_PASSWORD=0j9vd3qATwTsXW7C

To edit the ./config/database.php file via SSH:

nano ./config/database.php
Example of ./config/database.php

    'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'site_db'),
'username' => env('DB_USERNAME', 'db_user'),
'password' => env('DB_PASSWORD', '0j9vd3qATwTsXW7C'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],

In the nano editor, Ctrl+O is used to save changes, Ctrl+X is used to exit the editor.

Memcached connection (optional)

You need to install the PHP memcached module for the PHP version used on the site, as well as install the application.

Installing the memcached PHP module

PHP management menu in FASTPANEL

Install PHP memcached module in FASTPANEL

Installing the memcached application

Applications management menu in FASTPANEL

Install memcached application in FASTPANEL

Editing a configuration file

Specify the data to connect to memcached in file ./config/cache.php

Example of ./config/cache.php

'memcached' => [
'driver' => 'memcached',
'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),
'sasl' => [
env('MEMCACHED_USERNAME'),
env('MEMCACHED_PASSWORD'),
],
'options' => [
// Memcached::OPT_CONNECT_TIMEOUT => 2000,
],
'servers' => [
[
'host' => env('MEMCACHED_HOST', '127.0.0.1'),
'port' => env('MEMCACHED_PORT', 11211),
'weight' => 100,
],
],
],

Using Artisan on a non-system version of PHP

To use artisan on a non-system version of PHP, you must specify the full path to the executable file. Example of using an alternative php version 8.2:

/opt/php82/bin/php artisan list

Basic Artisan commands

Commands should be executed in a root directory of your project (example.com in this example)

cd /var/www/user/data/www/example.com

To view a list of all available Artisan commands, you can use the command

php artisan list

Launch a local Laravel development server. You can specify the --host and --port keys

php artisan serve

Start migration

php artisan migrate

Enabling maintenance mode on the site, key --redirect=/ to specify the page for maintenance mode

php artisan down

Turning off the maintenance mode on the site

php artisan up