In this tutorial, we will show you how to install Laravel on Ubuntu 20.04 LTS. For those of you who didn’t know, For those of you who didn’t know, Laravel is a free, open-source PHP web application framework, created by Taylor Otwell and intended for the development of web applications following the model–view–controller (MVC) architectural pattern. It is a pretty new framework, but with a big potential to become one of the most popular PHP frameworks.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of Laravel on Ubuntu 20.04 Focal Fossa. You can follow the same instructions for Ubuntu 18.04, 16.04, and any other Debian-based distribution like Linux Mint.
Prerequisites
- A server running one of the following operating systems: Ubuntu 20.04, 18.04, and any other Debian-based distribution like Linux Mint or elementary OS.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install Laravel on Ubuntu 20.04 LTS Focal Fossa
Step 1. First, make sure that all your system packages are up-to-date by running the following apt
commands in the terminal.
sudo apt update sudo apt upgrade
Step 2. Install LAMP server.
A Ubuntu 20.04 LAMP server is required. If you do not have LAMP installed, you can follow our guide here.
Step 3. Installing Composer.
Composer a dependency manager tool for PHP programming language. To install Composer, type the following commands:
curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer sudo chmod +x /usr/local/bin/composer
Verify the installation of the composer run the below command:
composer -V
Step 4. Installing Laravel on Ubuntu 20.04.
The latest Laravel version is available under the Github repository. Now we download the latest version, and install it with the following command:
cd /var/www git clone https://github.com/laravel/laravel.git
Next, switch to the Laravel directory and use the composer to install all dependencies required for the Laravel framework:
cd /var/www/laravel sudo composer install
Then, set proper permissions on files:
chown -R www-data.www-data /var/www/laravel chmod -R 755 /var/www/laravel chmod -R 777 /var/www/laravel/storage
Step 5. Create Environment Settings.
Now we create the Laravel environment configuration file. You can do it by renaming the .evn.example file to .env. :
mv .env.example .env
Next, generate a base64 random number encryption key, which is used by the Illuminate encrypter service:
$ php artisan key:generate Application key set successfully.
Then, edit the .env configuration file and update the required settings. Also, make sure APP_KEY is properly set as generated:
nano .env
APP_NAME=Laravel APP_ENV=local APP_KEY=base64:HFdS7c9rhDp+AeHu7kcmeilanaq2BQ/1gfFWEpoAk= APP_DEBUG=true APP_URL=http://localhost ...
Step 6. Configure MySQL / MariaDB Database Laravel.
Create a MySQL database for your Laravel application:
CREATE DATABASE laravel; CREATE USER 'laravel'@'localhost' IDENTIFIED BY 'your-password'; GRANT ALL ON laravel.* to 'laravel'@'localhost'; FLUSH PRIVILEGES; quit
Next, edit the .env file and update database settings:
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=laravel DB_USERNAME=laravel DB_PASSWORD=your-password
Step 7. Configuring Apache web server for Laravel.
Now we edit the Apache default virtual host configuration file (ie: 000-default.conf) and update Document Root to the Laravel public directory:
nano /etc/apache2/sites-enabled/000-default.conf
Add the following lines:
<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/laravel/public <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/laravel> AllowOverride All </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
Now, we can restart the Apache webserver so that the changes take place:
sudo systemctl restart apache2
Step 8. Accessing Laravel Web Interface.
Laravel will be available on HTTP port 80 by default. Open your favorite browser and navigate to http://your-domain.com
or http://server-ip-address
and complete the required steps to finish the installation. If you are using a firewall, please open port 80 to enable access to the control panel.
Congratulations! You have successfully installed Laravel. Thanks for using this tutorial for installing Laravel in Ubuntu 20.04 LTS (Focal Fossa) systems. For additional help or useful information, we recommend you to check the official Laravel website.