ก๊วนซอฟท์แวร์ </softganz> SoftGang (Gang Software)

Web &amp; Software Developer Gang.

Apache Config on Ubuntu Server :: Manual add new site

by Little Bear @10 ต.ค. 63 16:16 ( IP : 202...130 ) | Tags : Server , Apache

Apache Tuning from How To Optimize Apache

Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 15
MinSpareServers 5
MaxSpareServers 10
StartServers 5
MaxClients 150
MaxRequestsPerChild 0

Create new user how

sudo adduser userName

Make user sudo how

sudo adduser userName sudo

MySQL Configuration

  • Increrase memory size for MySQL Server using nano /etc/my.cnf and add/change value ตามรายละเอียด
    innodbbufferpoolsize = 2048M
    innodblogfilesize = 512M
    maxconnections = 500
    keybuffer_size = 512M
    

PHP Config

Set timezone to Asia/Bangkok

nano /etc/php/7.4/apache2/php.ini
date.timezone = Asia/Bangkok

Add CNAME domain.com to ppi.psu.ac.th

Add new site to Apache

cd /etc/apache2/sites-available
nano sites-available/doname.com.conf
<VirtualHost *:80>
    ServerName domain.com
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/domain.com
</VirtualHost>
<VirtualHost *:80>
    ServerName www.domain.com
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/domain.com
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost _default_:443>
    ServerName domain.com
    ServerAdmin webmaster@localhost
    DocumentRoot /home/user/domains/domain.com
</VirtualHost>
<VirtualHost _default_:443>
    ServerName www.domain.com
    ServerAdmin webmaster@localhost
    DocumentRoot /home/user/domains/domain.com
</VirtualHost>
</IfModule>
cd /etc/apache2/sites-enabled
ln -s ../sites-available/domain.com.conf domain.com.conf

Restart Apache

systemctl restart apache2

Restart MySql

systemctl restart mysql

INSTALL Let's Encrypt

1. ติดตั้งด้วย snap ดูรายละเอียดได้ที่ Certbot instructions

snap install --classic certbot
ln -s /snap/bin/certbot /usr/bin/certbot
certbot --apache
certbot certonly --apache
certbot renew --dry-run

2. ติดตั้งด้วย apt-get จาก repo

apt-add-repository -r ppa:certbot/certbot

After that, the following commands do not generate any errors:

apt update
apt-get update
apt install python3-certbot-apache
certbot --apache -d domain.com -d www.domain.com

You should test your configuration at:

https://www.ssllabs.com/ssltest/analyze.html?d=domain.com

IMPORTANT NOTES:

Congratulations! Your certificate and chain have been saved at:

  • /etc/letsencrypt/live/domain.com/fullchain.pem
  • Your key file has been saved at:
  • /etc/letsencrypt/live/domain.com/privkey.pem
  • Your cert will expire on 2021-01-08. To obtain a new or tweaked version of this certificate in the future, simply run certbot again with the "certonly" option. To non-interactively renew all of your certificates, run "certbot renew"

To test the renewal process, you can do a dry run with certbot:

sudo certbot renew --dry-run

Correct way to completely remove issued certificate(s) for a domain

certbot delete --cert-name domain.com

Copy file from another server using SSH

Alternatively, you could mount the myserver's filesystem over SSH with sshfs. This may be too much hassle for a one-off need, but convenient if you do this sort of thing often.

mkdir myserver
sshfs -p 22 domain.com:/path/ myserver
wget -O ~/myserver/path/to/remote/destination http://www.example.com/whatever

rsync -trv myserver/src/path/ dest/path/
umount myserver

rsync in background

nohup rsync -trv myserver/src/path/ dest/path/ &

Dump Database

mysqldump -u [username] -p [database-you-want-to-dump] > [path-to-place-data-dump.sql]
/usr/local/mysql/bin/mysqldump -u [username] -p [database-you-want-to-dump] > [path-to-place-data-dump.sql]

Ways to Flush DNS Cache on Mac OSx

sudo killall -HUP mDNSResponder

WhoIs LookUp

nslookup -type=ns softganz.com

Setup Time Sync

ติดตั้ง

apt-get install ntp

แก้ไข config

nano /etc/ntp.conf

เปลี่ยน server เป็น

server 1.th.pool.ntp.org
server 0.asia.pool.ntp.org
server 2.asia.pool.ntp.org
server clock.nectec.or.th

Restart

service ntpd restart

หรือ

service ntp restart

ที่มา

Relate topics