Table of Contents
Why Laravel ?
Before Install Larvel on Ubuntu, we must understand why Laravel? Laravel developed and maintained by Taylor Otwell. It is an open-source PHP application framework based on MVC architecture. If you are planning to use PHP professionally, then you must try one of the most suitable PHP frameworks. It will help you in fast development and make it easy to maintain the Laravel project. So in earlier the days’ developers write their framework. And such a framework always works better if you are a lone developer. If the project is serious and the team working on it then, it would not be easy to follow standards and maintenance processes. To deal with such situations, PHP framework interop Group published PHP Standard Recommendation for application structure, code and file organizing processes. So let install Laravel on Ubuntu.
There are many PHP frameworks like Yii, CodeIgniter, Zend, Phalcon, Symfony, CakePHP etc. However, Laravel framework is the most popular, easy to learn and to develop web applications without any issue. It helps the developer to simplify the development process with clean and reusable code sets.
What we need for Laravel?
In this article, we are going to learn how to configure the Laravel Project on Ubuntu. So what we need to set up, here are some imp points.
- Apache Server.
- The latest PHP version.
- PHP Extensions.
- Composer
Let start the process by installing the apache server. To install it, we are going to use Ubuntu’s package manager apt. Before proceeding to install, let update the Local Package Index first.
$ sudo apt-get update $ sudo apt-get install apache2 #install apache $ sudo systemctl start apache2 $ sudo systemctl enable apache2 $ sudo systemctl status apache2 #check apache is working or not. Output ( apache status ) apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2020-05-30 10:53:41 IST; 1 weeks 1 days ago Docs: https://httpd.apache.org/docs/2.4/ Main PID: 1386 (apache2) Tasks: 11 (limit: 9377) Memory: 30.6M CGroup: /system.slice/apache2.service ├─ 1386 /usr/sbin/apache2 -k start ├─116040 /usr/sbin/apache2 -k start ├─116041 /usr/sbin/apache2 -k start ├─116043 /usr/sbin/apache2 -k start ├─116044 /usr/sbin/apache2 -k start
Now Laravel server needs to install the latest PHP stable version with some extensions. BCMath, JSON, Mbstring, OpenSSL, PDO, Tokenizer and XML extension required. However, most of the extensions already installed and enabled by default. So we will run the following command to make sure all extension installed.
$ sudo apt install openssl php-common php-curl php-json php-mbstring php-mysql php-xml php-zip
At the time of writing this post, 7.4 is a stable PHP stable version so we can install version-specific extensions.
$sudo apt install php7.4 libapache2-mod-php7.4 php7.4-bcmath php7.4-json php7.4-mbstring php7.4-xml php7.4-zip php7.4-common $php -v #Check PHP version. #sudo systemctl restart apache2 #Restart your apache after update.
Install Composer
We will install a composer now, Laravel use composer to manage project dependencies. Composer is the dependency manager for PHP.
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/bin --filename=composer
User followng command to verify the installation.
$composer -V
Install Laravel on Ubuntu
At the time of writing this post, Laravel 8 is a stable version. Now time to set up a Laravel project. We will set up it in the root directory of Apache webserver folder i.e. “var/www/html/” so navigate to the folder.
$ cd /var/www/html
Use following composer command to set up project folder with latest Laravel version.
$ sudo composer create-project laravel/laravel=”8.0” project_name
Please replace project_name with your project name. We will test-run our project by using a Laravel webserver. For that navigate to project_name folder and use the following command
$ cd project_name $ php artisan serve Output Starting Laravel development server: http://127.0.0.1:8000 [Sun Dec 13 15:15:08 2020] PHP 7.4.9 Development Server (http://127.0.0.1:8000) started
URL will open following default Laravel Home Page.

Laravel configuration on Apache / Setup Virtual Host
After folder setup and Laravel, now we are going configure apache for the project. Let give access to non-root user to modify, delete and create a file in the working folder.
$ sudo chown -R $USER:$USER /var/www/html/project_name/
Now give read and execute permission to permission to parent folder .
$ sudo chmod -R 755 /var/www/html/project_name $ sduo chmod -R 775 /var/www/html/project_name/storage
After this, let configure to run our Laravel application. Therefore make a copy of default apache config and make changes according to the requirement
$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/project_name.conf $ sudo nano /etc/apache2/sites-available/project_name.config
Edit and replace /var/www/html with /var/www/html/project_name/public and then save file. After this we enabled it and check configurations error for any syntax error.
<VirtualHost *:80>
ServerAdmin [email protected]
project_name
.comServerName project_name.com
ServerAlias www.
project_name
.comDocumentRoot /var/www/html/
project_name
/public_htmlErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
$ sudo a2ensite project_name.conf - ( Enable Config ) $ sudo apache2ctl configtest - ( Check Error ) Output: Syntax OK
Now map local IP address with our local hostname to access our project in local system.. Hosts file used by operating system to map reference between local IP address and custome hostname. Edit hosts file to make changes.
$ sudo nano /etc/hosts
Enter following records in the hosts file to access project on local machine.
127.0.0.1 project_name.com
Now restart apache server to apply changes .
$ sudo systemctl restart apache2
In conclusion, we successfully installed and configured Laravel 8.0 ( LTS ) with PHP 7.4. Laravel has a huge developer community and massive ecosystem of both official and third-party package that we can use in our projects. You can find the community on laravel.io, Laracasts Discuss, LaraChat, Discord, Reddit and laracon.net.
Visit our another Laravel Post