Ubuntu
Ubuntu
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
[Geek] Linux basic comamnds

ชีวิตหวนกลับมาหา Linux : Ubuntu อีกครั้งหลังส่ง MacBook ไปเข้าโรงซ่อมเป็นครั้งที่ 2 พร้อมกับการรอคอยการกลับมาอีกประมาณ 3 สัปดาห์ (รวมความแล้ว 1 ปีกว่า ๆ ไม่ได้ใช้งานเครื่องเกือบ 2 เดือน)
จึงต้องหวนกลับมาหาคำสั่ง Linux อีกครั้ง
แต่ชีวิตก็มีความสุขดี
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
Setup FTP Server under Ubuntu/Debian
เก็บไว้ก่อน เดี๋ยวค่อยมาแปลและเขียนใหม่นะครับ
This article contains a brief introduction to set up an FTP-Server under Debian Linux. Activation of an FTP server should be done similarly with other distributions of Linux. Debian 5.0 (x86) was used as the test system.
Contents
- Installation of the required proftpd Package
- Adjusting the Configuration
- Anonymous FTP
- Re-loading the Configuration and Re-starting the FTP Server
- Links
Installation of the required proftpd Package
ProFTPd FTP-Server was used for this introduction because of its simply installation and configuration.
apt-get install proftpd
If the package cannot be found, update the local list of packages using:
apt-get update
If the package still cannot be installed after that, check the /etc/apt/sources.list on the appropriate Debian mirror server. You will find more information about this in the article Debian Mirror.
Indicate in the subsequent inquiry whether the FTP server should act as a standalone server (standalone) or as a service of inetd. In this example, the standalone option has been selected. Adjusting the Configuration
Our configuration assumes that we will login using system users found in the ftpuser group.
In order to adjust the configuration to your needs, edit the /etc/proftpd/proftpd.conf file.
If you are not using IPv6, this feature should be deactivated first:
UseIPv6 off
After that, we will add the following instruction at the end of the file:
<Global> RequireValidShell off </Global> DefaultRoot ~ ftpuser <Limit LOGIN> DenyGroup !ftpuser </Limit>
What do the instructions mean?
As a first step, we told ProFTPd that users wanting to login do not need a shell. Afterwards, we instructed ProFTPd to lock users in their home directory using DefaultRoot. Finally, we specified that only those users who are members of the ftpuser group could login.
We will now restart our FTP server so that our configuration takes effect:
/etc/init.d/proftpd restart
Then, we will create the ftpuser group and a first user that will be able to login.
addgroup ftpuser
Now, we create the user:
adduser ftpbenutzer -shell /bin/false -home /var/www
Finally, we assign the user to the ftpuser group:
adduser ftpbenutzer ftpuser
That’s everything. You should now be able to login with the user via FTP.
You have to run sudo deluser username groupname to delete a user from it's corresponding group. And run this sudo deluser --group groupname command to delete a group.
Anonymous FTP
By adding the following section to the etc/proftpd/proftpd.conf file, you will also give anonymous users (read) access to the FTP area:
. . . <Anonymous ~ftp> User ftp Group nogroup # We want clients to be able to login with "anonymous" as well as "ftp" UserAlias anonymous ftp # Cosmetic changes, all files belong to ftp user DirFakeUser on ftp DirFakeGroup on ftp RequireValidShell off # Limit the maximum number of anonymous logins MaxClients 10 # We want 'welcome.msg' displayed at login, and '.message' displayed # in each newly chdired directory. DisplayLogin welcome.msg DisplayFirstChdir .message # Limit WRITE everywhere in the anonymous chroot <Directory *> <Limit WRITE> DenyAll </Limit> </Directory> # # Uncomment this if you're brave. # # <Directory incoming> # # # Umask 022 is a good standard umask to prevent new files and dirs # # # (second parm) from being group and world writable. # # Umask 022 022 # # <Limit READ WRITE> # # DenyAll # # </Limit> # # <Limit STOR> # # AllowAll # # </Limit> # # </Directory> </Anonymous> . . .
To make sure, that user "ftp" is able to login anonymously to ftp-space, you have to add the user to the group "ftpuser":
adduser ftp ftpuser
Re-loading the Configuration and Re-starting the FTP Server
The configuration will have to be re-loaded after the adjustments to the /etc/proftpd/proftpd.conf file:
/etc/init.d/proftpd reload
Because the FTP server will be stopped when re-loading the configuration, it will also have to be re-started afterwards:
/etc/init.d/proftpd start
Links
- http://www.proftpd.org/ - Web site for the project
- http://www.castaglia.org/proftpd/ - Web site for the primary developer with numerous HOWTO pages and background information
ย้ายบ้านให้ MySql
วันนี้เกิดเหตุ wintesla2003.com หยุดทำงาน โชคดีที่สั่ง reboot ผ่าน DA แล้วสามารถเข้าใช้ ssh ได้ (หลังจากที่เข้า ssh ไม่ได้มาเป็นปี ก็ยังงงอยู่ว่ามันเข้าได้ยังไง โชคดีก็คือไม่ต้องวิ่งไปที่ IDC)
หลังจาก reboot ก็ยังใช้งานไม่ได้ ขณะกำลังหาสาเหตุ ก็นึกได้ว่า server นี้เคยมีปัญหากับ MySql มาครั้งนึงแล้ว คือ partition ที่เก็บข้อมูลเต็ม พอลอง df ดูก็ปรากฎว่าเต็มอีกแล้วจริง ๆ ด้วย
หลังจากลองย้ายบาง folder ออกไป ก็สามารถใช้งานได้ แต่มีบางตารางเสียหาย เลยสั่ง repair ปรากฎว่าเดี้ยงอีก เต็มอีกเหมือนเดิม
เลยตัดสินใจ "ย้ายบ้าน MySql ไปไว้อีก partition"
คำสั่ง
cd /home mkdir mysql chown mysql:mysql mysql cd mysql perl -pi -e 's/mysqld=ON/mysqld=OFF/' /usr/local/directadmin/data/admin/services.status /sbin/service mysqld stop cp -Rp /var/lib/mysql/* . cd /var/lib mv mysql mysql_old ln -s /home/mysql ./mysql /sbin/service mysqld start perl -pi -e 's/mysqld=OFF/mysqld=ON/' /usr/local/directadmin/data/admin/services.status <a class="hashtag" href="/tags/once">#once</a> satisfied that mysqld is running and functioning correctly, remove the old data: rm -rf mysql_old
ประมาณนี้ (แต่ผมไม่ได้ทำตามนี้เป๊ะ ๆ) คือ ย้ายข้อมูลไปไว้ใน /home แล้วทำ link จาก /var/lib/mysql ให้ชี้ไปที่ /home/mysql
ที่มา directadmin.com
ใครกิน I/O ของข้า
หลายวันที่ผ่านมาสังเกตุพบว่าเครื่องอืด ๆๆ ไฟฮาร์ดดิส ก็ ติด ๆ ดับ ๆ ตลอด ส่วนใหญ่จะติดตลอดเวลา แถม top - wa ขึ้น 30-40% ตลอด ก็งงว่า process อะไรวะที่กำลังเขียนฮาร์ดดิส เลยลองหาโปรแกรมเพื่อมาดูการใช้งาน I/O บน Ubuntu ซะหน่อย ว่าเกิดอะไรขึ้น
โปรแกรมที่ใช้ดูก็มี
- iotop
- atop
- cat /proc/[PID]/io
- pidstat
ดูจาก atop พบว่า gvfs- มันทำงานตลอด กิน I/O เยอะมาก น่าจะตัวนี้แหละ
kill ซะเลย
ชงัดนัก รอดูผล - ปกติด รอดูอีกครั้งหลัง reboot - ???
Dabian bandwidth monitoring
iftop
iftop
vnstat
vnstat -u -i eth0 vnstat vnstat -hours vnstat --days
iptstate
iptstate
Install PhoneGap on Ubuntu
Install open jdk verions 6.0
$ sudo apt-get install openjdk-6-jdk
First install node.js
$ sudo apt-get update $ sudo apt-get install python-software-properties python g++ make $ sudo add-apt-repository ppa:chris-lea/node.js $ sudo apt-get update $ sudo apt-get install nodejs $ node --version
ปกติ Ubuntu จะมี node package (Amateur Packet Radio Node Program) อยู่ และ nodejs binary จะถูกเปลียนชื่อจาก node เป็น nodejs เราจำเป็นต้องเปลี่ยน symlink /usr/bin/node เป็น /usr/bin/nodejs หรือไม่อย่างนั้นก็ uninstall เจ้า Amateur Packet Radio Node Program ออกเสียเพื่อไม่ให้เกิดความสับสน
Install Cordova 3.0.x
$ sudo npm install -g cordova
Install PhoneGap
$ sudo npm install -g phonegap
Change environment
$ export PATH=${PATH}:/Development/adt-bundle/sdk/platform-tools:/Development/adt-bundle/sdk/tools $ source ~/.bash_profile
Install SDK
Doanload from developer.android.com/sdk, extract, and run
android
Click New/Update to install SDK
Open a Project in the SDK
Use the cordova utility to set up a new project, as described in The Cordova The Command-line Interface. For example, in a source-code directory:
$ cordova create hello com.example.hello "HelloWorld" $ cd hello $ cordova platform add android $ cordova build
เสร็จแล้วครับ แต่ใช้ยังไงหว่า??? เดี๋ยวค่อยว่ากันอีกที ระหว่างนี้ก็แวะไปดูที่ PhoneGap ไปก่อนนะครับ
ลองดูตัวอย่างจาก
- ทบทวนที่เรียนจากติว PhoneGap ด้วย HTML5 & Jquery Mobile
- บทที่ 2 การเขียน Android โดยใช้ PhoneGap เบื้องต้น
- บทที่ 1 การติดตั้ง PhoneGap บน Eclipse สำหรับ Android
ที่มา github.com , phonegap.com
Disable USB keyboard wakeup
ต้องการยกเลิกการ wakeup ด้วยการกดปุ่มบน usb keyboard ก็เนื่องจากผมใช้ notebook ทำงาน แล้วช่วงหลังไม่สั่ง shutdown แต่จะสั่ง suspend แทน ตื่นมาบางเช้า เครื่องเปิดอยู่ ซึ่งก็คงมาจากมีใครมาโดน keyboard โดยไม่ตั้งใจ จึงอยาก disable มันเสีย
วิธีการ ลองเข้าไปแก้ไขในไฟล์ /proc/acpi/wakeup เปลี่ยนค่า ECH1, ECH 2 ให้เป็น disabled ก็ทำไม่ได้ ค่าจะถูกเปลี่ยนกลับ จึงต้องใช้วิธีเขียน script เพิ่มใน /etc/rc.local ตามนี้
# Disable USB wakeups caused by (un)plugging new devices. Otherwise the hub in # my USB monitor causes my PC to wake up when I turn the monitor off. for device in EHC1 EHC2 XHC do if grep -q "$device.*enabled" /proc/acpi/wakeup then echo $device > /proc/acpi/wakeup fi done
ที่มา askubuntu.com
อีกครั้ง - Make Ubuntu 16.04 to be a web server (LAMP)
ผ่านไปอีก 3 ปี (August,23 2016 14.12 PM) กับอีก 2 ปี (August,09 2013 23.27 PM) กลับมาเขียนใหม่อีกครั้ง หลังจากผ่าน 2 ปี ที่ได้ลง Ubuntu 13.04 ใหม่ในเครืองตนเอง ถือเป็นการล้างเครื่องและแก้ปัญหาที่เกิดจากการอัพเดทแล้วเกิด dependency ของ mysql-server กับ mysql-server-5.5 แล้วก็ลืมไปแล้วว่าหลังจากลงได้มีการปรับค่าอย่างไรบ้าง
Step 1 : Install [L.A.M.P Stack (Apache, Mysql, PHP
Install L.A.M.P Stack (Apache, Mysql, PHP) ทีเดียวซะเลย
root@god:/# apt-get install lamp-server^
ติดตั้งเพิ่มเติม php7-curl
root@god# apt-get install php-curl
แล้วก็ลง phpMyAdmin
root@god:/# apt-get install phpmyadmin
เลือก Apache แล้ว YES สำหรับ dbconfig-common.
Setup phpMyAdmin
root@god:/# nano /etc/phpmyadmin/config.inc.php
เปลี่ยนค่า
$cfg[‘LoginCookieValidity’] = 3600;
Enable mod_rewrite
root@god:/# a2enmod rewrite
เปลี่ยน DocumentRoot ของ apache เป็น folder อื่น และเปิดใช้งาน clean url
root@god:/# nano /etc/apache2/sites-available/000-default.conf
- เปลี่ยนบรรทัด /var/www/ เป็น /my web folder/ จำนวน 2 ตำแหน่ง
root@god:/# nano /etc/apache2/apache2.conf
- แก้ค่า AllowOverride ของ /my web folder/ จาก None เป็น AllowOverride All
Config PHP
nano /etc/php/7.0/apache2/php.ini
post_max_size=1024M upload_max_filesize = 1024M display_errors = On
Step 2 : Move mysql data folder to new location and config MySql
ย้ายข้อมูล mysql ไปไว้ที่ /folder/mysql
หมายเหตุ config file ของ mysql อยู่ที่ /etc/mysql/mysql.conf.d/mysqld.cnf
root@god:/# service mysql stop root@god:/# rsync -av /var/lib/mysql /folder root@god:/# mv /var/lib/mysql /var/lib/mysql.bak root@god:/# ln -s /folder/mysql /var/lib/mysql root@god:/# chown -h mysql:mysql /var/lib/mysql root@god:/# cp -r (/your/old/mysql/folder) /folder/mysql/ root@god:/# chown -R mysql:mysql /folder/mysql/*
Step 3 : Configuring AppArmor Access Control Rules
nano /etc/apparmor.d/tunables/alias
เปลี่ยนค่า
. . . alias /var/lib/mysql/ -> /folder/mysql/, . . .
หรือ
echo "alias /var/lib/mysql/ -> /folder/mysql/," >> /etc/apparmor.d/tunables/alias
Reload the apparmor profiles
root@god:/# /etc/init.d/apparmor reload root@god:/# /etc/init.d/apparmor restart
Restart mysql
root@god:/# systemctl start mysql
Step 4 : เปลี่ยน default engine เป็น MYISAM โดยเพิ่มข้อความด้านล่างไว้ใต้ [mysqld]
nano /etc/mysql/mysql.conf.d/mysqld.cnf
sql_mode = '' default-storage-engine=MYISAM collation-server = utf8_unicode_ci character-set-server = utf8
แล้วคราวนี้ก็ทำการ copy ฐานข้อมูลเก่า ๆ มาได้เลย อย่าลืมเปลี่ยน owner/group เป็น mysql ด้วยนะ
Step 5 : ติดตั้ง ProFtpd
ตามอ่านได้ที่ Setup FTP Server under Ubuntu/Debian
ปล. ลองศึกษาการ config เพิ่มเติมได้จาก opensource.cc.psu.ac.th
Last edited : Aug 23,2016 14:12 PM
อ้างอิงจาก
- How To Move a MySQL Data Directory to a New Location on Ubuntu 16.04
- Moving MySQL datadir
- [Increasing the phpMyAdmin session timeout](http://www.joho.se/2011/11/07/increasing-the-phpmyadmin-session-timeout/]