Professional Documents
Culture Documents
How To Install Laravel PHP Framework With Nginx On Ubuntu 20.04
How To Install Laravel PHP Framework With Nginx On Ubuntu 20.04
How To Install Laravel PHP Framework With Nginx On Ubuntu 20.04
04
Menu
Menu
Aaron Kili Last Updated: August 24, 2020 Laravel, Ubuntu Leave a comment
Laravel is the most popular, free, and open-source PHP framework in the world, known
for its expressive and elegant syntax. Laravel is accessible, powerful, and offers some
of the best web development tools required for large, robust, and modern applications.
In this article, you will learn how to install the Laravel PHP Framework on Ubuntu
20.04 server running on the Nginx web server.
Prerequisites
https://www.tecmint.com/install-laravel-with-nginx-on-ubuntu/ 1/18
26/10/2020 How To Install Laravel PHP Framework with Nginx on Ubuntu 20.04
https://www.tecmint.com/install-laravel-with-nginx-on-ubuntu/ 2/18
26/10/2020 How To Install Laravel PHP Framework with Nginx on Ubuntu 20.04
Next, you need to create a MySQL database for your Laravel application. So, log into
your mysql shell and create the database as follows.
$ sudo mysql
MariaDB [(none)]> CREATE DATABASE laraveldb;
MariaDB [(none)]> GRANT ALL ON laraveldb.* to 'webmaster'@'loca
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> quit
https://www.tecmint.com/install-laravel-with-nginx-on-ubuntu/ 3/18
26/10/2020 How To Install Laravel PHP Framework with Nginx on Ubuntu 20.04
Laravel utilizes the composer (a dependency manager for PHP) to manage its
dependencies. Therefore, before using Laravel, ensure you have Composer installed on
your system as shown.
Linux Foundation LFCS and LFCE Cer ti cation Preparation Guide - Get This Book
After installing the composer, use it to install the Laravel les. Move into your
/var/www/html directory where web les are stored, then install Laravel using the
composer as shown. Remember to replace example.com with the name of the
directory where the Laravel les will be stored.
$ cd /var/www/html
$ composer create-project --prefer-dist laravel/laravel example
https://www.tecmint.com/install-laravel-with-nginx-on-ubuntu/ 4/18
26/10/2020 How To Install Laravel PHP Framework with Nginx on Ubuntu 20.04
Note that while con guring NGINX to serve Laravel as described below, the
absolute path (or root path) for your site in NGINX con guration le will be
/var/www/html/example.com/publics .
$ ls -la /var/www/html/example.com/
https://www.tecmint.com/install-laravel-with-nginx-on-ubuntu/ 5/18
26/10/2020 How To Install Laravel PHP Framework with Nginx on Ubuntu 20.04
Next, Laravel uses an application key to secure user sessions and other encrypted
data. The default .env contains a default application key but you need to generate
a new one for your laravel deployment for security purposes.
https://www.tecmint.com/install-laravel-with-nginx-on-ubuntu/ 6/18
26/10/2020 How To Install Laravel PHP Framework with Nginx on Ubuntu 20.04
The generated key will be appended in the .env le as the value of the APP_KEY .
You can view the appended key using grep command.
You also need to con gure the Laravel database connection details in .env as
shown in the following screenshot.
https://www.tecmint.com/install-laravel-with-nginx-on-ubuntu/ 7/18
26/10/2020 How To Install Laravel PHP Framework with Nginx on Ubuntu 20.04
https://www.tecmint.com/install-laravel-with-nginx-on-ubuntu/ 8/18
26/10/2020 How To Install Laravel PHP Framework with Nginx on Ubuntu 20.04
In the con guration below, update the root directive to the Laravel application’s public
directory and make sure to replace www.example.com with the domain name of your
website as shown.
Also, set the fastcgi_pass directive should point to the medium PHP-FPM is
listening on for requests (for example fastcgi_pass unix:/run/php/php7.4-
fpm.sock ):
server{
server_name www.example.com;
root /var/www/html/example.com/public;
index index.php;
charset utf-8;
gzip on;
gzip_types text/css application/javascript text/javascr
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php {
include fastcgi.conf;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
https://www.tecmint.com/install-laravel-with-nginx-on-ubuntu/ 9/18
26/10/2020 How To Install Laravel PHP Framework with Nginx on Ubuntu 20.04
Save the le and then enable the Laravel site con guration by creating a link from
/etc/nginx/sites-available/example.com.conf to the /etc/nginx/sites-
enabled/ directory. Besides, remove the default server block con guration.
Next, check if the NGINX con guration syntax is correct by running the following
command before restarting the service.
$ sudo nginx -t
$ sudo systemctl restart nginx
Run the following commands to get the IP address of the Laravel server and add it to
the /etc/hosts le (replace the value according to your settings).
$ ip ad
$ echo “192.168.56.11 example.com” | sudo tee -a /etc/hosts
Now open a web browser on the local computer and use the following address to
navigate.
http://www.example.com/
https://www.tecmint.com/install-laravel-with-nginx-on-ubuntu/ 10/18
26/10/2020 How To Install Laravel PHP Framework with Nginx on Ubuntu 20.04
Now that you have Laravel installed, you can start building your web application or
site. For more information, see the Laravel documentation.
If you liked this article, then do subscribe to email alerts for Linux tutorials. If you
have any questions or doubts? do ask for help in the comments section.
TecMint is the fastest growing and most trusted community site for
any kind of Linux Articles, Guides and Books on the web. Millions of
people visit TecMint! to search or browse the thousands of
published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee
( or 2 ) as a token of appreciation.
Related Posts
https://www.tecmint.com/install-laravel-with-nginx-on-ubuntu/ 12/18
26/10/2020 How To Install Laravel PHP Framework with Nginx on Ubuntu 20.04
https://www.tecmint.com/install-laravel-with-nginx-on-ubuntu/ 13/18
26/10/2020 How To Install Laravel PHP Framework with Nginx on Ubuntu 20.04
Name *
Email *
Website
Save my name, email, and website in this browser for the next time I comment.
Notify me of followup comments via e-mail. You can also subscribe without
commenting.
Post Comment
This site uses Akismet to reduce spam. Learn how your comment data is processed.
https://www.tecmint.com/install-laravel-with-nginx-on-ubuntu/ 14/18
26/10/2020 How To Install Laravel PHP Framework with Nginx on Ubuntu 20.04
Linux Foundation LFCS and LFCE Certi cation Study Guide [eBooks]
How to Set and Unset Local, User and System Wide Environment Variables in Linux
https://www.tecmint.com/install-laravel-with-nginx-on-ubuntu/ 15/18
26/10/2020 How To Install Laravel PHP Framework with Nginx on Ubuntu 20.04
BCC – Dynamic Tracing Tools for Linux Performance Monitoring, Networking and
More
20 Netstat Commands for Linux Network Management
https://www.tecmint.com/install-laravel-with-nginx-on-ubuntu/ 16/18
26/10/2020 How To Install Laravel PHP Framework with Nginx on Ubuntu 20.04
How to Record and Replay Linux Terminal Sessions using ‘script’ and
‘scriptreplay’ Commands
How to Find Out Top Directories and Files (Disk Space) in Linux
https://www.tecmint.com/install-laravel-with-nginx-on-ubuntu/ 17/18
26/10/2020 How To Install Laravel PHP Framework with Nginx on Ubuntu 20.04
Tecmint: Linux Howtos, Tutorials & Guides © 2020. All Rights Reserved.
The material in this site cannot be republished either online or of ine, without our permission.
https://www.tecmint.com/install-laravel-with-nginx-on-ubuntu/ 18/18