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.

https://getcomposer.org/installer

root@linuxhelp:~# curl -sS https://getcomposer.org/installer | 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
index.html
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 https://getcomposer.org/root 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
work
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   readme.md  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/linuxhelp.laravel.com.conf

 

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

Entry:

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

</VirtualHost>


Enable the newly created domain linuxhelp.laravel.com and restart the apache service.

root@linuxhelp:~# a2ensite linuxhelp.laravel.com
Enabling site linuxhelp.laravel.com.
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.

1

 


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 www.linuxhelp.com
Be the first to comment, we value your suggestions. For further queries please comment below.

Tags: Laravel
user image Author :  Jackson