Install Laravel on Ubuntu 20.04

install laravel on ubuntu 20.04
how to install laravel on ubuntu 20.04

Laravel is an open-source PHP framework that can be used to develop web applications easier and faster through built-in features. It is based on the Symfony framework and following the model–view–controller architectural pattern. Today you will learn how to install Laravel on Ubuntu 20.04

Installing Laravel on Ubuntu 20.04 is an easy task, and it shouldn’t take more than 10 minutes to install.

install laravel ubuntu

Laravel comes with a rich set of features including, Artisan, Object-relational mapping, Template Engine, MVC Architecture, Unit-Testing, and Database Migration System that will increase the speed of web development.

In this tutorial, we will explain how to install the Laravel framework with the Apache webserver on our  Ubuntu VPS. Don’t forget, if you are one of our clients, you can always submit a ticket and our technical support will take care of the Laravel installation on Ubuntu 20.04, or any other request you might have. Let’s get started.

Prerequisites

  • A Ubuntu 20.04 VPS with root access enabled or a user with Sudo privileges.
  • A valid domain name pointed with your server.
  • MySQL or MariaDB
  • Apache 2.4 and PHP 7.2+

Step 1: Log in via SSH and Update your System

First, you will need to log in to your Ubuntu 20.04 VPS via SSH as the root user:

ssh root@IP_ADDRESS -p PORT_NUMBER
Next, run the following commands to upgrade all installed packages on your VPS:

apt-get update -y
apt-get upgrade -y

Step 2: Install Apache and PHP

First, install the Apache webserver, PHP, and required PHP extensions using the following command:
apt-get install apache2 php7.4 libapache2-mod-php7.4 php7.4-curl php-pear php7.4-gd php7.4-dev php7.4-zip php7.4-mbstring php7.4-mysql php7.4-xml curl -y

Once all the packages are installed, start the Apache service and enable it to start after system reboot using the following command:

systemctl start apache2
systemctl enable apache2

Step 3: Install Composer

The Composer is a package manager for the PHP programming language that can be used for managing dependencies of PHP software and required libraries.

You can download and install the Composer with the following command:

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
chmod +x /usr/local/bin/composer

Next, verify the installed version of the Composer with the following command:

composer --version

You should get the following output:

Composer version 1.10.6 2020-05-06 10:28:10

Step 4: Install Laravel Framework

laravel ubuntu 20.04

Next, you can install Laravel applications using the composer create-project command. This command is used to bootstrap new applications based on existing frameworks and content management systems.

First, change the directory to the Apache root directory and create a new Laravel application named laravelapp using the following command:

cd /var/www/html
composer create-project laravel/laravel laravelapp --prefer-dist

Once the installation is finished, you should see the following output:


Creating a "laravel/laravel" project at "./laravelapp"
Installing laravel/laravel (v7.6.0)
- Installing laravel/laravel (v7.6.0): Loading from cache
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fideloper/proxy
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
31 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan key:generate --ansi
Application key set successfully.

Next, change the directory to the laravelapp directory and run the following command to verify that all components were successfully installed:

cd laravelapp
php artisan

You should see the following output:

Laravel Framework 7.11.0
Usage:
command [options] [arguments]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--env[=ENV] The environment the command should run under
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Next, change the ownership of the laravelapp directory and give proper permissions to the storage directory with the following command:

chown -R www-data:www-data /var/www/html/laravelapp
chmod -R 775 /var/www/html/laravelapp/storage

Step 5: Configure Apache to Serve Laravel App

Next, create a new Apache virtual host configuration file to serve the Laravel app.

nano /etc/apache2/sites-available/laravel.conf

Add the following lines:


<VirtualHost *:80>
ServerName laravel.example.com
ServerAdmin admin@example.com
DocumentRoot /var/www/html/laravelapp/public
<Directory /var/www/html/laravelapp>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Save and close the file when you are finished. Then, enable the Apache virtual host and rewrite module with the following command:

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS

a2ensite laravel.conf
a2enmod rewrite

Finally, restart the Apache service to implement the changes:

systemctl restart apache2

Step 6: Access Laravel App

At this point, your Laravel application is installed and configured. Now, open your web browser and type the URL http://laravel.example.com. You should see the Laravel default page on the following screen:

Congratulations! you have successfully installed the Laravel framework on Ubuntu 20.04 VPS.


installing laravel on ubuntu 20.04

Of course, you don’t have to install Laravel on Ubuntu 20.04 yourself, if you use one of our Laravel VPS Hosting services, in which case you can simply ask our expert Linux admins to install Laravel on Ubuntu 20.04 for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post, on how to install Laravel on Ubuntu 20.04, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

3 thoughts on “Install Laravel on Ubuntu 20.04”

  1. Great documents. It works. Very helpful thanks. For those like me who has installed a server on the same machine (no laravel apps) if you install laravel and follow these steps it will overwrite your settings and you wouldn’t be able to run apps so you need to know what the command for a2ensite laravel.conf does and be able to switch back to your prev app’s othersite.conf file before following these instructions.

    Reply

Leave a Comment