Server
Server
อีกที : macOS 11.0 Big Sur Apache/MiriaDB/PHP Setup
รอก่อนนะ ค่อยกลับมาทยอยเขียน
Edit Apache config
sudo nano /etc/apache2/httpd.conf
ServerName my.local.:80 <Directory "/"> AllowOverride All Require all denied </Directory> <Directory "/Library/WebServer/Documents"> AllowOverride All </Directory>
Restart Apache
sudo apachectl restart sudo apachectl -k graceful
Edit MariaDB config
nano ~/.my.cnf
Restart MariaDB
mysql.server restart
ที่มา
Ubuntu Web Server Setup
แปะไว้ก่อน ค่อยมาเขียนรายละเอียดนะครับ
sudo nano /etc/php/7.4/fpm/php.ini sudo systemctl restart apache2sudo nano /etc/mysql/conf.d/mysqld.cnf sudo systemctl restart mysql
mkdir remotefolder sshfs -p 22 username@example.com:/home/folder/ remotefolder umount remotefolder
sshfs -p 22 username@example.com:/home/user/domains/example.com/public_html/ remotefolder nohup rsync -trv remotefolder/path/ path/ &
sudo apt update<br /> sudo apt upgrade
sudo apt install apache2 -y systemctl status apache2
sudo a2dismod ssl sudo a2enmod ssl<br /> <br /> <br />
apt install php7.4 php7.4-mysql php-common php7.4-cli php7.4-json php7.4-common php7.4-opcache libapache2-mod-php7.4
apt install mariadb-server mariadb-client systemctl status mariadb
mysql> CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password'; mysql> GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';<br /> <br /> <br />
sudo systemctl restart apache2<br /> sudo systemctl restart mysql<br /> <br /> <br /> wget -r --ask-password ftp://user:server.com/
- https://upcloud.com/community/tutorials/installing-lamp-stack-ubuntu/?utmterm=&utmcampaign=DSA&utmsource=adwords&utmmedium=ppc&hsaacc=9391663435&hsacam=7185608860&hsagrp=81739862313&hsaad=391197952986&hsasrc=g&hsatgt=dsa-460992423274&hsakw=&hsamt=b&hsanet=adwords&hsaver=3&gclid=CjwKCAiAeb-BRB2EiwAGBnXXuae-7ru2jsgSAiku6bX0k7XucjvKLGBQkSm-DKo92SXjG1odKAeRoCid0QAvD_BwE - https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql - https://stackoverflow.com/questions/113886/how-to-recursively-download-a-folder-via-ftp-on-linux - https://askubuntu.com/questions/709594/how-can-i-disable-and-enable-ssl-in-apache-without-a-command-if-possible
Apache Config on Ubuntu Server :: Manual add new site
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
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
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 ntp restart
ที่มา
- How To Secure Apache with Let's Encrypt on Ubuntu 18.04
- E: The repository 'http://ppa.launchpad.net/certbot/certbot/ubuntu focal Release' does not have a Release file
- How To Use SSHFS to Mount Remote File Systems Over SSH
- How to wget a file to a remote machine over SSH?
- Correct way to completely remove issued certificate(s) for a domain
- How to increase memory size for MySQL Server
- MySQL Performance Tuning Settings
- HOWTO: Sync เวลาไม่ควรใช้ ntpdate ควรใช้ ntpd แทน
Check and Repair Hardisk
umount -l /dev/sda1 e2fsck -cfpv /dev/sda1 > chresult.txt&
Install AFP Share Server Protocal on Linux
sudo apt-get install netatalk
sudo nano /etc/netatalk/AppleVolumes.default
/shares "Shares" /media/user/VolumeName "ShareName"
sudo /etc/init.d/netatalk restart
วิธีการติดตั้ง Let’s Encrypt automated free SSL certificate
เข้าสู่ยุค https จึงจำต้องทำเสียแล้ว
มาลองติดตั้ง Let's Encrypt บน Directadmin กันอีกสักรอบ
1. เริ่มด้วยการแก้ไข config ของ Directadmin ให้สามารถใช้งาน Let's Encrypt ก่อน
nano /usr/local/directadmin/conf/directadmin.conf
สำหรับใครที่ใช้ path : /var/www/html/.well-known (ใช้โดเมนเดียว) ให้เพิ่ม
enable_ssl_sni=1 letsencrypt=1
ส่วนใครที่ใช้ path : /home/user/domains/domain.com/public_html/.well-known (ใช้หลายโดเมน) ให้เพิ่ม
enable_ssl_sni=1 letsencrypt=2
หรือจะสั่งผ่าน Terminal ก็ได้โดย
echo enable_ssl_sni=1 >> /usr/local/directadmin/conf/directadmin.conf echo letsencrypt=2 >> /usr/local/directadmin/conf/directadmin.conf
แล้วสั่ง update config โดย
cd /usr/local/directadmin/custombuild ./build update ./build rewrite_confs
2. แล้วมาเพิ่ม Let's Encrypt ให้กับแต่ละเว็บ
กำหนดให้เว็บสามารถใช้งาน Secure SSL ก่อน
แล้วจึงไปเพิ่ม SSL Certificates ให้กับเว็บ โดยเลือก Free & automatic certificate from Let's Encrypt
(ต้องทำทั้ง www และ ไม่มี www)
ถ้าต้องการให้สามารถใช้งานได้ทั้ง https และ http ให้สร้าง link private _ html ให้ชี้ไปที่ public _ html ด้วยคำสั่ง
ln -s public _ html private _ html
แต่ถ้าต้องการให้ใช้งานเฉพาะ https อย่างเดียว ให้ rename public _ html ไปเป็น private _ html แล้วสร้าง folder public _ html ใหม่ และสร้างไฟล์ .htaccess โดยเพิ่มคำสั่ง
RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Let's Encrypt ก็จะเป็นของเรา
Linux Server Tools
top :: the Linux Top Command
top
iotop :: I/O Monitor
iotop
iftop :: Bandwidth Monitor
iftop
iptstate : IP Tables State
iptstate
df :: Display Free Disk Space
df
Make Macbook Pro to be Web Server
แก้ config ของ Apache
sudo nano /etc/apache2/httpd.conf
AllowOverride All
เปิดใช้งาน mod_rewrite
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
Install PHP
brew update brew install php@7.3 brew link php@7.3 brew services start php@7.3
เปิดใช้งาน php
LoadModule php7_module libexec/apache2/libphp7.so
เปลี่ยน DocumentRoot ของ web
sudo mv /Library/WebServer/Documents /Library/WebServer/Documents.old sudo ln -s /New/Web/Folder /Library/WebServer/Documents
แก้ php config โดย cp /etc/php.ini.default /etc/php.ini
post_max_size = 16M upload_max_filesize = 1024M date.timezone = Asia/Bangkok
Restart Apache
sudo apachectl configtest sudo apachectl -k restart
ที่มา macOS 10.15 Catalina Apache Setup: SSL
Install MariaDB
brew install mariadb
Start MariaDB
Service start
brew services start mariadb
Start without service
mysql.server start
Link data to new location
sudo ln -s /Users/mysql /usr/local/var/mysql sudo chown -h user:group /usr/local/var/mysql
แก้ไข config file ~/.my.cnf
sql_mode = NO _ ENGINE _ SUBSTITUTION,STRICT _ TRANS _ TABLES default-storage-engine = MYISAM collation-server = utf8_unicode_ci character-set-server = utf8
Auto Start
launchd In MacOS, create a file called /Library/LaunchDaemons/com.mariadb.server.plist with the following contents (edit to suit):
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.mariadb.server</string> <key>KeepAlive</key><true/> <key>RunAtLoad</key><true/> <key>LaunchOnlyOnce</key><false/> <key>ExitTimeOut</key><integer>600</integer> <key>WorkingDirectory</key><string>/usr/local/var</string> <key>Program</key><string>/usr/local/bin/mysqld</string> <key>ProgramArguments</key> <array> <string>/usr/local/bin/mysqld</string> <string>--user=_mysql</string> <string>--basedir=/usr/local/opt/mariadb</string> <string>--plugin-dir=/usr/local/opt/mariadb/lib/plugin</string> <string>--datadir=/usr/local/var/mysql</string> <string>--log-error=/usr/local/var/mysql/Data-Server.local.err</string> <string>--pid-file=/usr/local/var/mysql/Data-Server.local.pid</string> <string>--sql-mode=ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION</string> </array> </dict> </plist>
Then from a shell, run launchctl load /Library/LaunchDaemons/com.mariadb.server.plist and MariaDB will run immediately, and also upon reboot.
Fix the 2002 socket error first if you haven’t done so from the MySQL section-
sudo mkdir /var/mysql
Location -> /usr/local/Cellar/mariadb/{version}
Data location /usr/local/var/mysql/
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
Start MySQL
sudo /usr/local/mysql/support-files/mysql.server start
Stop MySQL
sudo /usr/local/mysql/support-files/mysql.server stop
Restart MySQL
sudo /usr/local/mysql/support-files/mysql.server restart
พบบั๊ก GHOST ใน glibc ความร้ายแรงระดับสูง กระทบลินุกซ์รุ่นเก่าจำนวนมาก
บริษัท Qualys รายงานบั๊กในไลบรารี glibc ให้ชื่อช่องโหว่ว่า GHOST (CVE-2015-0235) มีความร้ายแรงระดับสูงมาก กระทบลินุกซ์ตั้งแต่ปี 2000 และสามารถยิงช่องโหว่นี้ได้จากระยะไกล บั๊กนี้แก้ไขไปแล้วตั้งแต่สองปีก่อน แต่ไม่ได้ระบุว่าเป็นบั๊กความปลอดภัยร้ายแรงเนื่องจากยังไม่มีรายงานว่าสามารถอาศัยบั๊กนี้โจมตีเครื่องเซิร์ฟเวอร์ได้
ช่องโหว่นี้เป็นบั๊กของฟังก์ชั่น gethostbyname และ gethostbyname2 ของ glibc ตั้งแต่เวอร์ชั่น 2.2 ที่ออกมาตั้งแต่ปี 2000 เป็นต้นไป ความร้ายแรงของบั๊กนี้อยู่ที่การรันบั๊กจากระยะไกลได้ง่าย เพราะฟังก์ชั่นทั้งสองฟังก์ชั่นมักใช้งานในเซิร์ฟเวอร์อยู่แล้ว ทีมงานสามารถสร้างอีเมลที่มุ่งร้ายขึ้นมาเพื่อส่งเข้าไปรันโค้ดบนเซิร์ฟเวอร์ได้สำเร็จ เพียงแค่ส่งอีเมลเข้าเมลเซิร์ฟเวอร์
สำหรับคนที่ติดตั้งลินุกซ์ที่ใช้ glibc รุ่นตั้งแต่ 2.18 เป็นต้นไป (ออกเมื่อกลางปี 2013) จะไม่ได้รับผลกระทบจากบั๊กนี้อยู่แล้ว แต่เนื่องจากการแก้บั๊กไม่ได้เป็นการแก้ด้านความปลอดภัย คนที่ใช้ลินุกซ์รุ่นที่ออกก่อนหน้านั้นอาจจะไม่ได้รับแพตช์ โดยรุ่นที่มีบั๊กแต่ยังไม่ได้แพตช์ เช่น Debian 7, RHEL 6 และ 7, CentOS 6 และ 7, และ Ubuntu 12.04 เป็นต้น ผู้ดูแลระบบทุกคนควรรีบตรวจสอบและอัพเดตเมื่อผู้ผลิตปล่อยแพตช์ออกมาครับ
ทาง Qualys รายงานโค้ดทดสอบบั๊กเอาไว้ด้วย สามารถนำไปคอมไพล์ทดสอบบั๊กกันได้
ชื่อบั๊กเป็นการย่อมาจากคำว่า GetHOST
ที่มา - Qualys ผ่าน Blognone.com
Server Setup : การกำหนดสิทธิ์ Root ให้กับ user บน Ubuntu 14.04
Pre-Flight Check
- These instructions are intended specifically for adding a user on Ubuntu 14.04 LTS.
- I’ll be working from a Liquid Web Core Managed Ubuntu 14.04 LTS server, and I’ll be logged in as root.
Step 1: Add the User
It’s just one simple command to add a user. In this case, we’re adding a user called mynewuser :
adduser mynewuser
First you will be prompted to enter the user’s password (twice); do this step. Next you’ll be prompted to enter in the user’s information. This step is not required, and pressing enter fills the field with the default information:
Adding user `mynewuser’ … Adding new group `mynewuser’ (1001) … Adding new user `mynewuser’ (1001) with group `mynewuser’ … Creating home directory `/home/mynewuser’ … Copying files from `/etc/skel’ … Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully Changing the user information for mynewuser Enter the new value, or press ENTER for the default Full Name []: User Room Number []: Work Phone []: Home Phone []: Other []:
When prompted with the following question, enter Y then hit enter to continue.
Is the information correct? [Y/n] Y
Step 2: Grant Root Privileges to the User
visudo
Find the following code:
# User privilege specification root ALL=(ALL:ALL) ALL
In this case, we’re granting root privileges to the user mynewuser . Add the following below that code:
mynewuser ALL=(ALL:ALL) ALL
Then exit and save the file with the key commands Ctrl-x, Y, enter.
If you’ve followed the instruction above correctly, then you should now have a user setup by the name of mynewuser which can use sudo to run commands as root!
ที่มา How to Add a User and Grant Root Privileges on Ubuntu 14.04