# Intro
Penggunaan apache web server sampai saat artikel ini dibuat masih sangan banyak, meskipun dengan adanya modern web server berbasis javascript yang sekarang sudah berkembang. Apache dipilih mungkin dari ke-mature-annya sebagai pendahulu di bidang web server.
Untuk deployment aplikasi Laravel di sini menggunakan Apache dan PHP sebagai web server dan interpreter.
# Pre-requisites
- Akses sebagai user biasa(non-root) ke Ubuntu yang telah terinstall.
- Internet akses untuk melakukan instalasi tool-tool yang diperlukan
# Update Ubuntu
sudo apt update
# Instalasi Apache
sudo apt install apache2
sudo a2enmod rewrite
sudo systemctl restart apache2
Tambahkan configuration apache2:
nano /etc/apache2/apache2.conf
<Directory /var/www/html/public/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# Instalasi PHP
sudo apt install --no-install-recommends php8.1
sudo apt install libapache2-mod-php
# Switch versi PHP
sudo update-alternatives --config php
# untuk php 7.4
php7.4-{mbstring,cli,bcmath,json,xml,zip,pdo,common,tokenizer,mysql}
# Jika PHP tidak jalan di apache
Tambah kode pada /etc/apache2/apache2.conf
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
# Jalankan perintah:
sudo a2dismod mpm_event && sudo a2enmod mpm_prefork && sudo a2enmod php7.4
# Restart
sudo service apache2 restart
# Instalasi MariaDB
sudo apt install mariadb-server
sudo mysql_secure_installation
sudo mariadb
GRANT ALL ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Izinkan akses melalui any remote hosts(opsional):
# memastikan listen ke localhost
netstat -ant | grep 3306
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
Set variable bind-address:
bind-address = 0.0.0.0
# Restart mariaDB
sudo systemctl restart mariadb
# Check koneksi kembali
netstat -ant | grep 3306
Grant Access:
mariadb -u yaris -p
GRANT ALL ON customdb.* to 'ruser'@'192.168.1.25' IDENTIFIED BY 'ruserpwd' WITH GRANT OPTION;
# Instalasi NVM dan NodeJS
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
source ~/.bashrc
nvm install 16.18.1
# Instalasi Composer
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
sudo php /tmp/composer-setup.php –install-dir=/usr/local/bin –filename=composer
# Instalasi Module PHP
Contoh module yang diinstal, contoh:
sudo apt install phpunit #optional
sudo apt install php-xml
sudo apt install php-mbstring
sudo apt install php-curl
atau untuk command spesifik ke php8.1 sebagai berikut:
sudo apt install phpunit #optional
sudo apt install php8.1-xml
sudo apt install php8.1-mbstring
sudo apt install php8.1-curl
# Generate dan tambahkan public key to Github
ssh-keygen
# Pengaturan html root dan privilege www-data untuk directory aplikasi web
#Buka file 000-default.conf menggunakan perintah:
nano /etc/apache2/sites-available/000-default.conf
#Edit value DocumentRoot:
DocumentRoot /path/to/my/project
#Kemudian restart server apache:
sudo service apache2 restart
sudo chown -R yourname:www-data html_public
# Mengubah owner dan group
sudo chmod -R g+s html_public
# menambah attribut s agar file dan direktori tetap dalam permission group seperti direktori html_public
# Izinkan untuk akses ke storage
sudo chgrp -R www-data /var/www/html/html_public
sudo chmod -R 775 /var/www/html/html_public/storage
# Clone & Pull Data Dari Repository dan Konfigurasinya
- Clone dari repository source code yang akan di-deploy.
- Ubah .env file, pastikan APP_URL diawali dengan http atau https, dan sesuaikan dengan alamat IP server maupun DNS.
- Reload laravel config: php artisan optimize
# Konfigurasi FTP Server
$ sudo apt update
$ sudo apt install vsftpd
$ sudo service vsftpd status
$ sudo nano /etc/vsftpd.conf
$ sudo systemctl start vsftpd
$ sudo systemctl enable vsftpd
# Remove vsftpd
$ sudo apt remove vsftpd
# Referensi
- https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-20-04
- https://www.digitalocean.com/community/tutorials/how-to-install-php-8-1-and-set-up-a-local-development-environment-on-ubuntu-22-04
- https://computingforgeeks.com/how-to-install-php-on-ubuntu-linux-system/
- https://ostechnix.com/how-to-switch-between-multiple-php-versions-in-ubuntu/
- https://phoenixnap.com/kb/install-ftp-server-on-ubuntu-vsftpd