Complete guide to install laravel 5.8 on linux

What’s laravel?

Laravel is a free, open-source PHPweb framework, created by Taylor Otwell and intended for the development of web applications following the model–view–controller (MVC) architectural pattern and based on Symfony. Some of the features of Laravel are a modular packaging system with a dedicated dependency manager, different ways for accessing relational databases, utilities that aid in application deployment and maintenance, and its orientation toward syntactic sugar.
(Wikipedia)

Step 1 – Server Requirements for Installing Laravel 5.8

When you are about to use laravel on any system you will need some setup before able to use it. Here’s the basic requirement to follow the guide to install laravel 5.8 on linux.

  • PHP >= 7.1.3
  • BCMath PHP Extension
  • Ctype PHP Extension
  • JSON PHP Extension
  • Mbstring PHP Extension
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension

Let’s start to put hand in it

When you will use linux to install any software better get the last update.

$ sudo apt-get update
$ sudo apt-get upgrade

Let’s add some basic package to avoid trouble in installation

$ sudo apt-get install -y git curl wget zip unzip

Install PHP 7

$ sudo apt install ca-certificates apt-transport-https 
$ wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -
$ sudo echo "deb https://packages.sury.org/php/ jessie main" | tee /etc/apt/sources.list.d/php.list

Install Php 7.2 Note if you are using ubuntu you may skip the step above

$ sudo apt update
$ sudo apt install php7.2

Now we gonna install required php module

$ sudo apt-get install -y php7.2 php7.2-fpm libapache2-mod-php7.0 php7.2-cli php7.2-curl php7.2-mysql php7.2-sqlite3 php7.2-gd php7.2-xml php7.2-mcrypt php7.2-mbstring php7.2-iconv

As you see above this large command will install php, php-cli and the most important php libraries.

Step 2 – Install PHP Composer

Laravel utilizes Composer to manage its dependencies. So, before using Laravel, make sure you have Composer installed on your machine.

$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer
$ sudo chmod +x /usr/local/bin/composer

Now you are ready to install laravel

Step 3 – Install Laravel on linux

Intall laravel with composer create project to get the lastest available version of the framework

Navigate to your web server (apache) Directory

$ cd /var/www/

Now execute the command below to create a project named blog with the last version of laravel available

$ composer create-project --prefer-dist laravel/laravel blog

We add necessary permission to get it functional.

$ chmod -R 755 /var/www/blog
$ chmod -R 777 /var/www/blog/storage

Step 4 – Creating MySQL Database

As you gonna probably need a database you can install a mysql database or use and SQLite database. Now let’s install mysql database.

$ sudo apt-get install mysql-server

Click Enter to validate the first popup, then create a password for your Mysql root user. it’s highly recommended to secure Mysql server by running :

$ mysql_secure_installation

There’s a lot client to manage database like PhpMyadmin, Adminer, Mysql Workbench but for this tutorial we will use the command line to create our database.

mysql> CREATE DATABASE laravel;
mysql> GRANT ALL ON laravel.* to 'laravel'@'localhost' IDENTIFIED BY 'secret_password';
mysql> FLUSH PRIVILEGES;
mysql> quit

Edit the configuration file .env to add the database credentials.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=secret_password

Now you should get into a terminal then go to your directory and use laravel built in artisan to start your application.

php artisan serve

This is the end of our step by step guide to install laravel 5.8 on linux

You may also like...

6 Responses

  1. me says:

    Testing comment

  2. Josef says:

    hey, nice step by step tutorial; I use laragon on windows but I’d like to work on linux, how to install apache on linux ubuntu?

  1. July 2, 2019

    […] Laravel installation (in this article we use version […]

  2. July 9, 2019

    […] Complete guide to installa laravel 5.8 on linux […]

  3. July 13, 2019

    […] In case you are a Linux user you can follow the article on How to install laravel on Linux . Complete guide to install laravel 5.8 on linux. […]

Leave a Reply

Your email address will not be published. Required fields are marked *