การติดต้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

§ การตดติ งั้ WebServer โดยใช ้ FreeBSD 8.2 § กรณีศกษาึ www.mu-ph.org

โดย เสรมพิ นธั ุ ์ นตยิ นรา์ Email: [email protected] 1 เมษายน 2554 [** Rev01 : Apr 01,2011 **] * * * * * * * * * Objective: ต้องการทาํ WebServer ของ องค์กร ให้ทุกฝ่ ายในองค์กรม ี WebSite ใช้งาน โดยให้เนือท้ ฝี่ ่ ายละ 1 GBytes

Specifications ของเครื่องที่ใช้ www# dmesg Copyright (c) 1992-2011 The FreeBSD Project. Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994 The Regents of the University of California. All rights reserved. FreeBSD is a registered trademark of The FreeBSD Foundation. FreeBSD 8.2-RELEASE #0: Fri Feb 18 02:24:46 UTC 2011 [email protected]:/usr/obj/usr/src/sys/GENERIC i386 Timecounter "i8254" frequency 1193182 Hz quality 0 CPU: Intel(R) Xeon(TM) CPU 2.40GHz (2392.06-MHz 686-class CPU) Origin = "GenuineIntel" Id = 0xf29 Family = f Model = 2 Stepping = 9

Features=0xbfebfbff Features2=0x4400 real memory = 1073741824 (1024 MB) avail memory = 1036226560 (988 MB) ACPI APIC Table: FreeBSD/SMP: Multiprocessor System Detected: 4 CPUs FreeBSD/SMP: 4 package(s) x 1 core(s) cpu0 (BSP): APIC ID: 0 cpu1 (AP): APIC ID: 1 cpu2 (AP): APIC ID: 6 cpu3 (AP): APIC ID: 7

แบ่ง partition ดังนี ้ www# df Filesystem 1K-blocks Used Avail Capacity Mounted on /dev/amrd0s1a 1012974 176512 755426 19% / devfs 1 1 0 100% /dev /dev/amrd0s1h 63488502 4 58409418 0% /backups /dev/amrd0s1g 1012974 12 931926 0% /tmp /dev/amrd0s1e 5077038 832996 3837880 18% /usr /dev/amrd0s1f 50777034 4 46714868 0% /usr/local/www /dev/amrd0s1d 15231278 278 14012498 0% /var www#

โปรแกรมทลงี่ 1. แก้ไขแฟ้มที่จําเป็น 2. Compile Kernel เพื่อให้รองรับ Firewall และ Quota 3. Update ports tree 4. การติดตั้ง Firewall 5. การทํา Quota 6. ติดตั้ง mysql55-server 7. ติดตั้ง Apache22

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิตยนรา์ Page 1 การติดต้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

8. ติดตั้ง PHP52 9. ติดตั้ง PHP52-extensions 10. ติดตั้ง ZendOptimizer 11. ติดตั้ง webmin 12. ติดตั้ง phpmyadmin 13. ติดตั้ง vsftp 14. ติดตั้ง awstats 15. ติดตั้ง ntp 16. ติดตั้ง clamav 17. ติดตั้ง lynx 18. ติดตั้ง denyhosts 19. ติดตั้ง zip & unzip 20. การ Backup เวบ

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิตยนรา์ Page 2 การติดต้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

ลําดบทั ี่ 1). แก้ไขแฟ้มทจี่ ําเป็น

ในการตดติ งสามารถศั้ กษาไดึ จาก้ http://bsd.psru.ac.th/microcom/micro240/install53_1.pdf http://bsd.psru.ac.th/microcom/micro240/install53_2.pdf

เมอตื่ ดติ งั้ FreeBSD 8.1 เรยบรี อยแล้ ว้ เราก็ทําการแกไขแฟ้ ้ มทจี่ ําเป็ นเบองตื้ น้ ทําไดโดย้ login as: sermpan Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994 The Regents of the University of California. All rights reserved.

FreeBSD 8.2-RELEASE (GENERIC) #0: Fri Feb 18 02:24:46 UTC 2011

Welcome to FreeBSD!

Before seeking technical support, please use the following resources: o Security advisories and updated errata information for all releases are at http://www.FreeBSD.org/releases/ - always consult the ERRATA section for your release first as it's updated frequently. o The Handbook and FAQ documents are at http://www.FreeBSD.org/ and, along with the mailing lists, can be searched by going to http://www.FreeBSD.org/search/. If the doc distribution has been installed, they're also available formatted in /usr/share/doc.

If you still have a question or problem, please take the output of `uname -a', along with any relevant error messages, and email it as a question to the [email protected] mailing list. If you are unfamiliar with FreeBSD's directory layout, please refer to the hier(7) manual page. If you are not familiar with manual pages, type `man man'.

You may also use sysinstall(8) to re-enter the installation and configuration utility. Edit /etc/motd to change this login announcement.

$ su Password:

เรมดิ่ วยแก้ แฟ้ ้ม /etc/motd ลบทไมี่ จ่ ําเป็ นออก เหลอเพื ยงี 4 บรรทัดขางล้ าง่ แลว้ save www# vi /etc/motd FreeBSD 8.2-RELEASE (GENERIC) #0: Fri Feb 18 02:24:46 UTC 2011

Welcome to FreeBSD!

ลําดับตอไปแก่ แฟ้ ้ม Welcome ใหลดการ้ Delay จาก 10 วนาทิ ี เหลอื 3 วนาทิ ี www# vi /boot/defaults/loader.conf

############################################################## ### Loader settings ######################################## ##############################################################

#autoboot_delay="10" # Delay in seconds before autobooting, autoboot_delay="3" # Delay in seconds before autobooting,

และแกแฟ้ ้ม sshd_config เพออนื่ ุญาตให ้ User ชอื่ sermpan สามารถทจะี่ Secure Shell ไดแต้ เพ่ ยงผี เดู ้ ยวี www# vi /etc/ssh/sshd_config # Authentication:

AllowUsers sermpan

#LoginGraceTime 2m #PermitRootLogin no #StrictModes yes #MaxAuthTries 6 #MaxSessions 10 Save แลวส้ ง่ั Reload www# /etc/rc.d/sshd reload www#

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิตยนรา์ Page 3 การติดต้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

ลําดบทั ี่ 2). Compile Kernel เพื่อให้รองรับ Firewall และ Quota www# cd /usr/src/sys/i386/conf/ www# cp GENERIC MU-PH www# vi MU-PH ; ใหได้ เป้ ็ นดังน ี้ (เพมใสิ่ ส่ วนท่ เปี่ ็ นพนสื้ แดงี ) www# cat MU-PH # # GENERIC -- Generic kernel configuration file for FreeBSD/i386 # # For more information on this file, please read the handbook section on # Kernel Configuration Files: # # http://www.FreeBSD.org/doc/en_US.ISO8859-1/books/handbook/kernelconfig-config.html # # The handbook is also available locally in /usr/share/doc/handbook # if you've installed the doc distribution, otherwise always see the # FreeBSD World Wide Web server (http://www.FreeBSD.org/) for the # latest information. # # An exhaustive list of options and more detailed explanations of the # device lines is also present in the ../../conf/NOTES and NOTES files. # If you are in doubt as to the purpose or necessity of a line, check first # in NOTES. # # $FreeBSD: src/sys/i386/conf/GENERIC,v 1.474.2.15.2.1 2008/11/25 02:59:29 kensmith Exp $ cpu I486_CPU cpu I586_CPU cpu I686_CPU #ident GENERIC ident MU-PH

# To statically compile in device wiring instead of /boot/device.hints #hints "GENERIC.hints" # Default places to look for devices.

# Use the following to compile in values accessible to the kernel # through getenv() (or kenv(1) in userland). The format of the file # is 'variable=value', see kenv(1) # # env "GENERIC.env" makeoptions DEBUG=-g # Build kernel with gdb(1) debug symbols options SCHED_ULE # ULE scheduler options PREEMPTION # Enable kernel thread preemption options INET # InterNETworking options INET6 # IPv6 communications protocols options SCTP # Stream Control Transmission Protocol options FFS # Berkeley Fast Filesystem options SOFTUPDATES # Enable FFS soft updates support options UFS_ACL # Support for access control lists options UFS_DIRHASH # Improve performance on big directories options UFS_GJOURNAL # Enable gjournal-based UFS journaling options MD_ROOT # MD is a potential root device options NFSCLIENT # Network Filesystem Client options NFSSERVER # Network Filesystem Server options NFSLOCKD # Network Lock Manager options NFS_ROOT # NFS usable as /, requires NFSCLIENT options MSDOSFS # MSDOS Filesystem options CD9660 # ISO 9660 Filesystem options PROCFS # Process filesystem (requires PSEUDOFS) options PSEUDOFS # Pseudo-filesystem framework options GEOM_PART_GPT # GUID Partition Tables. options GEOM_LABEL # Provides labelization options COMPAT_43TTY # BSD 4.3 TTY compat (sgtty) options COMPAT_FREEBSD4 # Compatible with FreeBSD4 options COMPAT_FREEBSD5 # Compatible with FreeBSD5 options COMPAT_FREEBSD6 # Compatible with FreeBSD6 options COMPAT_FREEBSD7 # Compatible with FreeBSD7 options SCSI_DELAY=5000 # Delay (in ms) before probing SCSI options KTRACE # ktrace(1) support options STACK # stack(9) support options SYSVSHM # SYSV-style shared memory options SYSVMSG # SYSV-style message queues options SYSVSEM # SYSV-style semaphores options P1003_1B_SEMAPHORES # POSIX-style semaphores options _KPOSIX_PRIORITY_SCHEDULING # POSIX P1003_1B real-time extensions options PRINTF_BUFR_SIZE=128 # Prevent printf output being interspersed. options KBD_INSTALL_CDEV # install a CDEV entry in /dev options HWPMC_HOOKS # Necessary kernel hooks for hwpmc(4) options AUDIT # Security event auditing options MAC # TrustedBSD MAC Framework options FLOWTABLE # per-cpu routing cache การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิตยนรา์ Page 4 การติดต้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

#options KDTRACE_HOOKS # Kernel DTrace hooks options INCLUDE_CONFIG_FILE # Include this file in kernel options KDB # Kernel debugger related code options KDB_TRACE # Print a stack trace for a panic # # Add Firewall & Quota to kernel # options IPFIREWALL options IPFIREWALL_FORWARD options IPFIREWALL_DEFAULT_TO_ACCEPT options IPFIREWALL_VERBOSE options IPFIREWALL_VERBOSE_LIMIT=120 options IPDIVERT options QUOTA # # End of Additional Line # ......

www# pwd /usr/src/sys/i386/conf www# ll -rw-r--r-- 1 root wheel 13 Jun 20 2005 .cvsignore -rw-r--r-- 1 root wheel 598 Dec 22 00:09 DEFAULTS -rw-r--r-- 1 root wheel 13322 Dec 22 00:09 GENERIC -rw-r--r-- 1 root wheel 878 Dec 22 00:09 GENERIC.hints -rw-r--r-- 1 root wheel 13638 Apr 1 13:27 MU-PH -rw-r--r-- 1 root wheel 148 Dec 22 00:09 Makefile -rw-r--r-- 1 root wheel 31788 Dec 22 00:09 NOTES -rw-r--r-- 1 root wheel 1646 Dec 22 00:09 PAE -rw-r--r-- 1 root wheel 3487 Dec 22 00:09 XBOX -rw-r--r-- 1 root wheel 3238 Dec 22 00:09 XEN www# config MU-PH Kernel build directory is ../compile/MU-PH Don't forget to do ``make cleandepend && make depend'' www# cd ../compile/MU-PH www# make depend ; make ; make install . . . ===> zfs (install) install -o root -g wheel -m 555 zfs.ko /boot/kernel install -o root -g wheel -m 555 zfs.ko.symbols /boot/kernel ===> zlib (install) install -o root -g wheel -m 555 zlib.ko /boot/kernel install -o root -g wheel -m 555 zlib.ko.symbols /boot/kernel kldxref /boot/kernel www#

รอจนกระทงท่ั ํางานเสร็จ สง่ั Reboot www# reboot

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิตยนรา์ Page 5 การติดต้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

ลําดบทั ี่ 3). Update ports tree

เนองจากเครื่ องื่ Server ทลงอยี่ หลู่ ัง proxy และพบปัญหาเกยวกี่ บการั update ports ดวย้ cvsup จงไดึ ใช้ ว้ ธิ การี portsnap โดย login as: sermpan Using keyboard-interactive authentication. Password: Last login: Fri Apr 1 13:21:14 2011 from proxy.mu-ph.org Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994 The Regents of the University of California. All rights reserved.

FreeBSD 8.2-RELEASE (MU-PH) #0: Fri Apr 1 13:44:08 ICT 2011

Welcome to FreeBSD! $ su Password: www# cd / www# portsnap fetch Looking up portsnap.FreeBSD.org mirrors... 5 mirrors found. Fetching public key from portsnap5.FreeBSD.org... done. Fetching snapshot tag from portsnap5.FreeBSD.org... done. Fetching snapshot metadata... done. Fetching snapshot generated at Fri Apr 1 07:04:33 ICT 2011: 6946b3eb18578a0cf2278c7ab4a1985c9a2e7e74861a3c100% of 64 MB 99 kBps 00m00s Extracting snapshot... done. Verifying snapshot integrity... done. Fetching snapshot tag from portsnap5.FreeBSD.org... done. Fetching snapshot metadata... done. Updating from Fri Apr 1 07:04:33 ICT 2011 to Fri Apr 1 14:09:58 ICT 2011. Fetching 3 metadata patches.. done. Applying metadata patches... done. Fetching 0 metadata files... done. Fetching 10 patches.....10 done. Applying patches... done. Fetching 0 new ports or files... done. www# portsnap extract . . /usr/ports/x11/yelp/ /usr/ports/x11/zenity/ Building new INDEX files... done. www# portsnap update Ports tree is already up to date.

จากนนเรากั้ ็แตก Distfiles82.tar ทเคยลงมาใสี่ ไว่ ใน้ /usr/ports/distfiles และ tar เก็บ port ทไดี่ เอาไว้ เผ้ อการลงในคราวตื่ อๆไป่ www# cd / www# tar xpf /backups/Distfiles82.tar www#

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิตยนรา์ Page 6 การติดต้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

ลําดบทั ี่ 4). การติดตั้ง Firewall

เมื่อเราได้ Compile kernel เพอรองรื่ ับ Firewall และ Quota แล้ว ในลาดํ บตั ่อไปกเป็ ็นเรื่องของการทํา Firewall

Step # 1: Enabling IPFW

Open /etc/rc.conf file เพ่ิมสองบรรทดขั างล้ ่างเขาไป้ firewall_enable="YES" firewall_script="/backups/ipfw.rules"

Step # 2 Write a Firewall Rule Script www# vi /backups/ipfw.rules โดยมรายละเอี ยดดี ังน ี้

IPF="ipfw -q add" ipfw -q -f flush

#loopback $IPF 10 allow all from any to any via em0 $IPF 20 deny all from any to 127.0.0.0/8 $IPF 30 deny all from 127.0.0.0/8 to any $IPF 40 deny tcp from any to any frag

# statefull $IPF 50 check-state $IPF 60 allow tcp from any to any established $IPF 70 allow all from any to any out keep-state $IPF 80 allow icmp from any to any

# open port ftp (20,21), ssh (22), mail (25) # http (80), dns (53) etc

# ftp-data port=20 #$IPF 90 allow tcp from any to any 20 in #$IPF 100 allow tcp from any to any 20 out

# ftp port=21 $IPF 110 allow tcp from any to any 21 in $IPF 120 allow tcp from any to any 21 out

# ssh port=22 $IPF 130 allow tcp from any to any 22 in $IPF 140 allow tcp from any to any 22 out

# telnet port=23 #$IPF 150 allow tcp from any to any 23 in #$IPF 160 allow tcp from any to any 23 out

# smtp port=25 #$IPF 170 allow tcp from any to any 25 in #$IPF 180 allow tcp from any to any 25 out

# nameserver port=42 #$IPF 190 allow tcp from any to any 42 in #$IPF 200 allow tcp from any to any 42 out

# domain port=53 #$IPF 210 allow udp from any to any 53 in #$IPF 220 allow udp from any to any 53 out

# tftp port=69 #$IPF 230 allow tcp from any to any 69 in #$IPF 240 allow tcp from any to any 69 out

# finger port=79 #$IPF 250 allow tcp from any to any 79 in #$IPF 260 allow tcp from any to any 79 out

# http port=80 $IPF 270 allow tcp from any to any 80 in $IPF 280 allow tcp from any to any 80 out

# pop3 port=110 #$IPF 290 allow tcp from any to any 110 in

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิตยนรา์ Page 7 การติดต้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

#$IPF 300 allow tcp from any to any 110 out

# webmin port=10000 $IPF 310 allow tcp from any to any 10000 in $IPF 320 allow tcp from any to any 10000 out

# deny and log everything $IPF 500 deny log all from any to any

Step # 3: Start a firewall

You can reboot the box or you could reload these rules by entering on the command line. www# sh /backups/ipfw.rules

Task: List all the rules in sequence

Type the following command: www# ipfw list 00010 allow ip from any to any via em0 00020 deny ip from any to 127.0.0.0/8 00030 deny ip from 127.0.0.0/8 to any 00040 deny tcp from any to any frag 00050 check-state 00060 allow tcp from any to any established 00070 allow ip from any to any out keep-state 00080 allow icmp from any to any 00110 allow tcp from any to any dst-port 21 in 00120 allow tcp from any to any dst-port 21 out 00130 allow tcp from any to any dst-port 22 in 00140 allow tcp from any to any dst-port 22 out 00270 allow tcp from any to any dst-port 80 in 00280 allow tcp from any to any dst-port 80 out 00310 allow tcp from any to any dst-port 10000 in 00320 allow tcp from any to any dst-port 10000 out 00500 deny log logamount 120 ip from any to any 65535 allow ip from any to any www#

ด ู em0 ใหด้ ี คานํ เอามาจากี้ การใชค้ าสํ ง่ั ifconfig เป็ นชอของื่ LanCard

และในทํานองเดยวกี นถั าเรา้ Copy แฟ้ ม rc.conf จากเครองอื่ นมาใชื่ ้ ใหด้ คู าคํ านํ ดี้ วย้

ในลําดบตั อไปเป่ ็ นการทํา quota

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิตยนรา์ Page 8 การติดต้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

ลําดบทั ี่ 5). การทํา Quota

เพื่อเป็นการควบคุมใหแต้ ่ละฝ่ายในองคกรม์ ีพ้ืนที่ในการนาเสนอเวบหนํ ่วยงานละ 1024 Mbytes www# cd /etc/ www# vi fstab

แกท้ บรรที่ ดั /usr/local เพมิ่ ,userquota,groupquota หลงคั าวํ า่ rw www# cat fstab # Device Mountpoint FStype Options Dump Pass# /dev/amrd0s1b none swap sw 0 0 /dev/amrd0s1a / ufs rw 1 1 /dev/amrd0s1h /backups ufs rw 2 2 /dev/amrd0s1g /tmp ufs rw 2 2 /dev/amrd0s1e /usr ufs rw 2 2 /dev/amrd0s1f /usr/local/www ufs rw,userquota,groupquota 2 2 /dev/amrd0s1d /var ufs rw 2 2 /dev/acd0 /cdrom cd9660 ro,noauto 0 0 www#

ทแฟี่ ้ ม /etc/rc.conf เพมสองบรรทิ่ ดขั างล้ างเข่ าไป้ enable_quotas="YES" check_quotas="YES"

สง่ั Reboot www# reboot

เมอเครื่ องื่ boot ขนมาึ้ ใหส้ งเพั่ อใหื่ ้ Disk Quota มผลตี อการท่ ํางานทันท ี login as: sermpan Using keyboard-interactive authentication. Password: Last login: Fri Apr 1 14:16:45 2011 from proxy.mu-ph.org Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994 The Regents of the University of California. All rights reserved.

FreeBSD 8.2-RELEASE (MU-PH) #0: Fri Apr 1 13:44:08 ICT 2011

Welcome to FreeBSD!

$ su Password: www# quotacheck -a www# quotaon -a www#

เพมิ่ group ชอื่ webmaster เขาไปในระบบ้ โดย www# pw groupadd webmaster

เพมิ่ user เขาไปในระบบ้ 1 คน ในทนี่ ี้ คอื webmaster www# adduser Username: webmaster Full name: Uid (Leave empty for default): Login group [webmaster]: Login group is webmaster. Invite webmaster into other groups? []: Login class [default]: Shell (sh csh tcsh nologin) [sh]: nologin Home directory [/home/webmaster]: /usr/local/www Home directory permissions (Leave empty for default): Use password-based authentication? [yes]: Use an empty password? (yes/no) [no]: Use a random password? (yes/no) [no]: Enter password: Enter password again: Lock out the account after creation? [no]: Username : webmaster Password : ***** Full Name : Uid : 1003 Class : Groups : webmaster

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิตยนรา์ Page 9 การติดต้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

Home : /usr/local/www Home Mode : Shell : /usr/sbin/nologin Locked : no OK? (yes/no): yes adduser: INFO: Successfully added (webmaster) to the user database. Add another user? (yes/no): no Goodbye! www# quota -v webmaster Disk quotas for user webmaster (uid 1003): Filesystem usage quota limit grace files quota limit grace /usr/local 18 0 0 9 0 0 www# edquota -u webmaster Quotas for user webmaster: /usr/local/www: kbytes in use: 18, limits (soft = 1000, hard = 1024) inodes in use: 9, limits (soft = 0, hard = 0) www#

ตัง้ SoftQuota = 1000 Bytes และ HardQuota = 1024 Bytes www# quota -v webmaster Disk quotas for user webmaster (uid 1003): Filesystem usage quota limit grace files quota limit grace /usr/local/www 18 1000 1024 9 0 0 www#

ตัง้ grace period เอาแค ่ 7 วันโดย www# edquota -t Time units may be: days, hours, minutes, or seconds Grace period before enforcing soft limits for users: /usr/local/www: block grace period: 7 days, file grace period: 7 days

ให ้ Quota น ี้ แก ่ User คนอนๆดื่ วยโดย้ www# edquota -p webmaster `awk -F: '$3 > 1003 {print $1}' /etc/passwd` www#

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิตยนรา์ Page 10 การติดติ ้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

ลําดบทัั ี่ 6.) ติดตั้ง mysql55-server

เพื่อเป็็นการติดต้งั dattabase ไวใช้ ง้ าน

www# cd /usr/ports/databases/mysql55-server www# make config

1. และเมอถื่ กถามวู า่ เรองื่ mysql-server 5.5.10

===> No options to configure www# make WITH_CHARSET=tis620 WITH_XCHARSET=all WITH_COLLATION=tis620_thai_ci WITH_OPENSSL=yes BUILD_OPTIMIZED=yes WITH_ARCHIVE=yes WITH_FEDERATED=yes WITH_NDB=yes WITH_COMPAT=yes install clean

(บรรทัดทสองของี่ www# make with อยในบรรทู่ ัดเดยวกี ัน)

===> Vulnerability check disabled, database not found ===> License check disabled, port has not defined LICENSE ===> Found saved configuration for mysql-server-5.5.10 => mysql-5.5.10.tar.gz doesn't seem to exist in /usr/ports/distfiles/. => Attempting to fetch ftp://ftp.fi.muni.cz/pub/mysql/Downloads/MySQL-5.5/mysql-5..5.10.tar.gz mysql-5.5.10.tar.gz 3% of 22 MB 97 kBps 04m09s . .

1. เมอถื่ กถามวู า่ เรอื่ ง mysql-client 5.5.10

. . ************************************************************************

Remember to runn mysql_upgrade (with the optional --datadir= flag) the first time you start the MySQL server after an upgrade from an earlier versionn.

************************************************************************ install-info --quiet /usr/local/info/mysql.info /usr/local/info/dir ===> Installing rc.d startup script(s) ===> Compressing manual pages for mysql-server-5.5.10 ===> Registerring installation for mysql-server-5.5.10 ===> SECURITY REPORT: This port has installed the following files which may act as network servers and may therefore pose a remote security risk to the system. /usr/local/libexec/mysqld

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิิตยนรา์ Page 11 การติดต้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

This port has installed the following startup scripts which may cause these network services to be started at boot time. /usr/local/etc/rc.d/mysql-server

If there are vulnerabilities in these programs there may be a security risk to the system. FreeBSD makes no guarantee about the security of ports included in the Ports Collection. Please type 'make deinstall' to deinstall the port if this is a concern.

For more information, and contact details about the security status of this software, see the following webpage: http://www.mysql.com/ ===> Cleaning for cmake-2.8.4 ===> Cleaning for mysql-client-5.5.10 ===> Cleaning for mysql-server-5.5.10 www#

ให ้ mysql ทํางานทกครุ ังเม้ อเปื่ ิดเครองื่ www# vi /etc/rc.conf

เพมบรรทิ่ ัดตอไปน่ เขี้ าไป้

mysql_enable="YES"

save และออกจาก vi จากนันก้ ็ reboot เครองื่ www# reboot

เมอเราื่ reboot เครองแลื่ ว้ ก็ login เขาระบบ้ สงแรกทิ่ ตี่ องท้ ําคอื ให ้ password สําหรับการ login เพอเขื่ า้ database โดย www# /usr/local/bin/mysqladmin -u root password ssssssss www# mysql -u root mysql -p Enter password: Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.10 Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> status ------mysql Ver 14.14 Distrib 5.5.10, for FreeBSD8.1 (i386) using 5.2

Connection id: 2 Current database: mysql Current user: root@localhost SSL: Not in use Current pager: more Using outfile: '' Using delimiter: ; Server version: 5.5.10 Source distribution Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: latin1 Db characterset: latin1 Client characterset: latin1 Conn. characterset: latin1 UNIX socket: /tmp/mysql.sock Uptime: 55 sec

Threads: 1 Questions: 34 Slow queries: 0 Opens: 48 Flush tables: 1 Open tables: 41 Queries per second avg: 0.618 ------mysql> \q Bye www#

เป็ นอันวา่ เราสามารถใชงาน้ mysql ไดแล้ ว้ ลําดับตอไปเป่ ็ นการตดติ ัง้ apache22

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิตยนรา์ Page 12 การติดติ ้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

ลําดบทัั ี่ 7.) ติดตั้ง Apache22 www# cd /usr/ports/www/apache22 www# make config

1. และเมอถื่ กถามวู า่ เรองื่ apache 2. หนาต้ อไป่ เรองื่ appache

3. หนาต้ อไป่ เรองื่ apache 4. หนาต้ อไป่ เรองื่ appache

5. หนาต้ อไป่ เรองื่ apache 6. หนาต้ อไป่ เรองื่ appache

www# make instaall clean

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิิตยนรา์ Page 13 การติดติ ้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

1. เมอถื่ กถามเรู องื่ perl 2. เมอถื่ กถามเรู องื่ libiconv

3. เมอถื่ กถามเรู องื่ m4 4. เมอถื่ กถามเรู องื่ apr-ipv6-devrandom-gdbm-db42

5. เมอถื่ กถามเรู องื่ python27 6. เมอถื่ กถามเรู องื่ pth

. . รอซกั คร ู่ . .

To run apache www server from startup, add apache22_enable="YES" in your /etc/rcc.conf. Extra options can be found in startup script.

Your hostname must be resolvable using at least 1 mechanism in /etc/nsswitch typically DNS or /etc/hosts or apache might have issues staarting depending on the modules you are using. ===> Installing rc.d startup script(s) ===> Compressing manual pages for apache-2.2.177_2 ===> Registerring installation for apache-2.2.177_2 ===> SECURITY REPORT: This port has installed the following files which may act as network servers and may therefore pose a remote security risk to the system. /usr/local/libexec/apache22/mod_cgid.so

This port has installed the following startup scripts which may cause these network services to be started at boot time. /usr/local/etc/rc.d/apache22 /usr/local/etc/rc.d/htcacheclean

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิิตยนรา์ Page 14 การติดติ ้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

If there are vulnerabilities in these programs there may be a security risk to the system. FreeBSD makes no guarantee about the security of ports inccluded in the Ports Collection. Please type 'make deinstall' to deinstall the port if this is a concern.

For more information, and contact details about the security status off this software, see the following webpage: http://httpd.appache.org/ ===> Cleaning for perl-threaded-5.10.1_3 ===> Cleaning for autoconf-2.68 ===> Cleaning for libtool-2.4 ===> Cleaning for expat-2.0.1_1 ===> Cleaning for apr-devrandom-gdbm-db42-ldap24-mysql55-1.4.2.1.3.10 ===> Cleaning for pcre-8.12 ===> Cleaning for libiconv-1.13.1_1 ===> Cleaning for gdbm-1.8.3_3 ===> Cleaning for m4-1.4.16,1 ===> Cleaning for help2man-1.39.2 ===> Cleaning for gmake-3.81_4 ===> Cleaning for autoconf-wrapper-20101119 ===> Cleaning for python27-2.7.1_1 ===> Cleaning for automake-1.11.1 ===> Cleaning for openldap-client-2.4.25_1 ===> Cleaning for db42-4.2.52_5 ===> Cleaning for libsigsegv-2.9 ===> Cleaning for p5-Locale-gettext-1.05_3 ===> Cleaning for gettext-0.18.1.1 ===> Cleaning for pth-2.0.7 ===> Cleaning for automake-wrapper-20101119 ===> Cleaning for apache-2.2.17_2 www#

ให ้ apache ทํางานทกครุ ังเม้ อเปื่ ิดเครองื่ www# vi /etc/rcc.conf

เพมิ่ บรรทัดตอไปน่ เขี้ า้้ ไป apache22_enable="YES" save และออกจาก vi

แกไ้ ขรายละเอยดบางี ตััวในแฟ้ม httpd.conf www# vi /usr/local/etc/apache22/httpd.conf

ServerAdmin [email protected]

ServerName www.ph.mahidol.ac.th:80 save และออกจาก vi แลวส้ งั่ start www# /usr/local/etc/rc.d/apache22 start Performing sanity check on apache22 configuration: Syntax OK Starting apache22. แลว้ ลองเขาเวบด้ ทู ี่ http://www.mu-ph.org/

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิิตยนรา์ Page 15 การติดติ ้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

ลําดบทั ี่ 8.) ติดตั้ง PHP52 www# cd /usr/ports/lang/php52 www# make config

1. เมอถื่ กถามเรู องื่ php52

www# make instaall clean

===> Vulnerability check disabled, database not found ===> License check disabled, port has not defined LICENSE ===> Found saved configuration for php52-5.2.17 => php-5.2.17.tar.bz2 doesn't seem to exist in /usr/ports/distfiles/. => Attempting to fetch http://dk.php.net/distributions/php-5.2.17.tar.bz2 php-5.2.17.tar.bz2 18% of 8879 kB 47 kBps 02m33s. รอซกั คร ู่ . ***************************************************************

Make sure index.php is part of your DirectoryIndex.

You should add the following to your Apache configuration file:

AddType applicaation/x-httpd-php .php AddType applicaation/x-httpd-php-source .phps

*************************************************************** ===> Installing rc.d startup script(s) ===> Compressing manual pages for php52-5.2.17 ===> Registerring installation for php52-5.2.17 ===> SECURITY REPORT: This port has installed the following files which may act as network servers and may therefore pose a remote security risk to the system. /usr/local/libexec/apache22/libphp5.so /usr/local/bin/php /usr/local/bin/php-cgi

This port has installed the following startup scripts which may cause these network services to be started at boot time. /usr/local/etc/rc.d/php-fpm

If there are vulnerabilities in these programs there may be a security risk to the system. FreeBSD makes no guarantee about the security of ports inccluded in the Ports Collection. Please type 'make deinstall' to deinstall the port if this is a concern.

For more information, and contact details about the security status off this software, see the following webpage: http://www.php.net/ ===> Cleaning for pkg-config-0.25_1 ===> Cleaning for libevent-1.4.14b_2 ===> Cleaning for libxml2-2.7.8_1 ===> Cleaning for php52-5.2.17 www#

ในแฟ้ม httpd.conf ใหเพ้ มิ่ index.php ลงในบรรทัด DirectoryIndex

และเพม่ิ บรรทัดสแดงี ขางบน้ ลงในแฟ้ม httpd.conf ดวย้ (ตอท่ ายก้ ลมบรรทุ่ ัดของ AdddType ) save และออกจาก vi แลวส้ งั่ start

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิิตยนรา์ Page 16 การติดติ ้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

www# /usr/local/etc/rc.d/apache22 restart Performing sanity check on apache22 configuration: Syntax OK Stopping apache22. Waiting for PIDS: 1105. Performing sanity check on apache22 configuration: Syntax OK Starting apache22.

ตอนนระบบของเรากี้ี้ ็พรอมท้ จะทดสอบี่ php ไดโดย้ www# cd /usr/local/www/apache22/data www# echo "" > index.php

แลว้ ลองเขาเวบด้ ทู ี่ http://www.mu-ph.org/index.php

ในลําดับตอไปเป่ ็ นการตดติ ัง้ php5-extensions

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิิตยนรา์ Page 17 การติดติ ้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

ลําดบทัั ี่ 9.) ติดตั้ง PHP52-extensions www# cd /usr/ports/lang/php52-extensions www# make config

1. เมอถื่ กถามเรู องื่ php52-extensions 2. เมอถื่ กถามเรู องื่ php52-extensions (ตอ่ )

3. เมอถื่ กถามเรู องื่ php52-extensions (ตอ่ ) 4. เมอถื่ กถามเรู องื่ php52-extensions (ตอ่ )

5. เมอถื่ กถามเรู องื่ php52-extensions (ตอ่ )

www# make instaall clean

แลว้ ก็รออกเชี นเคย่ ...

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิิตยนรา์ Page 18 การติดติ ้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

1. เมอถื่ กถามเรู องื่ curl 2. เมอถื่ กถามเรู องื่ c-ares-config

3. เมอถื่ กถามเรู องื่ libssh2 4. เมอถื่ กถามเรู องื่ ca_root_nss

5. เมอถื่ กถามเรู องื่ php52-pcre 6. เมอถื่ กถามเรู องื่ php52-gd

7. เมอถื่ กถามเรู องื่ libxslt 8. เมอถื่ กถามเรู องื่ png

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิิตยนรา์ Page 19 การติดติ ้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

9. เมอถื่ กถามเรู องื่ gmp 10. เมอถื่ กถามเรู องื่ php52-mbstring

11. เมอถื่ กถามเรู องื่ net-snmp 12. เมอถื่ กถามเรู องื่ php52-sqlite

===> Generating temporary packing list ===> Checking if lang/php52-extensions already installed ===> Registering installation for php52-extensions-1.3_1 ===> Cleaning for php52-bcmath-5.2.17 ===> Cleaning for php52-bz2-5.2.17 ===> Cleaning for php52-calendar-5.2.17 ===> Cleaning for php52-ctype-5.2.17 ===> Cleaning for php52-curl-5.2.17 ===> Cleaning for php52-dom-5.2.17 ===> Cleaning for php52-exif-5.2.17 ===> Cleaning for pecl-fileinfo-1.0.4 ===> Cleaning for php52-filter-5.2.17 ===> Cleaning for php52-ftp-5.2.17 ===> Cleaning for php52-gd-5.2.17 ===> Cleaning for php52-gettext-5.2.17 ===> Cleaning for php52-gmp-5.2.17 ===> Cleaning for php52-hash-5.2.17 ===> Cleaning for php52-iconv-5.2.17 ===> Cleaning for php52-json-5.2.17 ===> Cleaning for php52-mbstring-5.2.17 ===> Cleaning for php52-mcrypt-5.2.17 ===> Cleaning for php52-mhash-5.2.17 ===> Cleaning for php52-mysql-5.2.17 ===> Cleaning for php52-ncurses-5.2.17 ===> Cleaning for php52-openssl-5.2.17 ===> Cleaning for php52-pcntl-5.2.17 ===> Cleaning for php52-pcre-5.2.17 ===> Cleaning for pecl-pdflib-2.1.8 ===> Cleaning for php52-pdo-5.2.17 ===> Cleaning for php52-pdo_sqlite-5.2.17 ===> Cleaning for php52-pdo_mysql-5.2.17 ===> Cleaning for php52-posix-5.2.17 ===> Cleaning for php52-pspell-5.2.17 ===> Cleaning for php52-readline-5.2.17 ===> Cleaning for php52-recode-5.2.17 ===> Cleaning for php52-session-5.2.17 ===> Cleaning for php52-shmop-5.2.17 ===> Cleaning for php52-simplexml-5.2.17 ===> Cleaning for php52-snmp-5.2.17 ===> Cleaning for php52-soap-5.2.17 ===> Cleaning for php52-sockets-5.2.17 ===> Cleaning for php52-spl-5.2.17 ===> Cleaning for php52-sqlite-5.2.17 ===> Cleaning for php52-tidy-5.2.17 การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิิตยนรา์ Page 20 การติดต้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

===> Cleaning for php52-tokenizer-5.2.17 ===> Cleaning for php52-xml-5.2.17 ===> Cleaning for php52-xmlreader-5.2.17 ===> Cleaning for php52-xmlwriter-5.2.17 ===> Cleaning for php52-zip-5.2.17 ===> Cleaning for php52-zlib-5.2.17 ===> Cleaning for curl-7.21.3_1 ===> Cleaning for libXpm-3.5.7 ===> Cleaning for freetype2-2.4.4 ===> Cleaning for png-1.4.5 ===> Cleaning for jpeg-8_3 ===> Cleaning for t1lib-5.1.2_1,1 ===> Cleaning for gmp-5.0.1 ===> Cleaning for libmcrypt-2.5.8 ===> Cleaning for libltdl-2.4 ===> Cleaning for mhash-0.9.9.9_1 ===> Cleaning for pdflib-7.0.4 ===> Cleaning for aspell-0.60.6_5 ===> Cleaning for recode-3.6_8 ===> Cleaning for net-snmp-5.5_4 ===> Cleaning for tidy-lib-090315.c_1 ===> Cleaning for c-ares-config-1.7.4 ===> Cleaning for libidn-1.19 ===> Cleaning for libssh2-1.2.7,2 ===> Cleaning for ca_root_nss-3.12.9 ===> Cleaning for xextproto-7.1.1 ===> Cleaning for xproto-7.0.16 ===> Cleaning for libX11-1.3.6,1 ===> Cleaning for libXext-1.1.2,1 ===> Cleaning for libXt-1.0.9 ===> Cleaning for libXaw-1.0.8,1 ===> Cleaning for dmalloc-5.5.2 ===> Cleaning for libxslt-1.1.26_2 ===> Cleaning for libxcb-1.7 ===> Cleaning for xorg-macros-1.11.0 ===> Cleaning for bigreqsproto-1.1.1 ===> Cleaning for xcmiscproto-1.2.0 ===> Cleaning for xtrans-1.2.5 ===> Cleaning for kbproto-1.0.5 ===> Cleaning for inputproto-2.0.1 ===> Cleaning for xf86bigfontproto-1.2.0 ===> Cleaning for libXau-1.0.6 ===> Cleaning for libXdmcp-1.0.3 ===> Cleaning for libSM-1.1.1_3,1 ===> Cleaning for printproto-1.0.4 ===> Cleaning for libXmu-1.1.0,1 ===> Cleaning for libXp-1.0.0,1 ===> Cleaning for libgcrypt-1.4.6 ===> Cleaning for libcheck-0.9.8 ===> Cleaning for xcb-proto-1.6 ===> Cleaning for libpthread-stubs-0.3_3 ===> Cleaning for libICE-1.0.7,1 ===> Cleaning for libgpg-error-1.10 ===> Cleaning for php52-extensions-1.3_1 www#

เมอตื่ ดติ ัง้ php5-extensions เสร็จแลวก้ ็มาถงขึ ันตอนการท้ ําให ้ Apache รจู ้ ักกบั PHP ใหเข้ าไปท้ ี่ /usr/local/etc/apache22/Includes www# cd /usr/local/etc/apache22/Includes

สรางไฟล้ ช์ อื่ php5.conf โดยใช ้ vi www# vi php5.conf

เพมบรรทิ่ ัดตอไปน่ เขี้ าไป้

DirectoryIndex index.php AddDefaultCharset tis-620 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps Include etc/apache22/extra/httpd-ssl.conf

save และออกจาก vi

สรางไฟล้ ์ php.ini www# cd /usr/local/etc/ www# cp php.ini-recommended php.ini

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิตยนรา์ Page 21 การติดติ ้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

กําหนดคาในไฟล่ ์ php.ini

default_charset = "tis-610" #เอาเรองหื่ มาย ; ออกดว้ ย session.save_path = "/tmp/sesstmp" #เอาเครองหมายื่ ; ออกดวยแล้ ะอยาล่ มไปสรื าง้ /tmp/sesstmp ใน /tmp พรอ้ มกบั chmod 777 /tmp/sesstmp ดวย้้

Generate Cert ใให ้ apache เพอใชื่ ร้ ัน HTTPS www# cd /usr/local/etc/apache22/ www# openssl genrsa -out server.key 1024 Generating RSA private key, 1024 bit long modulus ...... ++++++ ...... ++++++ e is 65537 (0x10001) www# openssl req -new -days 365 -key server.key -out server.csr You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:TH State or Province Name (full name) [Some-State]::Korat Locality Name (eg, city) []:sung-noen Organization Name (eg, company) [Internet Widgits Pty Ltd]:Rural Health Training & Research Center Organizational Unit Name (eg, section) []:Computer Division Common Name (eg, YOUR name) []:Computer Email Address []:[email protected]

Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []:mypasswd An optional company name []:MU-PH www# openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 365 Signature ok subject=/C=TH/ST=Korat/L=sung-noen/O=Rural Health Training & Research Center/OU=Computer Division/CN=Computer/[email protected] Getting Private key www# chmod 400 server.* www# ให ้ apache ทํางานทกครุ ังเม้ อเปื่ ิดเครองื่ www# vi /etc/rcc.conf

apache22_enable="YES"

save และออกจาก vi แลว้ reboot เครองื่ www# reboot

ตอนนระบบของเรากี้ พ็ รอมท้ จะทดสอี่ บ php ไดโดย้

เปิด browser แลว้ เขาไปท้ ี่ http://www.mu-ph.org/index.html

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิิตยนรา์ Page 22 การติดติ ้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

หรอื http://www.mu-ph.org/index.php

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิิตยนรา์ Page 23 การติดต้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

ลําดบทั ี่ 10). ติดตั้ง ZendOptimizer www# cd /usr/ports/devel/ZendOptimizer www# make config ===> No options to configure www# make install clean

===> Vulnerability check disabled, database not found ===> License check disabled, port has not defined LICENSE => ZendOptimizer-3.3.0a-freebsd6.0-i386.tar.gz doesn't seem to exist in /usr/ports/distfiles/. => Attempting to fetch from http://downloads.zend.com/optimizer/3.3.0a/. ZendOptimizer-3.3.0a-freebsd6.0-i386.tar.gz 9% of 9134 kB 90 kBps 01m31s . รอซกครั ู่ .

********************************************************************************

You have installed the ZendOptimizer package.

Edit /usr/local/etc/php.ini and add:

[Zend] zend_optimizer.optimization_level=15 zend_extension_manager.optimizer="/usr/local/lib/php/20060613/Optimizer" zend_extension_manager.optimizer_ts="/usr/local/lib/php/20060613/Optimizer_TS" zend_extension="/usr/local/lib/php/20060613/ZendExtensionManager.so" zend_extension_ts="/usr/local/lib/php/20060613/ZendExtensionManager_TS.so"

NOTE: PHP should be compiled in non-debug mode (default).

******************************************************************************** ===> Registering installation for ZendOptimizer-3.3.0.a ===> Cleaning for compat6x-i386-6.4.604000.200810_3 ===> Cleaning for ZendOptimizer-3.3.0.a www#

แกแฟ้ ้ม /usr/local/etc/php.ini โดยเพมบรรทิ่ ัดสแดงขี างบน้ หก บรรทัด ทที่ ายแฟ้ ้มเลย

จากนันเราก้ ็สงั่ restart apache www# /usr/local/etc/rc.d/apache22 restart Performing sanity check on apache22 configuration: Syntax OK Stopping apache22. Waiting for PIDS: 1613. Performing sanity check on apache22 configuration: Syntax OK Starting apache22. www#

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิตยนรา์ Page 24 การติดต้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

ลําดบทั ี่ 11.) ติดตั้ง webmin www# cd /usr/ports/sysutils/webmin/ www# make config ===> No options to configure www# make install clean

===> Vulnerability check disabled, database not found ===> License check disabled, port has not defined LICENSE => webmin-1.540.tar.gz doesn't seem to exist in /usr/ports/distfiles/. => Attempting to fetch http://heanet.dl.sourceforge.net/project/webadmin/webmin/1.540/webmin-1.540.tar.gz webmin-1.540.tar.gz 8% of 14 MB 173 kBps . รอซกครั ู่ . After installing Webmin for the first time you should perform the following steps as root:

* Configure Webmin by running /usr/local/lib/webmin/setup.sh

* Add webmin_enable="YES" to your /etc/rc.conf

* Start Webmin for the first time by running /usr/local/etc/rc.d/webmin start

The parameters requested by setup.sh may then be changed from within Webmin itself.

===> Installing rc.d startup script(s) ===> Registering installation for webmin-1.540 ===> Cleaning for p5-Net-SSLeay-1.36 ===> Cleaning for p5-Authen-PAM-0.16_1 ===> Cleaning for webmin-1.540 www#

จากนันเข้ าไป้ setup webmin ท ี่ www# /usr/local/lib/webmin/setup.sh

*********************************************************************** * Welcome to the Webmin setup script, version 1.540 * *********************************************************************** Webmin is a web-based interface that allows Unix-like operating systems and common Unix services to be easily administered.

Installing Webmin in /usr/local/lib/webmin ...

*********************************************************************** Webmin uses separate directories for configuration files and log files. Unless you want to run multiple versions of Webmin at the same time you can just accept the defaults.

Log file directory [/var/log/webmin]:

*********************************************************************** Webmin is written entirely in Perl. Please enter the full path to the Perl 5 interpreter on your system.

Full path to perl (default /usr/bin/perl):

Testing Perl ... Perl seems to be installed ok

*********************************************************************** name: FreeBSD Operating system version: 8.2

*********************************************************************** Webmin uses its own password protected web server to provide access to the administration programs. The setup script needs to know : - What port to run the web server on. There must not be another web server already using this port. - The login name required to access the web server. - The password required to access the web server. - If the webserver should use SSL (if your system supports it). - Whether to start webmin at boot time.

Web server port (default 10000): Login name (default admin): admin Login password: Password again: Use SSL (y/n): y ***********************************************************************

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิตยนรา์ Page 25 การติดติ ้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

Creating web server config files.. ..done

Creating access control file.. ..done

Creating start and stop scripts.. ..done

Copying config files.. ..done

Changing ownership and permissions .. ..done

Running postinstall scripts .. syslog-ng: not found ..done

Enabling backgrround status collection .. ..done

www#

จากนัันส้้ งั่ Start webmin โดย www# /usr/local/etc/rc.d/webmin start Starting webminn. Pre-loaded WebminCore www#

เขาเว้ บท ี่ port 10000 คอทื ี่ http://www.mu-ph.org:10000 จะปรากฎ error เนองจากเราื่ ระบวุ าจะเร่ ยกใชี ผ้ าน่ ssl

จงตึ อ้ งเรยกเปี ็ น https://www.mu-ph.org:10000 (ให ้ Click ท ี่ link ทหนี่ า้ เวบไดเลย้ )

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิิตยนรา์ Page 26 การติดติ ้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

เมอเื่ รา login เขาส้ รู่ ะบบ และ Click ท ี่ Server จะสงเกตั วุ าไม่ ม่ ี Apache WebServer

ทชี่ อ่ ง Search ใหใ้ สค่ ําวา่ apache ลงไป กดป่ มุ Enter จะพบ Appache 41 ท ี่ ใหเรา้ Click ที่ Column Module ตรงท ี่ Apache Webserver เพอดื่ ําเนนการติ อ่

เมอเื่ รา Click ท ี่ Apache Webserver จะปรากฏดงั ขางล้ าง่

ปัญหาคอื webmin ไมพบท่ อยี่ ของู่ httpd.conf ใหเรา้ Click ท ี่ module configuration (เป็ น Highlight สนี ํ้าเงนิ )เพอดื่ าํ เนนการติ อ่

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิิตยนรา์ Page 27 การติดติ ้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

โดยใหเราใส้ เลข่ 22 ทายค้ ําวา่ apache ลงไปใน /usr/local/etc/apache22 ทังหมดในเวบห้ นาน้ ี้ แลวส้ งั่ savve และเมอเรา่ืื refresh หนาจอ้ และ Click ท ี่ Server ก็จะปรากฎ Apache Webserver ตามตอง้ การ จากนัันเราก้้ ็สามารถทจี่ ะ config apache ผานทาง่ webmin ได ้ (แตไม่ แนะน่ ํา)

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิิตยนรา์ Page 28 การติดติ ้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

ลําดบทัั ี่ 12.) ติิดตั้ง phpmyadmin www# cd /usr/ports/databases/phpmyadmin/ www# make config

1. เมอถื่ กถามู เรองื่ phpMyAdmin

www# make instaall clean

. รอซกั คร ู่ . phpMyAdmin-3.3.10 has been installed into:

/usr/local/www/phpMyAdmin

Please edit connfig.inc.php to suit your needs.

To make phpMyAdmin available through your web site, I suggest that you add something like the following to httpd.conf:

Alias /phpmyadmin/ "/usr/local/www/phpMyAdmin/"

Options none AllowOverride Limit

Order Deny,Allow Deny frrom all Allow from 127.0.0.1 .example.com

===> Registerring installation for phpMyAdmin-3..3.10 ===> Cleaning for phpMyAdmin-3.3.10 www#

แกแ้ ฟ้้ม vi /usr/local/etc/apache22/httpd.conf โดยเพมบรรทิ่ ัดสแดงี ขางล้ าง่ สบเอิ ็ด บรรทัด ใน Zonee ของ Alias

Alias /admin/phpMyAdmin/ "/usr/local/www/phpMyAdmin/"

Options Indexes FollowSymlinks MultiViews AllowOverride None Order allow,deny Allow from all

จากนัันเราก้้ ็สงั่ restart apache wwv# /usr/local/etc/rc.d/apache22 restart Performing sanity check on apache22 configuration: Syntax OK Stopping apache22. Waiting for PIDS: 2559. Performing sanity check on apache22 configuration: Syntax OK Starting apache22..

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิิตยนรา์ Page 29 การติดติ ้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011 www# จากนัันเข้้ าไปท้ ี่ /usr/local/www/phpMyadmin www# cd /usr/local/www/phpMyAdmin/ www# cp config.sample.inc.php config.inc.php www# vi config.inc.php

เพมริ่ หสลั ับลงไป $cfg['blowfish_secret'] = 'phsecret'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! * และ เอา // ขางหน้ า้ บรรทัดออก /* Advanced phppMyAdmin features */ $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin'; $cfg['Servers'][$i]['bookmarktable'] = 'pma_bookmark'; $cfg['Servers'][$i]['relation'] = 'pma_a relation'; $cfg['Servers'][$i]['table_info'] = 'pma_table_info'; $cfg['Servers'][$i]['table_coords'] = 'pma_table_coords'; $cfg['Servers'][$i]['pdf_pages'] = 'pma_pdf_pages'; $cfg['Servers'][$i]['columnn_info'] = 'pma_column_info'; $cfg['Servers'][$i]['history'] = 'pma_history'; $cfg['Servers'][$i]['designer_coords'] = 'pma_designer_coords'; /* Contrib / Swekey authentication */ $cfg['Servers'][$i]['auth_sswekey_config'] = '/etc/swekey-pma.conf';

จากนัันเราก้้ ็สงั่ restart apache www# /usr/local/etc/rc.d/apache22 restart Performing sanity check on apache22 configuration: Syntax OK Stopping apache22. Waiting for PIDS: 24665. Performing sanity check on apache22 configuration: Syntax OK Starting apache22. www#

จากนัันลองเข้้ าเวบท้ ี่ http://www.mu-ph.org/admin/phpMyAdmin/

ในการใชงานให้ ใส้ ่ ชอื่ ผใชู ้ ้ เป็ น root และ password ทระบี่ ุ ตอนทเรี่ าลง mysql52-server

เรากจ็ ะเขาส้ หนู่ าเวบข้ อง phpMyAdmin เพอจื่ ัดการเกยี่ วกบั database แตผ่ เขู ้ ยนชอบี config database แบบ text mode มากกวา่

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิิตยนรา์ Page 30 การติดติ ้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิิตยนรา์ Page 31 การติดติ ้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

ลําดบทัั ี่ 13.) ติิดตั้ง vsftp www# cd /usr/ports/ftp/vsftpd/ www# make config

1. เมอถื่ กถามู เรองื่ vsftp

www# make instaall clean

===> SECURITY REPORT: This port has installed the following files which may act as network servers and may therefore pose a remote security risk to the system. /usr/local/libexec/vsftpd

If there are vulnerabilities in these programs there may be a security risk to the system. FreeBSD makes no guarantee about the security of ports inccluded in the Ports Collection. Please type 'make deinstall' to deinstall the port if this is a concern.

For more information, and contact details about the security status off this software, see the following webpage: http://vsftpd.bbeasts.org/ ===> Cleaning for vsftpd-ssl-2.3.4 www#

เขาไ้ ปแกแฟ้ ้ม vsftpd.conf ไดท้ นี่ ี่ www# cd /usr/local/etc/ www# vi vsftp.cconf

# Example config file /usr/local/etc/vsftpd.conf # # The default compiled in settings are fairly paranoid. This sample file # loosens things up a bit, to make the ftp more usable. # Please see vsftpd.conf.5 for all compiled in defaults. # # READ THIS: This example file is NOT an exhaustive list of vsftpd options. # Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's # capabilities. # # Allow anonymous FTP? (Beware - allowed by default if you comment this out). #anonymous_enabble=YES anonymous_enable=NO # # Uncomment this to allow local users to log in. #local_enable=YES local_enable=YES # # Uncomment this to enable any form of FTP write command. #write_enable=YES write_enable=YES # # Default umask for local users is 077. You may wish to change this to 022, # if your users expect that (022 is used by most other ftpd's) #local_umask=022 local_umask=022 # # Uncomment this to allow the anonymous FTP user to upload files. This only # has an effect if the above global write enable is activated. Also, you will # obviously need to create a directory writable by the FTP user. #anon_upload_ennable=YES การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิิตยนรา์ Page 32 การติดต้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011 anon_upload_enable=YES # # Uncomment this if you want the anonymous FTP user to be able to create # new directories. #anon_mkdir_write_enable=YES anon_mkdir_write_enable=YES # # Activate directory messages - messages given to remote users when they # go into a certain directory. dirmessage_enable=YES # # Activate logging of uploads/downloads. xferlog_enable=YES # # Make sure PORT transfer connections originate from port 20 (ftp-data). connect_from_port_20=YES # # If you want, you can arrange for uploaded anonymous files to be owned by # a different user. Note! Using "root" for uploaded files is not # recommended! #chown_uploads=YES #chown_username=whoever chown_uploads=YES chown_username=ftp # # You may override where the log file goes if you like. The default is shown # below. #xferlog_file=/var/log/vsftpd.log # # If you want, you can have your log file in standard ftpd xferlog format. # Note that the default log file location is /var/log/xferlog in this case. #xferlog_std_format=YES # # You may change the default value for timing out an idle session. #idle_session_timeout=600 # # You may change the default value for timing out a data connection. #data_connection_timeout=120 # # It is recommended that you define on your system a unique user which the # ftp server can use as a totally isolated and unprivileged user. #nopriv_user=ftpsecure nopriv_user=ftp # # Enable this and the server will recognise asynchronous ABOR requests. Not # recommended for security (the code is non-trivial). Not enabling it, # however, may confuse older FTP clients. #async_abor_enable=YES # # By default the server will pretend to allow ASCII mode but in fact ignore # the request. Turn on the below options to have the server actually do ASCII # mangling on files when in ASCII mode. # Beware that on some FTP servers, ASCII support allows a denial of service # attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd # predicted this attack and has always been safe, reporting the size of the # raw file. # ASCII mangling is a horrible feature of the protocol. #ascii_upload_enable=YES #ascii_download_enable=YES # # You may fully customise the login banner string: #ftpd_banner=Welcome to blah FTP service. ftpd_banner=Welcome to MU-PH FTP service. # # You may specify a file of disallowed anonymous e-mail addresses. Apparently # useful for combatting certain DoS attacks. #deny_email_enable=YES deny_email_enable=NO # (default follows) #banned_email_file=/etc/vsftpd.banned_emails # # You may specify an explicit list of local users to chroot() to their home # directory. If chroot_local_user is YES, then this list becomes a list of # users to NOT chroot(). chroot_local_user=YES chroot_list_enable=YES # (default follows) chroot_list_file=/usr/local/etc/vsftpd.chroot_list # # You may activate the "-R" option to the builtin ls. This is disabled by # default to avoid remote users being able to cause excessive I/O on large # sites. However, some broken FTP clients such as "ncftp" and "mirror" assume # the presence of the "-R" option, so there is a strong case for enabling it. #ls_recurse_enable=YES

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิตยนรา์ Page 33 การติดต้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

# # When "listen" directive is enabled, vsftpd runs in standalone mode and # listens on IPv4 sockets. This directive cannot be used in conjunction # with the listen_ipv6 directive. listen=NO # # This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6 # sockets, you must run two copies of vsftpd whith two configuration files. # Make sure, that one of the listen options is commented !! #listen_ipv6=YES secure_chroot_dir=/usr/local/share/vsftpd/empty

# If using vsftpd in standalone mode, uncomment the next two lines: # listen=YES # background=YES

สรางแฟ้ ้ม vsftpd.chroot_list ทเดี่ ยวกี บั vsftpd.conf โดยใสช่ อของื่ user ทสามารถี่ upload เวบได ้ www# vi vsftpd.chroot_list webmaster

แลว้ save หมายถงึ user ทชี่ อื่ webmastr สามารถทจะี่ ftp ขนึ้ server ได ้ นอกนันไม้ ได่ ้

จากนันแก้ แฟ้ ้ม inetd.conf www# vi /etc/inetd.conf #ftp stream tcp nowait root /usr/libexec/ftpd ftpd -l ftp stream tcp nowait root /usr/local/libexec/vsftpd vsftpd /usr/local/etc/vsftpd.conf

เพมิ่ inetd_enable=”YES” ลงใน /etc/rc.conf ดวย้

สงั่ reboot เขาส้ ู่ Server ใหมอ่ กครี ัง้

ณ ตอนน ี้ เราก็ใชโปรแกรมท้ เกี่ ยวกี่ บั ftp ก็สามารถทจะี่ upload/Download แฟ้มไปมาระหวงเคร่ องเรากื่ บั server ได ้

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิตยนรา์ Page 34 การติดติ ้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

ลําดับที่ 14.) ติิดตั้ง awstats www# cd /usr/ports/www/awstats/ www# make config

1. เมอถื่ กู ถามเรองื่ awstats

www# make instaall clean

***************************************************************** Please add the following to your apache config, and restart.

# # Directives to allow use of AWStats as a CGI # Alias /awstatsclasses "/usr/local/www/awstats/claasses/" Alias /awstatscss "/usr/local/www/awstats/css/" Alias /awstatsiicons "/usr/local/www/awstats/icons/" ScriptAlias /awstats/ "/usr/local/www/awstats/cgi-bin/"

# # This is to permit URL access to scripts/files in AWStats directory. # Options None AllowOverriide None Order allow,deny Allow from all

*****************************************************************

If you are upgrrading from AWStats 6.4 or older, please note the following:

If you used the geoip plugin, you must edit your AWStats config file to change the line LoadPlugin="geoip GEOIP_STANDARD" into LoadPlugin="geoip GEOIP_STANDARD /pathto/GeoIP.dat"

***************************************************************** ===> Registerring installation for awstats-7.0_11,1 ===> Cleaning for p5-Net-XWhois-0.90_4 ===> Cleaning for awstats-7.0_1,1 www#

แกแ้ ฟ้้ม vi /usr/local/etc/apache22/httpd.conf โดยเพมบรรทิ่ ัดสแดงี ขางบน้ สบเจิ ็ด บรรทัด ลาง่ บรรทัดทเราเพี่ มเริ่ องื่ phpMyAdmin จากนัันเราก้้ ็สงั่ restart apache www# /usr/local/etc/rc.d/apache22 restart Performing sanity check on apache22 configuration: Syntax OK Stopping apache22. Waiting for PIDS: 1127. Performing sanity check on apache22 configuration: Syntax OK Starting apache22. www#

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิิตยนรา์ Page 35 การติดติ ้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

แกไ้ ขแฟ้ม awstats.conf โดย www# cd /usr/local/www/awstats/cgi-bin/ www# ll total 748 -r-xr-xr-x 1 root wheel 7126 Apr 2 05:37 awredir.pl -r-xr-xr-x 1 root wheel 61638 Apr 2 05:37 awstats.model.conf -r-xr-xr-x 1 root wheel 657786 Apr 2 05:37 awstats.pl drwxr-xr-x 5 root wheel 1536 Apr 2 05:37 lang drwxr-xr-x 2 root wheel 512 Apr 2 05:37 lib drwxr-xr-x 3 root wheel 1024 Apr 2 05:37 plugins www# cp awstats.model.conf awstats.conf www# vi awstats.conf

# LogType=W # SiteDomain="www.mu-ph.org" # HostAliases=" www.mu-ph.org localhost 127.0.0.1 REEGEX[myserver\.com$]" # AllowToUpdateStatsFromBrowser=1

เขาด้ สู ถติ ไดิ ท้ ี่ http://www.mu-ph.org/awstats/awstats.pl

เมอเื่ ขาแล้ วเรา้ click ท ี่ update หรอื ปรับปรุงเดยว๋ี น ี้ ถาพบ้ error บนหนาเวบว้ า่

Error: Couldn't open server log file "/var/log/httpd/mylog.log" : No such file or directory

Setup ('/usr/local/www/awstats/cgi-bin/awstats.conf' file, web server or permissions) may be wrong. Check config file, permissions and AWStats documentation (in 'docs' directory).

ใหเร้ า www# mkdir /varr/log/httpd www# touch /varr/log/httpd/mylog.log www#

จากนัันให้้ เรา้ refresh หนาเวบ้ ก็จะไดตามต้ องการ้

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิิตยนรา์ Page 36 การติดติ ้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

เมอื่ click ทปรี่ ับปรงุ เดยวน๋ี ี้ ก็จะได ้

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิิตยนรา์ Page 37 การติดติ ้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

ลําดบทัั ี่ 15.) ติิดตั้ง ntp www# cd /usr/ports/net/ntp www# make config 1. เมอถื่ กถามู เรองื่ ntp

www# make instaall clean

===> SECURITY REPORT: This port has installed the following files which may act as network servers and may therefore pose a remote security risk to the system. /usr/local/bin/ntpd /usr/local/bin/ntpdate /usr/local/bin/sntp

If there are vulnerabilities in these programs there may be a security risk to the system. FreeBSD makes no guarantee about the security of ports inccluded in the Ports Collection. Please type 'make deinstall' to deinstall the port if this is a concern.

For more information, and contact details about the security status off this software, see the following webpage: http://www.ntp.org/ ===> Cleaning for ntp-4.2.6p2 www#

ใส ่ NTP ท ี่ crontab โดย www# crontab –e

0 5 * * * /usr/local/bin/ntpdate –u 203.185.69.60

หรอื สงั่ั update เวลาตอนนเลยโดยี้ www# date Sat Apr 2 05:53:35 ICT 2011 www# /usr/locall/bin/ntpdate -u 203.185.69.60 date 2 Apr 05:53:41 ntpdate[25373]: step time server 203.185.69.60 offset -3.412298 sec www# date Sat Apr 2 05:53:42 ICT 2011 www#

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิิตยนรา์ Page 38 การติดติ ้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

ลําดับทั ี่ 16). ติดตั้ง clamav www# cd /usr/ports/security/clamav www# make config

1. เมอถื่ กถามู เรองื่ clamav

www# make instaall clean

1. เมอถื่ กถามู เรองื่ llvm

===> SECURITY REPORT: This port has installed the following files which may act as network servers and may therefore pose a remote security risk to the system. /usr/local/sbinn/clamd

This port has installed the following startup scripts which may cause these network services to be started at boot time. /usr/local/etc/rc.d/clamav-milter /usr/local/etc/rc.d/clamav-freshclam /usr/local/etc/rc.d/clamav-clamd

If there are vulnerabilities in these programs there may be a security risk to the system. FreeBSD makes no guarantee about the security of ports inccluded in the Ports Collection. Please type 'make deinstall' to deinstall the port if this is a concern.

For more information, and contact details about the security status off this software, see the following webpage: http://www.clamav.net/ ===> Cleaning for llvm-2.88_3 ===> Cleaning for arc-5.21o_1 ===> Cleaning for arj-3.10.22_4 ===> Cleaning for lha-1.14i_6 ===> Cleaning for unzoo-4.4_2 ===> Cleaning for clamav-0.97 www#

เพมสิ่ องบรรทัดขางล้ า่ งลงไปใน /etc/rc.conf clamav_clamd_enable="YES" clamav_freshclam_enable="YES"

แกไ้ ขแฟ้ม /usr/local/etc/clamd.conf โดยท ี่

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิิตยนรา์ Page 39 การติดต้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

LogFile /var/log/clamav/clamd.log PidFile /var/run/clamav/clamd.pid TemporaryDirectory /var/tmp DatabaseDirectory /var/db/clamav LocalSocket /var/run/clamav/ clamd.sock FixStaleSocket yes User clamav AllowSupplementaryGroups yes ScanPE yes ScanOLE2 yes ScanPDF yes ScanHTML yes ScanArchive yes

แกไขแฟ้ ้ม /usr/local/etc/freshclam.conf โดยท ี่

# Uncomment the following line and replace XY with your country # code. See http://www.iana.org/cctld/cctld-whois.htm for the full list. #DatabaseMirror db.XY.clamav.net DatabaseMirror db.TH.clamav.net

ท ี่ crontab –e ใหเพ้ มิ่ การไปปรับปรงขุ อม้ ลู Virus จาก site ของ clamav ทกๆชุ วโมงสองนาทั่ ี และ ให ้ scan ทเกี่ ็บ web ทกๆตุ หนี งของทึ่ กๆวุ ัน www# crontab –e 0 6 * * * /sbin/reboot 0 5 * * * /usr/local/bin/ntpdate -u 203.185.69.60 2 * * * * /usr/local/bin/freshclam –quiet 0 1 * * * /usr/local/bin/clamscan -r -i /usr/local/www 10 11 * * * /etc/webmin//tempdelete.pl

สงใหั่ ้ Clamav ทํางานกอน่ กอนท่ จะี่ update โดย www# /usr/local/etc/rc.d/clamav-freshclam start Starting clamav_freshclam. www# /usr/local/etc/rc.d/clamav-clamd start Starting clamav_clamd. LibClamAV Warning: ************************************************** LibClamAV Warning: *** The virus database is older than 7 days! *** LibClamAV Warning: *** Please update it as soon as possible. *** LibClamAV Warning: ************************************************** www#

การสงใหั่ ้ clamav ทําการ update ตัวเอง www# /usr/local/bin/freshclam ClamAV update process started at Sat Apr 2 06:40:05 2011 main.cvd is up to date (version: 53, sigs: 846214, f-level: 53, builder: sven) daily.cvd is up to date (version: 12940, sigs: 93187, f-level: 60, builder: ccordes) bytecode.cvd is up to date (version: 142, sigs: 40, f-level: 60, builder: acab) www#

การสงใหั่ ้ scan ท ี่ directory ทตี่ องการโดย้ scan รวม sub-directory และแสดงเฉพาะ แฟ้มทตี่ ดิ virus www# /usr/local/bin/clamscan -r -i /usr/local/www

------SCAN SUMMARY ------Known viruses: 938118 Engine version: 0.97 Scanned directories: 98 Scanned files: 1833 Infected files: 0 Data scanned: 39.24 MB Data read: 17.59 MB (ratio 2.23:1) Time: 28.767 sec (0 m 28 s) www#

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิตยนรา์ Page 40 การติดติ ้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

ลําดบทัั ี่ 17).ติดตั้ง lynx

www# cd /usr/ports/www/lynx-current www# make config ===> No options to configure www# make instaall clean

===> SECURITY REPORT: This port has installed the following files which may act as network servers and may therefore pose a remote security risk to the system. /usr/local/bin/lynx

If there are vulnerabilities in these programs there may be a security risk to the system. FreeBSD makes no guarantee about the security of ports inccluded in the Ports Collection. Please type 'make deinstall' to deinstall the port if this is a concern.

For more information, and contact details about the security status off this software, see the following webpage: http://lynx.iscc.org/current/ ===> Cleaning for mime-support-3.51.1 ===> Cleaning for lynx-2.8.8d8_1 www#

ลองเขา้ www# /usr/local/bin/lynx www.mu-ph.org

ถาม้ นั แสดงไดด้ ังรูปขา้ งบนแสดงวา่ It works ( lynx ) ทํางานแลว้

ผเขู ้ ยี นเอาไวทดสอบว้ า่ เครองื่ server ตัวน ี้ สามารถออก internet ไดหร้ อไมื ?่

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิิตยนรา์ Page 41 การติดต้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

ลําดบทั ี่ 18). ติดตั้ง denyhosts

www# cd /usr/ports/security/denyhosts www# make config ===> No options to configure www# make install clean

------To run denyhosts from startup, add denyhosts_enable="YES" in your /etc/rc.conf. Configiration options can be found in /usr/local/etc/denyhosts.conf ------In order to proper working of denyhosts 1. edit your /etc/hosts.allow file and add: sshd : /etc/hosts.deniedssh : deny sshd : ALL : allow 2. issue the following command if /etc/hosts.deniedssh does not exist yet touch /etc/hosts.deniedssh ------Warning: syslogd should ideally be run with the -c option; this will ensure that denyhosts notices multiple repeated login attempts.

To do this, add syslogd_flags="-c" to /etc/rc.conf ------===> Installing rc.d startup script(s) ===> Registering installation for denyhosts-2.6_3 ===> Cleaning for denyhosts-2.6_3 www#

แกไขแฟ้ ้ม /etc/hosts.allow vi /etc/hosts.allow # Wrapping sshd(8) is not normally a good idea, but if you # need to do it, here's how #sshd : .evil.cracker.example.com : deny sshd : /etc/hosts.deniedssh : deny sshd : ALL : allow

และสงสรั่ างแฟ้ ้ม /etc/hosts.deniedssh โดยใชค้ ําสงั่ touch /etc/hosts.deniedssh

แกไขแฟ้ ้ม /usr/local/etc/denyhosts.conf

SECURE_LOG = /var/log/auth.log HOSTS_DENY = /etc/hosts.allow PURGE_DENY = 7d BLOCK_SERVICE = sshd HOSTNAME_LOOKUP=YES ADMIN_EMAIL = [email protected]

เพมการทิ่ ํางานของ denyhosts ใน crontab –e

0,20,40 * * * * /usr/local/bin/python /usr/local/bin/denyhosts.py -c /usr/local/etc/denyhosts.conf

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิตยนรา์ Page 42 การติดต้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

ลําดบทั ี่ 19). การติดตั้ง zip & UNZIP www# cd /usr/ports/archivers/zip www# make config ===> No options to configure www# make install clean

===> Compressing manual pages for zip-3.0 ===> Registering installation for zip-3.0 ===> Cleaning for unzip-6.0 ===> Cleaning for zip-3.0

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิตยนรา์ Page 43 การติดต้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011

ลําดบทั ี่ 20). การ Backup (เฉพาะ เวบ) www# cd /backups/ www# mkdir /backups/last-full www# date +%d%b > /backups/last-full/www-full-date www# mkdir /usr/local/www/util www# vi backups.sh

#!/bin/sh cd /usr/local/www/util #backup database mysqldump mysql > mysql.sql --password=ssssssss

#backup passwd & group cp /etc/passwd* . cp /etc/group* . cp /etc/master* .

#backup conf cp /etc/rc.conf . cp /usr/local/etc/apache22/httpd.conf . CP /usr/local/etc/apache22/Includes/php5.conf . cp /usr/local/etc/php.ini . cp /etc/resolv.conf . cp /etc/ntp.conf . cp /usr/local/www/awstats/cgi-bin/awstats.conf . cp /usr/local/etc/clamd.conf . cp /usr/local/www/phpMyAdmin/config.inc.php . cp /usr/local/etc/denyhosts.conf . cp /usr/local/etc/freshclam.conf . cp /etc/inetd.conf .

# Full and incremental backup script # Updated 04 July 2002 # Based on a script by Daniel O'Callaghan # and modified by Gerhard Mourani # Change the 5 variables below to fit your computer/backup COMPUTER=www # Name of this computer DIRECTORIES="/usr/local/www" # Directory to backup BACKUPDIR=/backups # Where to store the backups TIMEDIR=/backups/last-full # Where to store time of full backup TAR=/usr/bin/tar # Name and location of tar # You should not have to change anything below here PATH=/usr/local/bin:/usr/bin:/bin DOW=`date +%a` # Day of the week e.g. Mon DOM=`date +%d` # Date of the Month e.g. 27 DM=`date +%d%b` # Date and Month e.g. 27 Sep # On the 1st of the month a permanet full backup is made # Every Sunday a full backup is made - overwriting last Sundays backup # The rest of the time an incremental backup is made. Each incremental # backup overwrites last weeks incremental backup of the same name. # # if NEWER = "", then tar backs up all files in the directories # otherwise it backs up files newer than the NEWER date. NEWER # gets it date from the file written every Sunday. # Monthly full backup if [ $DOM = "01" ]; then NEWER="" $TAR $NEWER -cf $BACKUPDIR/$COMPUTER-$DM.tar $DIRECTORIES fi # Weekly full backup if [ $DOW = "Sun" ]; then NEWER="" NOW=`date +%d-%b` # Update full backup date echo $NOW > $TIMEDIR/$COMPUTER-full-date $TAR $NEWER -cf $BACKUPDIR/$COMPUTER-$DOW.tar $DIRECTORIES # Make incremental backup - overwrite last weeks else # Get date of last full backup NEWER="--newer `cat $TIMEDIR/$COMPUTER-full-date`" $TAR $NEWER -cf $BACKUPDIR/$COMPUTER-$DOW.tar $DIRECTORIES fi

#remove passwd & group

cd /usr/local/www/util rm -f passwd* rm -f group*

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิตยนรา์ Page 44 การติดต้งั WebServer โดยใช ้ FreeBSD 8.2

Rev001: Apr 1,2011 rm -f master*

เพมคิ่ ําสงในั่ crontab –e

0 4 * * * /backups/backups.sh

เป็ นการทํา backup ทกตุ สี ของที่ กวุ ัน www# ll total 298316 drwxrwxr-x 2 root operator 512 Apr 1 20:08 .snap -rw-r--r-- 1 root wheel 299815424 Apr 2 06:58 Distfiels82.tar -rwx------1 root wheel 2526 Apr 2 06:57 backups.sh -rwx------1 root wheel 58 Apr 1 14:55 chkdisk.sh -rw-r--r-- 1 root wheel 1183 Apr 1 14:45 ipfw.rules drwxr-xr-x 2 root wheel 512 Apr 1 22:19 last-full -rw-r--r-- 1 root wheel 2703872 Apr 1 22:19 www-01Apr.tar -rw-r--r-- 1 root wheel 2703872 Apr 1 22:19 www-Fri.tar www# ./backups.sh tar: Removing leading '/' from member names www# ll total 320204 drwxrwxr-x 2 root operator 512 Apr 1 20:08 .snap -rw-r--r-- 1 root wheel 299815424 Apr 2 06:58 Distfiels82.tar -rwx------1 root wheel 2526 Apr 2 06:57 backups.sh -rwx------1 root wheel 58 Apr 1 14:55 chkdisk.sh -rw-r--r-- 1 root wheel 1183 Apr 1 14:45 ipfw.rules drwxr-xr-x 2 root wheel 512 Apr 1 22:19 last-full -rw-r--r-- 1 root wheel 2703872 Apr 1 22:19 www-01Apr.tar -rw-r--r-- 1 root wheel 2703872 Apr 1 22:19 www-Fri.tar -rw-r--r-- 1 root wheel 22391808 Apr 2 06:59 www-Sat.tar www#

จะเห็นวาม่ แฟี ้ม www-Sat.tar เกดขิ นมาึ้

สวนแฟ่ ้ม www-01Apr.tar และ www-Fri.tar เป็ นแฟ้มทที่ ําในวันท ี่ 1 (ของทกเดุ อนจะมื ี www-01XXX.tar ออกมาดวย้ )

ใหส้ งเกตั วุ า่ ในวนอาทั ตยิ ์ จะเป็ นการ Backup แบบ Full นอกนัน้ จะ backup เฉพาะแฟ้มทมี่ การเปลี ยนแปลงี่

ทายท้ สี่ ดนุ ี้

หวังเป็ นอยางย่ งวิ่ า่ เอกสารชนนิ้ ี้ คงจะมสี วนช่ วย่ ในการทํา WebServer ดวย้ FreeBSD 8.2

เสรมพิ ันธ ุ์ นตยิ นรา์ 2 เมษายม 2554

การติดต้งั WebServer โดยใช ้ FreeBSD 8.2 โดย เสริมพนธั ุ ์ นิตยนรา์ Page 45