Let’s bring Laravel to Ubuntu

Laravel is very popular open source PHP framework aimed at fast and easy development of web applications. To know more read — why Laravel is best PHP framework?
Official guide to install Laravel is here — https://laravel.com/docs/master/installation — which is little confusing and incomplete. You can try to install using official guide in first attempt. If stuck after two or three attempt, then you are at right place.
I’m trying to simplify the steps for installation and configuration of Laravel on Ubuntu.
During writing this article Laravel 5.3 has released. All steps followed in Ubuntu 15, however It may have worked on 14 or Later version.
Pre-Requisities
Before Start installation of Laravel configure your system with following steps. If all set you can skip to Installation of Laravel.
- Update System
- Install/Configure LAMP Stack
- Install Composser
- Activate mod_rewrite
1. Update Sytem
Before proceeding with the installation on Ubuntu, it’s always a good idea to make sure your sources and existing software are all updated. Use this command to install the updates on Ubuntu.
sudo apt-get update
sudo apt-get upgrade
2. Install/Configure LAMP Stack
LAMP stack is a group of open source software platform widely used to get web servers up and running.
LAMP Stands for Linux, Apache, MySQL and PHP (You are free to use P for Perl and Python? But in general PHP assumed). Linux is as Operating System, Apache is most used web server software, MySQL is Relational Database Management system, and finally PHP is as Object oriented programming(Web Scripting) language for web.
2.1 Required Version of LAMP Stack
Linux : Ubuntu would be good but Mint, Fedora and other distro can be used too. This article is based on Ubuntu 15.10 (14 or 16 will be OK?).
Apache 5.3
MySQL 5
PHP >= 5.6
If Lamp Stack installed, check version of installed software using following command on terminal
apache2 -v
mysql -V
php -v
2.2 Install LAMP Stack using commands on terminal
Apache (Some Version of Linux may have Apache Installed)
sudo apt-get install apache2
MySQL
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql
During the installation, MySQL will ask you to set a root password.
All installation process is self-explaining, you can figure out what should on or off. (You are trying to configure web server on Ubuntu. Do you really need more explanation?)
PHP with necessary extenstion
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt unzip curl openssl
3. Install Composer (Globally)
Composer is an application-level package manager for the PHP programming language that provides a standard format for managing dependencies of PHP software and required libraries. It was developed by Nils Adermann and Jordi Boggiano in 2011.
curl -sS https://getcomposer.org/installer | php
Curl is a tool to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP). The command is designed to work without user interaction.
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer
Move compser.phar file to bin to access systemwide.
4. Activate mod_rewrite module
Mod_rewrite is something like URL manipulation script in Apache. We have to activate using following command
sudo a2enmod rewrite
sudo service apache2 restart
Install Laravel (via composer)
To install Laravel, move to the public html directory on your system. Since we are on Ubuntu and using Apache, your default webserver directory will be /var/www/html. Use cd command on terminal to move to this location
cd /var/www/html
Now you have to type following command
sudo composer create-project laravel/laravel project-name — prefer-dist

Installation of Laravel will start. It will take some time to complete download all necessary packages with laravel.
Final Configuration
After sometime Laravel project created with given name (in my case project name was hello-laravel).
- Grant Permission
Give proper permissions to the project directory. For this you need to enable access to it from the www-data group and to give it writing permissions to the storage directory.
sudo chgrp -R www-data /var/www/html/project
sudo chmod -R 775 /var/www/html/project/storage

2. Set Apache configuration file
At /etc/apache2/sites-available directory and use the following command to create a configuration file for your laravel install.
cd /etc/apache2/sites-available
sudo nano laravel.conf
Enable laravel.conf configration and restart apache server
sudo a2dissite 000-default.conf
sudo a2ensite laravel.conf
sudo service apache2 restart

Ready to go

So easy!! Let’s start building application using Laravel 5 PHP Framework. Thanks. Keep tune for next tuts.