How to install Laravel Framework in Ubuntu

To install Laravel Framework in Ubuntu

Laravel is a PHP framework designed for easy development of PHP applications. It supports multi-platform and allows the users to develop the MVC web applications. Installation of Laravel Framework in Ubuntu is discussed in this manual.


Installation of Laravel Framework

First setup a LAMP server by using "apt-get" command.

root@linuxhelp:~# apt-get install lamp-server -y
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'libhttp-message-perl' for task 'lamp-server'
Note, selecting 'libencode-locale-perl' for task 'lamp-server'
Note, selecting 'php7.0-cli' for task 'lamp-server'
Note, selecting 'mysql-client-5.7' for task 'lamp-server'
Note, selecting 'libapache2-mod-php' for task 'lamp-server'
Note, selecting 'rename' for task 'lamp-server'
Note, selecting 'mysql-server-5.7' for task 'lamp-server'
Note, selecting 'php-common' for task 'lamp-server'

Creating config file /etc/php/7.0/mods-available/pdo_mysql.ini with new version
Setting up php-mysql (1:7.0+35ubuntu6) ...
Processing triggers for libc-bin (2.23-0ubuntu3) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (229-4ubuntu4) ...
Processing triggers for ufw (0.35-0ubuntu2) ...
Processing triggers for libapache2-mod-php7.0 (7.0.4-7ubuntu2) ...

Use the following command to install the PHP extensions.

root@linuxhelp:~# apt-get install curl php-curl php-mcrypt php-mbstring php-gettext -y
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libapache2-mod-php7.0 libcurl3-gnutls libmcrypt4 php-pear php-xml php7.0-cli php7.0-common php7.0-curl php7.0-json php7.0-mbstring php7.0-mcrypt php7.0-mysql php7.0-opcache
  php7.0-readline php7.0-xml
Suggested packages:
  libmcrypt-dev mcrypt
The following NEW packages will be installed:
  libmcrypt4 php-curl php-gettext php-mbstring php-mcrypt php-pear php-xml php7.0-curl php7.0-mbstring
Creating config file /etc/php/7.0/mods-available/mcrypt.ini with new version
Setting up php-mcrypt (1:7.0+35ubuntu6) ...
Processing triggers for libc-bin (2.23-0ubuntu3) ...
Processing triggers for libapache2-mod-php7.0 (7.0.8-0ubuntu0.16.04.2) ...

Now its time to enable the php and apache module by using following command.

root@linuxhelp:~# phpenmod mcrypt
root@linuxhelp:~# phpenmod mbstring
root@linuxhelp:~# a2enmod rewrite
Enabling module rewrite.
To activate the new configuration, you need to run:
  service apache2 restart

To accomplish the installation of LAMP server, restart and enable the apache service.

root@linuxhelp:~# systemctl restart apache2
root@linuxhelp:~# systemctl enable apache2
apache2.service is not a native service, redirecting to systemd-sysv-install
Executing /lib/systemd/systemd-sysv-install enable apache2

Once the apache service is enabled, start and enable the mysql service.

root@linuxhelp:~# systemctl start mysql
root@linuxhelp:~# systemctl enable mysql
Synchronizing state of mysql.service with SysV init with /lib/systemd/systemd-sysv-install...
Executing /lib/systemd/systemd-sysv-install enable mysql

Below link will help you to download the composer script, either download through "curl" command.

root@linuxhelp:~# curl -sS | php
All settings correct for using Composer
Downloading 1.2.0...

Composer successfully installed to: /home/user1/composer.phar
Use it: php composer.phar

Rename the “composer.phar” script into “composer” as shown below.

root@linuxhelp:~# mv composer.phar /usr/local/bin/composer  

Now go to apache document root (/var/www/html) and remove the “index.html” file.

root@linuxhelp:~# cd /var/www/html
root@linuxhelp:/var/www/html# ls
root@linuxhelp:/var/www/html# rm -rf index.html

This action will help you to avoid the conflicts between laravel as well as apache’s default web page.


Run the following command to install the laravel framework.

root@linuxhelp:/var/www/html# composer create-project laravel/laravel work --prefer-dist
Do not run Composer as root/super user! See for details
Installing laravel/laravel (v5.3.0)
  - Installing laravel/laravel (v5.3.0)
    Downloading: 100%         

Created project in work
> php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing vlucas/phpdotenv (v2.4.0)
    Downloading: 100%         

  - Installing symfony/polyfill-mbstring (v1.2.0)
    Downloading: 100%
Generating autoload files
> IlluminateFoundationComposerScripts::postUpdate
> php artisan optimize
Generating optimized class loader
> php artisan key:generate
Application key [base64:9y0TM6X3chUL+74YrUiSCJLOrt8V3SZV2BwwhKxw6jg=] set successfully.

Once the installation is completed, rename the “work” directory into “laravel”.

root@linuxhelp:/var/www/html# ls
root@linuxhelp:/var/www/html# mv work laravel

In the laravel directory, set the write permission for the “storage” directory.

root@linuxhelp:/var/www/html# cd laravel/
root@linuxhelp:/var/www/html/laravel# ls
app      bootstrap      composer.lock  database     package.json  public     resources  server.php  tests
artisan  composer.json  config         gulpfile.js  phpunit.xml  routes     storage     vendor
root@linuxhelp:/var/www/html/laravel# chmod -R o+w storage

Next create the apache virutalhost to access from the browser.

root@linuxhelp:~# vim /etc/apache2/sites-available/


Now add the below lines into to the virutalhost configuration file.


<VirtualHost *:80>
    DocumentRoot /var/www/html/laravel/public
    <Directory /var/www/html/laravel/public>
    AllowOverride All
    Require all granted


Enable the newly created domain and restart the apache service.

root@linuxhelp:~# a2ensite
Enabling site
To activate the new configuration, you need to run:
  service apache2 reload
root@linuxhelp:~# systemctl restart apache2

Navigate to http://<IP_address>/laravel/public. Finally, default web page of Laravel will appear.



Thank you! for using Linux Help.

You find this tutorial helpful? Share with your friends to keep it alive.
For more help topics browse our website
Be the first to comment, we value your suggestions. For further queries please comment below.

Tags: Laravel
user image Author :  Jackson
user image
gundul 27-11-2017 at 12:12
This is why Yes, when calling the localhost/laravel/public appearance of this kind of (the contents of the index.html) */ define('LARAVEL_START', microtime(true)); /* |-------------------------------------------------------------------------- | Register The Auto Loader |-------------------------------------------------------------------------- | | Composer provides a convenient, automatically generated class loader for | our application. We just need to utilize it! We'll simply require it | into the script here so that we don't have to worry about manual | loading any of our classes later on. It feels great to relax. | */ require __DIR__.'/../vendor/autoload.php'; /* |-------------------------------------------------------------------------- | Turn On The Lights |-------------------------------------------------------------------------- | | We need to illuminate PHP development, so let us turn on the lights. | This bootstraps the framework and gets it ready for use, then it | will load up this application so that we can run it and send | the responses back to the browser and delight our users. | */ $app = require_once __DIR__.'/../bootstrap/app.php'; /* |-------------------------------------------------------------------------- | Run The Application |-------------------------------------------------------------------------- | | Once we have the application, we can handle the incoming request | through the kernel, and send the associated response back to | the client's browser allowing them to enjoy the creative | and wonderful application we have prepared for them. | */ $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); $response = $kernel->handle( $request = Illuminate\Http\Request::capture() ); $response->send(); $kernel->terminate($request, $response);