How to Install Laravel 8 on Ubuntu 20.04

Laravel 8 released on September 8, 2020. Starting with this release, major releases will be released every 6 months in February and August, while minor releases and patches will be released every week. Laravel 8 is not a Long Term Support (LTS) version, bug fixes are supported until March 8, 2021 and security fixes are supported until September 8, 2021. Laravel 8 release information can be read in full at Release Notes.

Support policy

*Server Requirements*

Server requirements that must be met to run Laravel 8:

· PHP >= 7.3 · BCMath PHP Extension · Ctype PHP Extension · Fileinfo PHP extension · JSON PHP Extension · Mbstring PHP Extension · OpenSSL PHP Extension · PDO PHP Extension · Tokenizer PHP Extension · XML PHP Extension

*Install Composer*

Laravel uses Composer to manage its dependencies. So, before installing Laravel, install Composer first.

Install Composer:

[INPUT]

1 sudo apt install composer

*Install PHP*

Install PHP and the required extensions:

[INPUT]

1 sudo apt install php php-common php-bcmath php-mbstring php-mysql php-tokenizer php-zip

*Install Laravel*

Install Laravel 8.0 using Composer and save it in the */home/user/public_html/blog* folder:

[INPUT]

1 2 3 mkdir ~/public_html cd ~/public_html composer create-project laravel/laravel blog 8.0

If you don’t specify a version number, the latest version of Laravel is installed:

[INPUT]

1 composer create-project laravel/laravel blog

*Running Laravel with a Development Server*

Running Laravel using a development server:

[INPUT]

1 2 cd blog php artisan serve

The results of the above command run the development server with IP address 127.0.0.1 (localhost IP) and port 8000:

[INPUT]

1 2 Starting Laravel development server: http://127.0.0.1:8000 [Thu Sep 10 23:32:56 2020] PHP 7.4.3 Development Server (http://127.0.0.1:8000) started

Browse *http://127.0.0.1:8000* atau *http://localhost:8000*.

Laravel 127.0.0.1:8000

*Running Laravel with Apache*

Install Apache web server:

[INPUT]

1 sudo apt install apache2 libapache2-mod-php

Restart *apache2* service:

[INPUT]

1 2 sudo systemctl restart apache2 sudo systemctl status apache2

URL address *http://127.0.0.1:8000* can be changed to a hostname or local domain using Apache *virtual host* and the file */etc/hosts*.

Create a virtual host with the name *laravel.web*:

[INPUT]

1 sudo nano /etc/apache2/sites-available/laravel.web.conf

Enter the virtual host configuration:

[INPUT]

1 2 3 4 5 6 7 8 9 10 11     ServerName laravel.web         DocumentRoot /home/user/public_html/blog/public              Options Indexes FollowSymLinks MultiViews         AllowOverride All         Require all granted          ErrorLog /var/log/apache2/laravel.web_error.log     CustomLog /var/log/apache2/laravel.web_access.log combined

Enable virtual host and Apache rewrite module:

[INPUT]

1 2 sudo a2ensite laravel.web.conf sudo a2enmod rewrite

Restart apache2 service:

[INPUT]

1 sudo systemctl restart apache2

Change ownership and permissions for the DocumentRoot folder:

[INPUT]

1 2 sudo chown -R $USER:www-data /home/user/public_html/blog sudo chmod -R 775 /home/user/public_html/blog

Open the file */etc/hosts*:

[INPUT]

1 sudo nano /etc/hosts

Enter local domain *laravel.web*:

[INPUT]

1 127.0.0.1 laravel.web

Browse *http://laravel.web*.

Laravel local domain

*Install SSL*

Install the SSL certificate for the local server using *mkcert* to run the HTTPS protocol.

Install the dependency package for Homebrew:

[INPUT]

1 sudo apt install build-essential curl file git

Download and run the Homebrew installer:

[INPUT]

1 sh -c “$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)”

Make homebrew available in the system environment:

[INPUT]

1 2 3 4 test -d ~/.linuxbrew && eval $(~/.linuxbrew/bin/brew shellenv) test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv) test -r ~/.bash_profile && echo eval” ($(brew –prefix)/bin/brew shellenv)” >>~/.bash_profile echo “eval $($(brew –prefix)/bin/brew shellenv)” >>~/.profile

Install the dependency package for mkcert:

[INPUT]

1 sudo apt install libnss3-tools

Install mkcert via brew:

[INPUT]

1 brew install mkcert

Install Certificate Authority (CA):

[INPUT]

1 mkcert -install

Create an SSL certificate for laravel.web:

[INPUT]

1 mkcert laravel.web

Create an ssl directory and move the created SSL into it:

[INPUT]

1 2 sudo mkdir /etc/apache2/ssl sudo mv laravel.web*.pem /etc/apache2/ssl

Open the laravel.web virtual host configuration file:

[INPUT]

1 sudo nano /etc/apache2/sites-available/laravel.web.conf

Change the configuration to:

[INPUT]

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24     ServerName laravel.web         RewriteEngine on     RewriteCond %{SERVER_NAME} =laravel.web     RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]           ServerName laravel.web         DocumentRoot /home/user/public_html/blog/public              Options Indexes FollowSymLinks MultiViews         AllowOverride All         Require all granted          ErrorLog /var/log/apache2/laravel.web_error.log     CustomLog /var/log/apache2/laravel.web_access.log combined       SSLEngine on     SSLCertificateFile /etc/apache2/ssl/laravel.web.pem     SSLCertificateKeyFile /etc/apache2/ssl/laravel.web-key.pem

Activate Apache SSL module and restart the apache2 service:

[INPUT]

1 2 sudo a2enmod ssl sudo systemctl restart apache2

Browse *https://laravel.web*.

Laravel https

*MariaDB database*

Install MariaDB database:

[INPUT]

1 sudo apt install mariadb-server

Run mysql_secure_installation:

[INPUT]

1 2 3 4 5 6 7 8 sudo mysql_secure_installation   Enter current password for root (enter for none): ENTER Set root password? [Y/n] y Remove anonymous users? [Y/n] y Disallow root login remotely? [Y/n] y Remove test database and access to it? [Y/n] y Reload privilege tables now? [Y/n] y

Login to MariaDB:

[INPUT]

1 sudo mysql -u root -p

Create a database and user for Laravel:

[INPUT]

1 2 3 4 5 CREATE DATABASE blog; CREATE USER ‘userblog’@’localhost’ IDENTIFIED BY ‘passblog’; GRANT ALL PRIVILEGES ON blog.* TO ‘userblog’@’localhost’; FLUSH PRIVILEGES; EXIT;

Open the *.env* file:

[INPUT]

1 nano ~/public_html/blog/.env

Database connection configuration:

[INPUT]

1 2 3 DB_DATABASE=blog DB_USERNAME=userblog DB_PASSWORD=passblog

*Create Register and Login Functions*

Run migrate to create a user table:

[INPUT]

1 php artisan migrate

Install *laravel/jetstream*:

[INPUT]

1 2 composer require laravel/jetstream composer update

Install livewire:

[INPUT]

1 php artisan jetstream:install livewire

The register and login functions are active.

Login & Register link

Register form

Laravel dashboard

Good luck 🙂

Leave a Reply

Your email address will not be published.

scroll to top