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.
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:
1 | sudo apt install composer |
Install PHP
Install PHP beserta extension yang dibutuhkan:
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:
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:
1 | composer create-project laravel/laravel blog |
Menjalankan Laravel dengan Development Server
Menjalankan Laravel dengan menggunakan development server:
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:
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.
Menjalankan Laravel dengan Apache
Install Apache web server:
1 | sudo apt install apache2 libapache2-mod-php |
Restart apache2 service:
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:
1 | sudo nano /etc/apache2/sites-available/laravel.web.conf |
Masukkan konfigurasi virtual host:
1 2 3 4 5 6 7 8 9 10 11 | <VirtualHost *:80> ServerName laravel.web DocumentRoot /home/musaamin/public_html/blog/public <Directory /home/musaamin/public_html/blog/public> Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted </Directory> ErrorLog /var/log/apache2/laravel.web_error.log CustomLog /var/log/apache2/laravel.web_access.log combined </VirtualHost> |
Aktifkan virtual host dan Apache rewrite module:
1 2 | sudo a2ensite laravel.web.conf sudo a2enmod rewrite |
Restart apache2 service:
1 | sudo systemctl restart apache2 |
Ubah ownership dan permission folder DocumentRoot:
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:
1 | sudo nano /etc/hosts |
Masukkan local domain laravel.web:
1 | 127.0.0.1 laravel.web |
Browse http://laravel.web.
Install SSL
Install sertifikat SSL untuk local server dengan menggunakan mkcert agar bisa menjalankan HTTPS protocol.
Install paket dependensi untuk Homebrew:
1 | sudo apt install build-essential curl file git |
Download dan jalankan installer Homebrew:
1 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)" |
Membuat homebrew tersedia di system environment:
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:
1 | sudo apt install libnss3-tools |
Install mkcert via brew:
1 | brew install mkcert |
Install Certificate Authority (CA):
1 | mkcert -install |
Membuat sertifikat SSL untuk laravel.web:
1 | mkcert laravel.web |
Membuat direktori ssl dan memindahkan SSL yang sudah dibuat ke dalamnya:
1 2 | sudo mkdir /etc/apache2/ssl sudo mv laravel.web*.pem /etc/apache2/ssl |
Buka file konfigurasi laravel.web virtual host:
1 | sudo nano /etc/apache2/sites-available/laravel.web.conf |
Ubah konfigurasinya menjadi:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <VirtualHost *:80> ServerName laravel.web RewriteEngine on RewriteCond %{SERVER_NAME} =laravel.web RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] </VirtualHost> <IfModule mod_ssl.c> <VirtualHost *:443> ServerName laravel.web DocumentRoot /home/musaamin/public_html/blog/public <Directory /home/musaamin/public_html/blog/public> Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted </Directory> 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 </VirtualHost> </IfModule> |
Aktifkan Apache SSL module dan restart apache2 service:
1 2 | sudo a2enmod ssl sudo systemctl restart apache2 |
Browse https://laravel.web.
MariaDB database
Install MariaDB database:
1 | sudo apt install mariadb-server |
Jalankan mysql_secure_installation:
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:
1 | sudo mysql -u root -p |
Membuat database dan user untuk Laravel:
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:
1 | nano ~/public_html/blog/.env |
Konfigurasi koneksi database:
1 2 3 | DB_DATABASE=blog DB_USERNAME=userblog DB_PASSWORD=passblog |
Membuat Fungsi Register dan Login
Jalankan migrate untuk membuat user table:
1 | php artisan migrate |
Memasang laravel/jetstream:
1 2 | composer require laravel/jetstream composer update |
Install livewire:
1 | php artisan jetstream:install livewire |
Fungsi register dan login sudah aktif.
Selamat mencoba 🙂
Illuminate\Database\QueryException
could not find driver (SQL: select * from information_schema.tables where table_schema = blog and table_name = migrations and table_type = ‘BASE TABLE’)
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
667▕ // If an exception occurs when attempting to run a query, we’ll format the error
668▕ // message to include the bindings with SQL, which will make this exception a
669▕ // lot more helpful to the developer instead of just the database’s errors.
670▕ catch (Exception $e) {
➜ 671▕ throw new QueryException(
672▕ $query, $this->prepareBindings($bindings), $e
673▕ );
674▕ }
675▕
+34 vendor frames
35 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
ini kenapa ya bang, udah nyari di internet katanya suruh ngedit php.ini apalah itu… tetep gk solve
itu error setelah php artisan migrate bang
dari pesan error driver untuk database tidak ditemukan