How to Set Up Laravel

Laravel is a free, open-source PHP framework used for software development that can be installed on both Linux personal computers and servers. While installing Laravel via the application installer Softaculous, you may have come across an error message such as this this:

Required PHP version greater than equal to 7.2.5 found version is : 7.1.3

In order to work around this issue, we need to perform a manual install of Laravel. In this article, we will outline the steps to set up Laravel via SSH. Please note that in order to complete the steps in this guide, you will first need to set up an SSH connection on your machine.

Topics Include: 

Install Laravel on your Dedicated Hosting plan to start developing PHP applications today!

Laravel Installation 

Please refer to the Laravel installation documentation here for information beyond the scope of this article. 

Once you’ve connected to your server via SSH and created a database, run the following command to install Laravel:

composer create-project --prefer-dist laravel/laravel projectName

Composer will then download and install Laravel. 

Document Root

Once Laravel is installed, you may notice issues with the document root. The document root is the main folder that the server expects your files to be served from. In Laravel projects, the public_html folder is the document root. For those using a shared server, you may need to contact Technical Support and let them know you would like to have the public_html folder act as the document root for your site.

Alternatively, if you just want to get up and running quickly, place the following in your .htaccess file so that attempts to access your private directories and files will automatically be redirected to the public folder: 

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]

Note that if you decide to use this method the URL for your site will look like domain.com/public/

Environment Configuration

The next step is to configure the Laravel environment by editing the .env file. This is where we need to add the database credentials that were created earlier.

To perform this step, change DB_DATABASE, DB_USERNAME, and DB_PASSWORD to reflect the actual values used for your Laravel installation.

For example:

DB_DATABASE=username_databaseName

DB_USERNAME= user_name

DB_PASSWORD=pass_word

Other values that you may want to change include the APP_NAME, APP_ENV, APP_DEBUG, and the various mail settings if you will be using mail functions in your application. On production systems, change APP_DEBUG=true to false.

PHP

If you encounter PHP issues you may need to use an updated version. Check your PHP version using the following command:

php -v

The default version is located in /usr/local/bin/php. You can update in cPanel via the MultiPHP Manager or update PHP in bash:

alias php=/opt/cpanel/ea-phpversion/root/usr/bin/php

Artisan

You may run into an error like this when trying to run artisan commands:

Psy\Exception\RuntimeException
Unable to create PsySH runtime directory.
Make sure PHP is able to write to /run/user/1234 in order to continue.
at vendor/psy/psysh/src/Configuration.php:580

If this happens, create a .psysh.php file in your project directory with the following content:

<?php
return [
'runtimeDir' => './.psysh',
];

Error Migrating Database

When trying to migrate your database you may get an error stating a key is too long when creating a table. Fix this issue by modifying the app/Providers/AppServiceProvider.php file to look like this:

<?php
namespace App\Providers;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}

/**
* Bootstrap any application services
 *
* @return void
*/
public function boot()
{
Schema::defaultStringLength(191);
}

Once all of these steps are completed, Laravel has been installed successfully. Congratulations, you now know how to set up a Laravel installation!

Was this article helpful? Let us know!