Install Laravel on Ubuntu 20.04
--Resource --
Update
Update your system:
sudo sudo apt update -y
sudo apt-get upgrade -y
Install Apache and PHP
Install the Apache webserver, PHP, and required PHP extensions:
sudo 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
Apache service - commands
systemctl status apache2
systemctl start apache2
systemctl enable apache2
Install Composer
Update your system:
sudo url -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer
verify the installed version:
composer --version
Install Laravel Framework
To install:
cd /var/www/html
sudo composer create-project laravel/laravel laravelapp --prefer-dist
cd laravelapp
php artisan
Change the ownership of the laravelapp directory and give proper permissions to the storage directory
chown -R www-data:www-data /var/www/html/laravelapp
chmod -R 775 /var/www/html/laravelapp/storage
Configure Apache to Serve Laravel App
Edit configuration file:
sudo nano /etc/apache2/sites-available/laravel.conf
Add these lines to the file (laravel.conf):
<VirtualHost *:80>
ServerName localhost
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:
a2ensite laravel.conf
a2enmod rewrite
Restart the Apache service:
systemctl restart apache2
Access Laravel App
Go to this url on browser:
localhost/