Install Laravel Framework on Ubuntu

Posted on July 11th, 2020

In this tutorial, we can check how to Install Laravel Framework on Ubuntu.

Laravel is a free, open-source Model View Controller (MVC) PHP web framework. This framework makes the development of full-featured web applications easy. The Laravel framework is robust and easy to understand. By the use of the Laravel framework, we can reuse the components of an existing framework to create a new application. The web application developed with the help of the Laravel framework is more realistic and structured, and this framework can boost up the speed of web development.

The features offered by the Laravel framework makes it more robust, powerful, and secure. Some of the features offered by the Laravel framework are Job Middleware, Semantic versioning, Eloquent Subquery Enhancements, Lazy collection, and more. The Laravel features that boost web application designing are:

  1. Built-in libraries and modules.
  2. The features and helpers offered by Laravel make testing an easy process.
  3. The routing feature of Laravel frameworks helps to improve the performance of your web application.
  4. The configuration management feature of Laravel helps to manage the configuration efficiently.
  5. The mail class feature of Laravel helps in sending an email with rich content and attachments from the web application.

In this knowledgebase, you learn how we can install the Laravel framework on Ubuntu 18.04 LTS server.

System Prerequisites

Before installing Laravel framework on your Ubuntu server, the system should satisfy the following requirements:

  1. Apache Webserver
  2. PHP 7.1.3 and above with PDO, Mbstring, XML, OpenSSL, Tokenizer, Ctype, and JSON PHP Extensions.
  3. Composer

 

Install PHP 7.2 and Apache Web Server

Log in to the server as an ssh user with sudo privileges.

Add the third-party PHP repository on your Ubuntu server by executing the following command.

$ sudo add-apt-repository ppa:ondrej/php

Run the following command to update your system’s apt repository.

$ sudo apt update

Run the following command to install Apache and PHP 7.2.

$ sudo apt-get install apache2 php7.2 libapache2-mod-php7.2  php7.2-gd php7.2-xml php7.2-mbstring php7.2-opcache

 

Install Composer

Composer act as an application-level package manager for PHP language.  This package manager helps to manage all the dependencies of PHP software and libraries in a standard format.

Before installing the composer, you need to install some useful tools, such as git, curl, and unzip packages using the following command.

$ sudo apt install git curl unzip

Install the composer by executing the following commands. The composer installs all the packages that are required to run the Laravel framework on the server.

$ sudo cd /opt
$ sudo curl -sS https://getcomposer.org/installer | php

Move the installed composer to the ‘/usr/local/bin’ directory to run that globally.

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

 

Install Laravel Framework on Ubuntu Server

To install Laravel framework on your Ubuntu server, follow the below steps:

Log in to the server as an ssh user with sudo privileges.

Switch to the public_html directory of your Ubuntu server by using the following command.

$ sudo cd /var/www/html

Next, install Laravel and create a directory named ‘new-project’ with this installation.

$ sudo composer create-project laravel/laravel new-project --prefer-dist

In the above command, the composer uses Git to download and install all modules and packages required for the functioning of the Laravel framework. The sample output for the above command should be similar to the one shown in the following screenshot.

Install Laravel

 

Configure Apache Web Server for Laravel

First, we need to change the group permission of the project directory created to the ‘www-data’ group and then edit permission of the storage directory. For the same, run the following commands.

$ sudo chgrp -R www-data /var/www/html/new-project
$ sudo chmod -R 755 /var/www/html/new-project/storage

Next, Switch to the ‘/etc/apache2/sites-available’ directory and create and open the Laravel configuration file by using any of the text editors.

$ sudo cd /etc/apache2/sites-available
$ sudo vim laravel.conf

Then, copy and paste the following content in the configuration file after that save and close the file.

ServerName localhost
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/new-project/public
AllowOverride All
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

Disable the default configuration file and then enable the Laravel configuration file by using the following commands.

$ sudo a2dissite 000-default.conf
$ sudo a2ensite laravel.conf

Then, enable the rewrite mode.

$ sudo a2enmod rewrite

After making all the changes, restart the Apache service by executing the following command.

$ sudo systemctl restart apache2

Check the status of the Apache service after the restart by executing the following command.

$ sudo systemctl status apache2

 

Test Laravel Installation

Now the installation of the Laravel framework on your Ubuntu server is successful. To confirm the same, browse the following URL from any of the web browsers. This URL should open the Laravel welcome page. In the following URLs, replace the <server_IP_address> and <domain_name> flag with your servers IP and domain name, respectively.

http://<server_IP_address>
or
http://<domain_name>

 

Conclusion

Laravel is a free, open-source MVC PHP web framework intended for the development of full-featured web applications. This framework is robust and easy to understand. By using Laravel, we can reuse the existing components of different frameworks to create a web application. We hope that this knowledge base was helpful to you. Please comment below for any questions or queries. If you are an InterServer customer, please reach out to our support team for further help.

Leave a Reply