Install or setup Laravel 5 Framework in Ubuntu 16.04/14.04 for Apache server with the help of Composer:

Laravel is a free, open-source and PHP web development framework which employs the Model-View-Controller design pattern and easy development of applications.

So if you beginner in PHP development and thinking to start any PHP framework then I would suggest only Laravel. Laravel is best PHP framework to start with for experience developer also. Laravel code structure flow also documented very easy.Topic which are covered here:

Now let see how to configure or install Laravel 5 in Ubuntu apache server .

Before installation of Laravel:
Before proceeding with the Laravel installation, Important thing is to make sure your sources, libraries , packages and applications are all updated. Please try below command for updating our existing resources.

How to update packages in ubuntu or linux

1

sudo apt-get update

For installation of Laravel 5 in Ubuntu apache server , there are simple steps you need to follow which We have mentioned below.

Steps to install and configure Laravel 5 in Ubuntu apache server:

Step 1:-LAMP Installation on Ubuntu OS

To start with Laravel framework, we first need to install or set up LAMP server in Ubuntu. If you have already installed LAMP stack server in your system then skip this step else use below commands to set up lamp on Ubuntu system.

==> Installation of PHP5 in ubuntu

For Laravel, Need to install PHP 5 along with its several extra packages by below commands:

How to install php in ubuntu apache server

1

2

3

4

5

sudo apt-get install python-software-properties

sudo add-apt-respository ppa:ondrej/php5

sudo apt-get update

sudo apt-get install php5 php5-mcrypt php5-gd

sudo php5enmod mcrypt

==>Installation of Apache server

Here we need to install Apache server for creating development environment for developers.Below command will help to install apache 2. And in command “libapache2-mod-php5” package help to link between apache and PHP.

Step 2:- Install Composer in ubuntu

To start with Laravel installation, Need to install Composer first. It is a tool for dependency management in PHP. To install Laravel and all its dependencies, Composer is required. It will download and install all packages, which are required to run Laravel easily.

To install Composer, Use the below commands to download & configure composer in your ubuntu system.

How to install composer in ubuntu for laravel

1

curl-sS https://getcomposer.org/installer | php

Above command will use to download composer.phar package to system directory.
As we need to run globally Composer so we required to move composer.phar file to /usr/local/bin directory by below command .So that we can run composer from any directory.

How to move composer file to bin file in ubuntu

1

sudo mv composer.phar/usr/local/bin/composer

Step 3:-Install Laravel in Ubuntu OS

To download latest version of Laravel, Move to the public html directory on your system. Since we are on Ubuntu with Apache server, we would install Laravel in /var/www/html directory.

The above second command will create a YourProjectName directory with laravel installation done with it And Composer uses git to download and install all the required packages and modules or laravel.

Here you can rename your file name from YourProjectName to LaravelProject.Now Laravel installation is done.Please go to next step to configure apache setting according to laravel dependencies.

Step 4:-Apache setting configuration changes

Now need to assign www-data group to yourProjectName file and give to proper permission to yourProjectName directory.

How to assign permission and change group to www-data

1

2

sudo chgrp-Rwww-data/var/www/html/yourProjectName

sudo chmod-R775/var/www/html/yourProjectName/storage

Step 5 :- Create Apache VirtualHost

Now add a Virtual Host changes in your Apache configuration file to access Laravel framework from web browser.Now go to the /etc/apache2/sites-available directory to creat a configuration file “laravel.conf” by below commands.

How to create virtual host in ubuntu

1

2

3

cd/etc/apache2/sites-available

cat>laravel.conf

Now edit this config command by VIM command by below command:

How to edit laravel config file

1

sudo vim laravel.conf

Now add the paste below content to new config file and close it after saving this changes.

How to create virtual host in Ubuntu

1

2

3

4

5

6

7

8

9

10

11

12

13

<VirtualHost *:80>

ServerName laravel.com

ServerAdminwebmaster@localhost

DocumentRoot/var/www/html/YourProjectName/public

<Directory/var/www/html/YourProjectName>

AllowOverrideAll

</Directory>

ErrorLog${APACHE_LOG_DIR}/error.log

CustomLog${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Now you have to enable this newly created .conf file by a2ensite . mod_rewrite also required to enable for redirect one URL to another URL properly.

how to enable mod rewrite and a2ensite in config file

1

2

sudo a2ensite laravel.conf

sudo a2enmod rewrite

Once you enable this config file by a2ensite, System would ask to restart to update your changes by below commands

How to restart apache server in ubuntu

1

sudo service apache2 restart

Step 6:-Host file configuration

At this point you have done with installation of Laravel 5 PHP framework on your system.
Now need to make a new entry to hosts file for mapping IP (127.0.0.1)with virtual server name to access in web browser.

laravel.com (virtual domain) is now configured with apache.

Step 7:- Final conclusion of all steps

Your Laravel framework installation is now successfully completed.
So now visit http://laravel.com to access your laravel project. If successful installed then you should see the below screen.Thanks