Skip to content

Instantly share code, notes, and snippets.

@zgramming
Last active November 5, 2022 13:55
Show Gist options
  • Save zgramming/b8a73080d0f40a3ae7bf404518c6b114 to your computer and use it in GitHub Desktop.
Save zgramming/b8a73080d0f40a3ae7bf404518c6b114 to your computer and use it in GitHub Desktop.
How to deploy laravel project on your VPS
TUTORIAL INSTALL PROJECT LARAVEL DI VPS
Source Tutorial : https://www.youtube.com/watch?v=ZiqE6uOTbf4
Referensi subdomain : https://adamtheautomator.com/nginx-subdomain/
REVISI
- sudo apt update
- sudo apt upgrade
- sudo apt install ca-certificates apt-transport-https
- sudo apt install software-properties-common
- sudo add-apt-repository ppa:ondrej/php
- sudo apt install php7.4 php7.4-fpm
- sudo apt install php7.4-{cli,common,curl,zip,gd,mysql,xml,mbstring,json,intl}
Install Nginx
- sudo apt install nginx certbot python3-certbot-nginx
- sudo nano /etc/nginx/sites-available/NAMA_FOLDER_WEBSITE_DARI_VAR_WWW , lalu gunakan config(1.0)
- sudo ln -s /etc/nginx/sites-available/NAMA_FOLDER_PROJECT /etc/nginx/sites-enabled
- sudo nginx -t (memastikan kalau tidak ada syntax error saat config nginx)
- sudo systemctl restart nginx (restart nginx)
Install MySQL
- sudo apt-get install mysql-server
- izinkan mysql untuk di-remote access
- sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
- cari line bind-address, kemudian ubah yang tadinya 127.0.0.1 => 0.0.0.0
- sudo ufw allow 3306
- sudo service mysql restart
- sudo systemctl status mysql.service (check apakah status mysql active / tidak)
- CREATE USER 'zeffry'@'%' IDENTIFIED WITH mysql_native_password BY 'YOUR_PASSWORD';
- GRANT ALL PRIVILEGES ON *.* TO 'zeffry'@'%' WITH GRANT OPTION;
- FLUSH PRIVILEGES;
- sudo mysql && ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'passwordku'
Install Composer
- sudo curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
- sudo HASH=`curl -sS https://composer.github.io/installer.sig`
- sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
- cd /var/www/YOUR_PROJECT_LARAVEL && composer install
- sudo chown -R $USER:www-data /var/www/YOUR_PROJECT_LARAVEL/storage
- sudo chown -R $USER:www-data /var/www/YOUR_PROJECT_LARAVEL/bootstrap
- sudo chmod -R 775 /var/www/YOUR_PROJECT_LARAVEL/storage
- sudo chmod -R 775 /var/www/YOUR_PROJECT_LARAVEL/bootstrap
- ikuti langkah install larave https://github.com/zgramming/laravel-starter-project
- sudo nano /etc/nginx/sites-available/NAMA_PROJECT_LARAVEL (pakai config nginx 1.0 dibawah)
- sudo nginx -t (pastikan tidak ada error saat setup nginx)
- sudo ln -s /etc/nginx/sites-available/NAMA_PROJECT_LARAVEL /etc/nginx/sites-enabled/
- sudo systemctl restart nginx (RESTART NGINX)
- sudo nano /etc/nginx/nginx.conf && sudo systemctl restart nginx (ikuti config 2.0)
- php --ini (untuk cari letak versi php) && sudo nano LOKASIPHP/php.ini
post_max_size = 50M
upload_max_filesize = 50M
- sudo service php8.1-fpm restart && sudo systemctl restart nginx (restart php setiap ada settingan yang berubah)
Setup nginx sites-available
server {
# Binds the TCP port 80.
listen 80;
# Root directory used to search for a file
root /var/www/zeffry-reynando-admin/public;
# Defines the file to use as index page
index index.html index.htm;
# Defines the domain or subdomain name.
# If no server_name is defined in a server block then
# Nginx uses the 'empty' name
server_name admin.zeffry.my.id;
location / {
try_files $uri /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
2.0
http {
client_max_body_size 100M;
}
SETUP SSL DI DOMAIN / SUBDOMAIN
sudo apt-get install certbot python3-certbot-nginx -y
sudo certbot certonly --agree-tos --email YOUR_EMAIL@gmail.com -d YOUR_DOMAIN.COM && choose number 1 Nginx Web Server plugin (nginx)
After that, remember certificate & the key location
- /etc/letsencrypt/live/zeffry.my.id/fullchain.pem (certificate)
- /etc/letsencrypt/live/zeffry.my.id/privkey.pem (key)
sudo chown -R $USER:$USER /etc/letsencrypt(to grant access)
sudo chmod -R 775 /etc/letsencrypt
ls /etc/letsencrypt/live/*zeffry.my.id/ (check if certificate exists)
sudo nano /etc/nginx/sites-available/YOUR_DOMAIN (gunakan 2.0)
sudo systemctl restart nginx (restart nginx)
3.0 Sites available after use SSL
server {
# Binds the TCP port 80.
listen 80;
# Defines the domain or subdomain name.
# If no server_name is defined in a server block then
# Nginx uses the 'empty' name
server_name admin.zeffry.my.id;
# Redirect the traffic to the corresponding
# HTTPS server block with status code 301
return 301 https://$host$request_uri;
}
server {
# Binds the TCP port 80.
listen 443 ssl;
# Root directory used to search for a file
root /var/www/zeffry-reynando-admin/public;
# Defines the file to use as index page
index index.html index.htm;
# Defines the domain or subdomain name.
# If no server_name is defined in a server block then
# Nginx uses the 'empty' name
server_name admin.zeffry.my.id;
# SSL Configuration
# Path of the SSL certificate
ssl_certificate /etc/letsencrypt/live/admin.zeffry.my.id/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/admin.zeffry.my.id/privkey.pem;
# Use the file generated by certbot command.
include /etc/letsencrypt/options-ssl-nginx.conf;
# Define the path of the dhparam.pem file.
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
location / {
try_files $uri /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment