How to Install Laravel Framework on Ubuntu 18.04 LTS With Examples

In this guide, we look at how to install Laravel framework on Ubuntu 18.04 server. Laravel is a free and open source PHP web framework. It was created in 2011 by Taylor Otwell and has since been used for development of robust mobile applications using the MVC model.

Let’s dive in and see how we can install Laravel framework on Ubuntu 18.04 LTS Server.

Before we install Laravel framework, let’s first install the prerequisite packages that will be required.

System prerequisites

Your system will need to satisfy the requirements below before proceeding.

  • Apache Web server
  • PHP >= 7.1.3 with OpenSSL, PDO, Mbstring, Tokenizer, XML, Ctype and JSON PHP Extensions.
  • Composer – an application-level package manager for the PHP

1. Install Apache Web server and PHP 7.2

We are going to add a third party PHP repository. Even though Ubuntu’s own repository has its own PHP, a third party repository is very much recommended because it gets more frequently updated.

To add the repository execute the command:

Sample Output

ondrej-ppa

Next, update your system’s repositories.

Sample Output

ondrej-ppa

Next, install Apache and PHP 7.2 alongside other prerequisites.

Sample Output

install-prerequisites

2. Install Composer

Before we embark on the installation, we will first install a few useful tools. These are git version control, curl and unzip packages.

Sample Output

install-curl-zip-git

Next, we need to install composer. The composer is another useful tool that handles dependency management in PHP and allows you to package the required libraries associated with a package as one. Composer will download and install all the packages required to run the Laravel framework.

To install Composer, execute the following commands

Sample Output

install-composer

The curl command downloads Composer to the /opt directory. Since we need composer running globally, we must move it to the /usr/local/bin directory under 'composer' name.

This will allow us to run composer from anywhere.

3. Install Laravel Framework

Now, let’s navigate to the public_html directory of our Ubuntu System. To install Laravel, we will navigate to the /var/www/html directory.

Next, we will create a directory “your-project” with Laravel installation. The composer will proceed to use Git to download and install all packages and modules that Laravel requires for functioning.

Sample Output

installing-composer

4. Configure Apache Web Server for Laravel

The next step is to configure our Apache Web server. We need to assign the necessary permissions to the project directory which will allow access to it from the www-data group and give it write permissions to the storage directory. To get this done, run the following commands.

Now let’s navigate to /etc/apache2/sites-available directory and run the command below to create a configuration file for our Laravel install.

Add the following content:

Save the file and Exit.

Finally, we are going to enable the newly created laravel.conf file. But before that, let’s disable the default config file.

Sample Output

Next, enable the Laravel config file.

Sample Output

Then enable rewrite mode:

Sample Output

install-composer

Lastly, restart the Apache service.

To verify that Apache is running execute the command:

Sample Output

check-apache2-status

5. Test Laravel Website

At this point, You have successfully installed Laravel on your Ubuntu 18.04 LTS System. To confirm that the installation went as expected visit your server’s IP address.

In my case, the server’s IP is https://38.76.11.149

Laravel-GUI

We hope that this guide has been helpful. Feel free to leave your feedback at the comment section.

By admin

Leave a Reply