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
Also Read:- How To Install Linux, Apache, MySQL, PHP (LAMP) on Ubuntu 16.04
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
Install Composer
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.
cd /var/www/html/
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;
mysql> quit
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.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=vetechno
DB_USERNAME=laravel
DB_PASSWORD=pass##123
Apache Configuration
sudo nano /etc/apache2/sites-available/laravel-vetechno.conf
Now copy and paste the below code and save it.
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/vetechno/public
ServerName laravelblog.local
<Directory /var/www/html/vetechno/public>
Options +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
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
Conclusion
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.
Also Read:- How to uninstall PHP, Apache and MySQL on Ubuntu 16.04