Last Updated on January 26, 2021 by Vikash Ekka
|Install and setup Laravel 7 on Ubuntu 18.04 and 20.04 LTS|
Hey guys, In this blog, I’m writing how to install and configure Laravel 7 on Ubuntu 18.04 LTS and Ubuntu 20.04 LTS from scratch with step by step example. The same instructions would be applied for Ubuntu 20.04 LTS.
Before we start installing Laravel 7, make sure that you have already installed LAMP (Linux, Apache, MySQL, and PHP). If not then you can follow the link to install and configure the LAMP stack on your system Link
Laravel is an open-source PHP framework that is designed for the faster development of MVC web applications in PHP.
Before move on you will need to make sure your server meets the following requirements. To do so install all php extension.
Note:- PHP >= 7.2.5
sudo apt install php7.2-common php7.2-cli php7.2-gd php7.2-mysql php7.2-curl php7.2-intl php7.2-mbstring php7.2-bcmath php7.2-imap php7.2-xml php7.2-zip
Table of Contents
- Install Composer
- Install Laravel 7
- Create and setup Database Connection for Laravel
- Apache Configuration
- Enable Laravel virtual host file and Apache2 Rewrite Module
- Restart Apache2 server
- Access Laravel Application
sudo apt install composer
The above command will install the composer in your Ubuntu system.
Install Laravel 7
For this blog, I’m installing laravel 7 in /var/www/html/ directory. To install Laravel 7 enter the following command.
composer create-project laravel/laravel vetechno –prefer-dist “7.*”
sudo chown -R www-data:www-data /var/www/html/vetechno/
sudo chmod -R 755 /var/www/html/vetechno/
Create and setup Database Connection for Laravel
mysql -u root -p
mysql> CREATE DATABASE vetechno;
mysql> GRANT ALL ON vetechno.* to ‘laravel’@’localhost’ IDENTIFIED BY ‘pass##123’;
mysql> FLUSH PRIVILEGES;
Next, Go to /var/www/html/vetechno and rename the .env.example file to .env .Enter the following command
cp .env.example .env OR mv .env.example .env
Then enter the following command to generate the Laravel 7 Key
php artisan key:generate
Now edit the .env configuration file settings and update the database connection with the following code. Also, make sure APP_KEY is properly set as generated in the above command.
sudo nano /etc/apache2/sites-available/laravel-vetechno.conf
Now copy and paste the below code and save it.
Require all granted
CustomLog /access.log combined
Enable Laravel virtual host configuration file and Apache2 Rewrite Module
sudo a2ensite laravel-vetechno.conf
sudo a2enmod rewrite
Access Laravel Application
This command will start a development server at http://localhost:8000
php artisan serve
Congratulations you have successfully installed and configured the Laravel 7 PHP framework on your Ubuntu system. Access Laravel application in your favorite web browser. If this blog really helpful then please do comment on the comment box. Please feel free to ask questions.