Cara Install Laravel 8 di Ubuntu 20.04

Laravel 8 dirilis pada tanggal 8 September 2020. Mulai di rilis ini, rilis mayor akan dirilis setiap 6 bulan sekali pada bulan Februari dan Agustus, sementara untuk rilis minor dan patch akan dirilis setiap minggu. Laravel 8 bukan versi Long Term Support (LTS), bug fixes didukung sampai 8 Maret 2021 dan security fixes didukung sampai 8 September 2021. Informasi rilis Laravel 8 dapat dibaca secara lengkap di Release Notes.

Support policy

*Server Requirements*

Server requirements yang harus dipenuhi untuk menjalankan 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 menggunakan Composer untuk mengelola dependensinya. Jadi, sebelum install Laravel, install Composer terlebih dahulu.

Install Composer:

[INPUT]

1 sudo apt install composer

*Install PHP*

Install PHP beserta extension yang dibutuhkan:

[INPUT]

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

*Install Laravel*

Install Laravel 8.0 dengan menggunakan Composer dan tersimpan dalam folder */home/musaamin/public_html/blog*:

[INPUT]

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

Jika tidak menuliskan nomor versi yang terinstall adalah Laravel versi terbaru:

[INPUT]

1 composer create-project laravel/laravel blog

*Menjalankan Laravel dengan Development Server*

Menjalankan Laravel dengan menggunakan development server:

[INPUT]

1 2 cd blog php artisan serve

Hasil perintah di atas menjalankan development server dengan IP address 127.0.0.1 (localhost IP) dan 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

*Menjalankan Laravel dengan 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* bisa diubah menjadi hostname atau local domain dengan menggunakan Apache *virtual host* dan file */etc/hosts*.

Membuat virtual host dengan nama *laravel.web*:

[INPUT]

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

Masukkan konfigurasi virtual host:

[INPUT]

1 2 3 4 5 6 7 8 9 10 11     ServerName laravel.web         DocumentRoot /home/musaamin/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

Aktifkan virtual host dan Apache rewrite module:

[INPUT]

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

Restart apache2 service:

[INPUT]

1 sudo systemctl restart apache2

Ubah ownership dan permission folder DocumentRoot:

[INPUT]

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

Buka file */etc/hosts*:

[INPUT]

1 sudo nano /etc/hosts

Masukkan local domain *laravel.web*:

[INPUT]

1 127.0.0.1 laravel.web

Browse *http://laravel.web*.

Laravel local domain

*Install SSL*

Install sertifikat SSL untuk local server dengan menggunakan *mkcert* agar bisa menjalankan HTTPS protocol.

Install paket dependensi untuk Homebrew:

[INPUT]

1 sudo apt install build-essential curl file git

Download dan jalankan installer Homebrew:

[INPUT]

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

Membuat homebrew tersedia di 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 paket dependensi untuk 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

Membuat sertifikat SSL untuk laravel.web:

[INPUT]

1 mkcert laravel.web

Membuat direktori ssl dan memindahkan SSL yang sudah dibuat ke dalamnya:

[INPUT]

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

Buka file konfigurasi laravel.web virtual host:

[INPUT]

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

Ubah konfigurasinya menjadi:

[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/musaamin/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

Aktifkan Apache SSL module dan restart 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

Jalankan 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 ke MariaDB:

[INPUT]

1 sudo mysql -u root -p

Membuat database dan user untuk 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;

Buka file *.env*:

[INPUT]

1 nano ~/public_html/blog/.env

Konfigurasi koneksi database:

[INPUT]

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

*Membuat Fungsi Register dan Login*

Jalankan migrate untuk membuat user table:

[INPUT]

1 php artisan migrate

Memasang *laravel/jetstream*:

[INPUT]

1 2 composer require laravel/jetstream composer update

Install livewire:

[INPUT]

1 php artisan jetstream:install livewire

Fungsi register dan login sudah aktif.

Login & Register link

Register form

Laravel dashboard

Selamat mencoba 🙂

Leave a Reply

Your email address will not be published.