โดยปกติแล้วชาวบ้านชาวช่องเขาจะใช้ console ล้อกอินเข้าไปสร้างเข้าไปแก้ vhost แต่ผมไม่ค่อยชอบวิธีนั้น รู้สึกว่ามันยากมันไม่ใช่ทาง ผมชอบใช้ filezilla ftp เข้าไปดึงไฟล์ลงมาแก้ที่เครื่องวินโดวผม ผมว่ามันง่ายกว่า
1.เปิด filezilla ขึ้นมา ไม่มีก็ไปหามาลง จากนั้นคลิกที่ปุ่มที่ผมทำเครื่องหมายเลข 1 ไว้แล้วคลิกปุ่ม New Site อีกดอก

2.ป้อนรายละเอียดต่างๆตามหมายเลข
1: ตั้งชื่ออะไรก็ได้ ให้วันหลังกลับมาใช้งานแล้วจำได้ว่าจะคอนเน็คไปที่ไหน
2: เลือกเป็น SFTP
3: ป้อนหมายเลข IP ของ droplet (ไปดูที่ droplet ครับมันจะแสดงไว้ชัดเจน)
4: ป้อน username สำหรับล้อกอินเข้า droplet ซึ่งก็คือ root
5: ป้อนรหัสผ่านสำหรับล้อกอินเข้า droplet ซึ่งก็คือรหัสผ่านของ root นั่นแหละ
6: คลิก Connect เพื่อเชื่อมต่อสิ รออะไร

3. มันจะขึ้นกล่องบอกอะไรสักอย่างก็ไม่รู้ขี้เกียจอ่าน ให้ติ๊กเครื่องหมายที่วงกลมไว้ตรงเลข 1 แล้วคลิกปุ่ม OK

4. ถ้ารหัสผ่านถูกต้องมันก็ควรเข้ามาที่หน้านี้แหละ

5.เข้าไปยังโฟลเดอร์ /var/www แล้วคลิกขวาสร้างโฟลเดอร์ชื่อ wordpressayothaya ขึ้นมา คือโฟลเดอร์นี้จะไว้สำหรับเก็บเว็บไซต์ wordpressayothaya.com และเหตุที่สร้างโฟลเดอร์ขึ้นมาใหม่ก็เพราะว่าต้องการแยกส่วนการจัดเก็บเว็บแต่ละเว็บให้ชัดเจน เผื่อในอนาคตต้องการมีเว็บเพิ่ม ก็มาสร้างโฟลเดอร์ใหม่ สร้าง vhost ใหม่
การเข้าไปยังโฟลเดอร์ที่ต้องการก็พิมพ์พาธเข้าไปในช่องที่วงแดงๆไว้ในภาพ

6.เข้าไปที่ /etc/apache2/sites-available/ แล้วคลิกขวาดาวน์โหลดไฟล์ 000-default.conf ลงมา

7.เปิดไฟล์ 000-default.conf ขึ้นมาด้วย editor ตัวไหนก็ได้ จากนั้นแก้ไขให้เป็นตามนี้
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/wordpressayothaya
ServerName wordpressayothaya.com
ServerAlias www.wordpressayothaya.com
<Directory /var/www/wordpressayothaya/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
</VirtualHost>
ตัวที่สำคัญคือ DocumentRoot, Directory ชี้ให้ถูกพาธนะครับ ชื่อโฟลด้งโฟลเดอร์อย่าให้ผิด
ServerName ด้วย ชื่อเว็บอย่าให้ผิด ตัวนี้ไม่ต้องใส่ www นำหน้า จะใส่ www นำหน้าต้องตัว ServerAlias โน่น
แก้เสร็จแล้วบันทึกมันเป็นชื่อใหม่ว่า wordpressayothaya.com.conf

8.อัปโหลด wordpressayothaya.com.conf ขึ้นไปไว้ที่เดียวกับ 000-default.conf

9.ถึงตอนนี้เราหลีกเลี่ยงการใช้งาน console ไม่ได้แล้วเพราะว่าเราต้องใช้คำสั่ง linux เพื่อสั่งให้ไฟล์ config เมื่อกี้ทำงาน เปิด console ขึ้นมา ล้อกอินให้เรียบร้อยแล้วพิมพ์คำสั่งด้านล่าง แล้วกด enter ป้าบเข้าให้
sudo a2ensite wordpressayothaya.com.conf

10.จากนั้น restart apache ไปทีนึง พิมพ์คำสั่งด้านล่างแล้วกด enter
systemctl restart apache2

virtual host ของเราเสร็จเรียบร้อยแล้ว พร้อมรอติดตั้งเวิร์ดเพรส
Leave a Reply