How to Install Laravel on Ubuntu 18.04

0
5286
laravel2

In this tutorial, we will get to the process of how to install Laravel on UBUNTU 18.04. However, let’s have a description What is Laravel? Laravel is a free and an open source web application framework that is compatible with PHP language. Laravel is a new generation web framework, and it is basically projected for the development of new web applications that are in MVC. We got there major Laravel types.

  • Horizon.
  • Dusk.
  • Echo

So now what is MVC?Model view controller is an architecture that help us to differentiate an application into its three logical components. That are (Model, View and Controller). Every component is built to handle the specific development for that application. It is the most popular framework at the time and most of the projects are being implemented using this framework.

Before starting the tutorial, you must have some basic knowledge of Linux, like how to use shell and how to host site on VPS. Because we will use Apache2 with this Laravel framework, Therefore, at first we will install Apache server

Step 1: Installing Apache2

Apache web server is the most popular web server in the world, because it is well documented and has been in use for a long time in the web. However, it is also known as the default web server for hosting websites. To install Apache using Ubuntu package manager follow the instructions.

Command:

$ sudo apt update
$ sudo apt install Apache2

After following the commands, you can now see the default Ubuntu web page. Which will be look like something as follows.

apache-Installed

 

Step 2: Installing MySQL

After installing web server now we need to store data that will be used for future operations. However, database management system is now a basic need for any website to fetch and store data. Therefore, we will now install MySQL database management system, which will be done by following the instructions given below.

Command:

$ sudo apt install mysql-server

This will install MySQL, note that you don’t need to type sudo apt update command because when you install apache, then this package will be already updated along with installation of Apache2.

Step 3 — Installing PHP

PHP is basically the coding module of the Laravel framework, it is also a setup that will code to display the content, run scripts and connects the server to your database that it MySQL. This is needed in order to get information and process the content to your web server for further representation.To install PHP along with some packages, kindly follow the given command.

Command:

$sudo apt install php libapache2-mod-php php-mbstring php-xmlrpc php-soap php-gd php-xml php-cli php-zip

 

In most case, when you want to modify the Apache server files whenever a directory is requested. At the time when user request a directory from server, then Apache will look for that file. We will need to tell the server to use PHP file so that it will be on first priority. So to do this just type the following command:

Command:

$ sudo vim /etc/apache2/mods-enabled/dir.conf

 

Step 4 — Install Composer

After installing PHP, now it’s time to install composer. To install composer, you must have curl package to be installed, in order to run the command to execute them. To install this type following command

Command:

$ curl -sS https://getcomposer.org/installer | sudo php — –install-dir=/usr/local/bin –filename=composer

 

installing-composer

Now go to laravel directory and create new laravel project to do this enter these commands. Note: in my case osreader is project name you can change it by yours.

$ cd /var/www/html$ sudo composer create-project laravel/laravel osreader –prefer-dist

create-laravel-project

Step 5 — Configure Apache2

After installing the composer, now we need to configure Apache2 to use it with Laravel files. This file will now control that how the user will access Laravel content. To configure Apahce2 follow the instruction given accordingly.

Command:

sudo nano /etc/aache2/sites-available/Laravel.conf

After typing the command now copy and paste the following content to the file and save it.

<VirtualHost *:80>

ServerAdmin admin@osreader.com

DocumentRoot /var/www/html/osreader/public

ServerName osreader.com

<Directory /var/www/html/osreader/public>

Options +FollowSymlinks

AllowOverride All

Require all granted

</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

 

configure-apache-for-laravel

Step 6 — Use and enable Laravel Rewrite module

Now we need to use and enable the Laravel modules for further processing Just follow the instructions to do this.

Command:

sudo a2ensite Laravel.conf
sudo a2enmod rewrite

Step 7 — Restart Apache2

After performing all the settings and installation, now it’s time to restart the Apache2 so that it will run after, and can be used. Now type the following command and restart the Apache2.

Command:

sudo systemctl restart Apache2.service

After complete these steps you are ready to go with your Laravel Project.

laravel-homePageConclusion:

After performing all the steps accordingly, we are now able to install Laravel framework to Ubuntu as well as installing and configuration of Apache2. You just need to perform steps accordingly to avoid any mistakes. However, if you still face any problem regarding this, you can contact us anytime.

LEAVE A REPLY

Please enter your comment!
Please enter your name here