Install Web Server Pada Arch Linux
install apache
sudo pacman -S apachemenjalankan/mematikan service
sudo systemctl start httpd.servicesudo systemctl stop httpd.serviceinstall mariadb
sudo pacman -S mariadbKonfigurasi mariadb
sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysqlsudo mysql_secure_installationmenjalankan/mematikan service
sudo systemctl start mariadb.servicesudo systemctl stop mariadb.serviceinstall php
sudo pacman -S php php-apache php-cgi php-gd php-imapkonfigurasi php
sudo vim /etc/php/php.iniuntuk menampilkan error
display_errors = onhapus komentar dan edit seperti ini
date.timezone = Asia/Jakartakonfigurasi hhtpd
sudo vim /etc/httpd/conf/httpd.confmelihat list module
ls /etc/httpd/modules/cek status konfigurasi apache server
sudo apachectl configtestMembuat User Baru
adduser hardusermod -aG sudo hardSSH Configure
Copy SSH Key
su - hardsudo mkdir ~/.sshsudo chmod 700 ~/.sshsudo nano ~/.ssh/authorized_keyssudo chmod 600 ~/.ssh/authorized_keyssudo exitLogin Automatis ssh
Pastikan Anda sudah membuat ssh keygen jika belum ketikan :
ssh-keygenJika sudah langsung ketikkan :
ssh-copy-id user@ipConfig SSH Server
Keterangan port :
Ports 0-1023 = system or well-known ports.
Ports 1024-49151 = user or registered ports.
Ports 49152-65535 = dynamic / private ports.
Untuk Konfigurasi ikuti cara berikut :
vim /etc/ssh/sshd_configRubah seperti ini
Port 50000
PermitRootLogin no
PubkeyAuthentication yes
PasswordAuthentication nokeluar dari text editor
sudo systemctl restart sshsudo systemctl status sshConfig SSH Login
Host NamaServer
Hostname HostServer
User UserServer
port portServer
identityFile ~/.ssh/id_rsa_tesSet Timezone
timedatectl set-timezone Asia/JakartadateUpdate System
sudo apt updatesudo apt upgrade -ysudo rebootTransfer File
scp crud.zip server:~/Install Apache
sudo apt install apache2 -yMembuat Virtual Host
mkdir /var/www/hard.comvim /var/www/hard.com/index.htmlcd /etc/apache2/sites-availablesudo vi hard.com.conf<VirtualHost *:80>
ServerName hard.com
ServerAlias www.hard.com
DocumentRoot /var/www/hard.com
<Directory /var/www/hard.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/apache2/hard.com_error.log
CustomLog /var/log/apache2/hard.com_access.log combined
</VirtualHost>sudo a2ensite hard.com.confsudo a2enmod rewritesudo systemctl restart apache2sudo systemctl status apache2Install PHP 7.4
sudo apt show phphttps://launchpad.net/~ondrej/+archive/ubuntu/php
sudo apt install software-properties-common -ysudo add-apt-repository ppa:ondrej/phpsudo apt install libapache2-mod-php7.4 php7.4 php7.4-common php7.4-mysql php7.4-curl php7.4-gd php-imagick php7.4-cli php7.4-mbstring php7.4-zip php7.4-bcmath -yphp -vphp -msudo apt search php7.4sudo vi /var/www/hard.com/info.php<?php phpinfo(); ?>sudo vi /etc/php/7.4/apache2/php.iniupload_max_filesize = 10M
post_max_size = 10Msudo systemctl restart apache2Install phpmyadmin
sudo apt install -y apache2 mysql-server php libapache2-mod-php php-mysql -ysudo apt install phpmyadmin php-json php-curl php-mbstring php-zipInstall composer
sudo apt install curl php7.4-cli php7.4-mbstring git unzip -ycurl –sS https://getcomposer.org/installer | phpsudo mv composer.phar /usr/local/bin/composerDi Ubuntu 18.04 bisa juga langsung :
sudo apt updatesudo apt install composerComposer on docker
docker pull composer:<tags>Cara Penggunaan
docker run --rm --interactive --tty \
--volume $PWD:/app \
composer <command>Dicontoh ini saya akan menggunakan composer untuk install laravel
docker run --rm --interactive --tty \
--volume $PWD:/app \
composer:<tags> create-project laravel/laravel <nama-project>Install MariaDB 10.4
Default MariaDB 10.1
sudo apt show mariadb-serverhttps://downloads.mariadb.org/mariadb/repositories/
sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://sgp1.mirrors.digitalocean.com/mariadb/repo/10.4/ubuntu bionic main'sudo apt install mariadb-server -ysudo systemctl status mariadbsudo mysql_secure_installationsudo mysql -u root -pmysql> CREATE DATABASE toko;mysql> CREATE USER 'hard'@'localhost' IDENTIFIED BY 'rahasia';mysql> GRANT ALL PRIVILEGES ON toko.* TO 'musa'@'localhost';mysql> FLUSH PRIVILEGES;mysql> exitcd /home/hardunzip crud.zipsudo mysql -u musa -p toko < crud/toko.sqlcp -v crud/* /var/www/hard.com/cd /var/wwwsudo rm hard.com/index.htmlsudo chown -R hard:www-data hard.comsudo chmod -R 775 hard.comsudo ls -lInstall SSL Let's Encrypt untuk Apache
https://certbot.eff.org/all-instructions
sudo add-apt-repository ppa:certbot/certbotsudo apt install certbot python3-certbot-apache -ycertbot --apache -d hard.com -d www.hard.comjika command diatas tidak bisa dijalankan maka ikuti command dibawah ini Checking Your Apache Virtual Host Configuration
sudo vi /etc/apache2/sites-available/your_domain.confedit
ServerName your_domain;
SeverAlias www.your_domainsudo apache2ctl configtestsudo systemctl reload apache2izinkan firefall
sudo ufw statussudo ufw allow 'Apache Full'sudo ufw delete allow 'Apache'sudo ufw statusMendapatkan SSL Certificate
sudo certbot --apache --register-unsafely-without-emailMenverifikasi pembaruan certbot karena Let’s Encrypt berlaku selama 10 hari maka lakukan pembaruan otomatis lankahnya seperti dibawah ini
sudo systemctl status certbot.timersudo certbot renew --dry-runInstall Nginx dan PHP-FPM
sudo systemctl stop apache2sudo systemctl disable apache2sudo systemctl status apache2sudo apt install nginx -ysudo apt install php7.4-fpm php7.4 php7.4-common php7.4-mysql php7.4-curl php7.4-gd php-imagick php7.4-cli php7.4-mbstring php7.4-zip php7.4-bcmath -ysudo systemctl status php7.4-fpmsudo vi /etc/php/7.4/fpm/pool.d/www.confsudo cd /etc/nginx/conf.dsudo nano hard.com.confserver {
listen 80;
server_name hard.com www.hard.com;
root /var/www/hard.com;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $fastcgi_script_name =404;
include fastcgi_params;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
}
access_log /var/log/nginx/hard.com_access.log;
error_log /var/log/nginx/hard.com_error.log;
}sudo nginx -tsudo systemctl restart nginxsudo systemctl status nginxsudo vi /etc/php/7.4/fpm/php.iniupload_max_filesize = 10M
post_max_size = 10MInstall SSL Let's Encrypt untuk Nginx
sudo apt install certbot python3-certbot-nginx -ysudo certbot --nginx -d hard.com -d www.hard.comFirewall iptables
- cloud firewall
- ufw
- firewalld
- iptables
sudo apt install iptables-persistent -ysudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPTsudo iptables -A INPUT -p icmp -j ACCEPTsudo iptables -A INPUT -p tcp --dport 50000 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPTsudo iptables -A INPUT -p tcp --dport 80 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPTsudo iptables -A INPUT -p tcp --dport 443 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPTsudo iptables -P INPUT DROPsudo netfilter-persistent savesudo netfilter-persistent reloadsudo iptables -Lsudo iptables -P INPUT ACCEPTsudo iptables -Fsudo iptables -LBackup
sudo mkdir -p backup/hard.com/wwwsudo mkdir backup/hard.com/dbsudo vi mysqldump-toko.cnf[mysqldump]
user=hard
password=rahasiavi backup.sh#!/bin/bash
rsync -av /var/www/defnex.com/ /root/backup/defnex.com/www --delete
mysqldump --defaults-extra-file=/root/mysqldump-toko.cnf toko | gzip > /root/backup/defnex.com/db/toko-$(date +%d%m%Y).sql.gzsudo chmod u+x backup.shsudo ./backup.shls -l backup/hard.com/wwwls -l backup/hard.com/dbrm backup/hard.com/www/*rm backup/hard.com/db/*crontab -e15 10 * * * /bin/bash /root/backup.shsudo systemctl restart cronFormat https://crontab.guru
ls -l backup/hard.com/wwwls -l backup/hard.com/dbProblem Server
Troubleshooting: Too Many Redirects
Cek Using cURL for Redirect Loops
vi redirects.sh#!/bin/bash
echo
for domain in $@; do
echo --------------------
echo $domain
echo --------------------
curl -sILk $domain | egrep 'HTTP|Loc' | sed 's/Loc/ -> Loc/g'
echo
donechmod +x redirects.shRedirects in the .htaccess File
- Force HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]- Force HTTPS: When Behind a Load Balancer or Proxy (CloudFlare/Incapsula/Sucuri/etc.)
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]- Force non-www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\. [NC] RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]- Force www
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule (.*) http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]- For Codeigniter
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>pilih dan sesuaikan dengan kebutuhan
Terimakasih
Silahkan sesuaikan tidak harus sama persis 😊