Sunday, October 26, 2014 10:30 PM 0 Comments apache , apache2 , appserv , kittinan , lamp , linux ,localhost , mysql , php , php5 , phpmyadmin , server , ubuntuinstall , ติดตั้ง , วิธีการติดตั้ง
มาถึงปลายปี 2014 ผมเชื่อว่ายังมีนักพัฒนาเวปด้วยภาษา php หลายท่านยังใช้ Appserv, XAMPP, WAMP และ MAMP กันอยู่ ไม่ใช่มันไม่ดีนะครับ แต่เราควรที่จะเรียนรู้วิธีการติดตั้ง Software แต่ละตัวกันเองดีกว่า ผมจะยกตัวอย่างของ Appserv นะครับ Appserv รุ่นล่าสุดยังใช้งาน PHP ใน version 5.2 อยู่เลยครับ ซึ่งปัจจุบัน ณ เวลานี้ PHP ออก version 5.6 มาแล้วครับ
และอีกอย่างนึงก็อยากให้นักพัฒนาเวปด้วย php ทั้งหลายลองหันมาใช้ Linux กันครับ เพราะสภาพแวดล้อมจริงๆในการรัน Web Server ส่วนใหญ่จะรันอยู่บน Linux ซึ่งจะทำให้ตัวนักพัฒนาเข้าใจสภาพแวดล้อมดียิ่งขึ้นครับ
เรามาเริ่มกันเลยครับ โดยผมจะใช้ Ubuntu 14.04 ในการติดตั้ง ผ่าน Terminal หรือ Command line นั้นเอง โดยบน Ubuntu 14.04 สามารถกดคีย์ลัดคือ CTRL + ALT +T
1. ติดตั้ง Apache Web Server
sudo apt-get install apache2
2. ทดสอบว่า Apache ติดตั้งสำเร็จ โดยเปิด Web Browser แล้วเข้าที่ http://localhost/3. ทำการติดตั้ง Mysql Server (หากไม่ชอบ Mysql ผมแนะนำเป็น MariaDB แทนครับ Performance ดีกว่า Mysql มากๆ)3.1 ติดตั้ง Mysql sudo apt-get install mysql-server mysql-client
4. ติดตั้ง PHP และ Apache php module sudo apt-get install php5 libapache2-mod-php5 php5-mysql php5-curl php5-gd php-pear php5-imagick php5-mcrypt php5-memcache php5-sqlite php5-json
5. ทดสอบว่า php ใช้งานได้
sudo chmod 777 /var/www/html/
5.1 สร้างไฟล์ info.php ที่ path /var/www/html/
nano /var/www/html/info.php
โดยใส่ code เข้าไปดังนี้
<?php
phpinfo();
Enter Your Mysql Password
5.2 Restart Apache sudo service apache2 restart
5.3 ทดสอบโดยการเปิด Web Browser ไปที่ http://localhost/info.php
6. ติดตั้ง Phymyadmin
6.1 Download ไฟล์ phpmyadmin จากเวป http://www.phpmyadmin.net/home_page/downloads.php
6.2 แตกไฟล์ที่ Download ไว้ที่ /var/www/html/phpmyadmin
6.3 เปลี่ยนชื่อไฟล์ /var/www/html/phpmyadmin/config.sample.inc.php เป็น /var/www/html/phpmyadmin/config.inc.php
6.4 เปิดไฟล์ /var/www/html/phpmyadmin/config.inc.php และแก้ไข้บรรทัด
$cfg['blowfish_secret'] = '5555555555555555555555555555555555';
โดยใส่ค่ามั่วๆลงไป
6.5 ทดสอบโดยการเปิด Web Browser ไปที่ http://localhost/phpmyadmin
ก็เสร็จสิ้นไปแล้วสำหรับการติดตั้ง Apache + Mysql + PHP + Phpmyadmin นะครับ ไม่ยากเลยง่ายนิดเดียว
Before installation, Make sure you have assigned static IP to the server.
Step 1 » Issue the below command to update repository.
krizna@leela:~$ sudo apt-get update
Step 2 » Now install isc-dhcp-server package and dependencies.
krizna@leela:~$ sudo apt-get install isc-dhcp-server -y
Step 3 » After installing, open /etc/default/isc-dhcp-server file and assign interface.
krizna@leela:~$ sudo nano /etc/default/isc-dhcp-server
INTERFACES="eth0"
Step 4 » We need to define below values in dhcpd.conf file located in /etc/dhcp/directory.
Example scenario:
Network : 192.168.100.0/24
Range : 192.168.100.20 ( Starting IP ) – 192.168.100.100 ( Ending IP )
Gateway : 192.168.100.1
Primary DNS : 192.168.100.5
Sec DNS : 8.8.8.8
Take backup copy before making changes to the original file .Better rename the file and create a new one .
krizna@leela:~$ sudo mv /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.org
krizna@leela:~$ sudo nano /etc/dhcp/dhcpd.conf
and add the below code after making changes as per your network values.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# option definitions common to all supported networks...
default-lease-time 600;
max-lease-time 7200;
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;
# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;
subnet 192.168.100.0 netmask 255.255.255.0 { #network
range 192.168.100.20 192.168.100.100; # Range
option domain-name-servers 192.168.100.5, 8.8.8.8; #Pri DNS , Sec DNS
option domain-name "krizna.com"; #Domain name
option routers 192.168.100.1; #Gateway
option broadcast-address 192.168.100.255; #Broadcast
default-lease-time 600;
max-lease-time 7200;
}
Step 5 » Now start/restart dhcp service using the below command.
krizna@leela:~$ sudo service isc-dhcp-server restart
Sometimes you need to reserve IP to some devices like printers, camera, linux machines etc.
In this case, first you need to find MAC Address of that device and define values in that particular subnet.
For example, Printer with 00:DD:HD:66:55:9B MAC Address has to be assigned with 192.168.100.50 IP. For this, you need to add code like below to that subnet.
1
2
3
4
5
6
7
8
9
10
11
12
subnet 192.168.100.0 netmask 255.255.255.0 { #network
- - - - -
max-lease-time 7200;
host printer-finance {
hardware ethernet 00:DD:HD:66:55:9B;
fixed-address 192.168.100.50;
}
host cam-gate {
hardware ethernet 00:KK:HD:44:55:22;
fixed-address 192.168.100.90;
}
}
and restart DHCP service.
krizna@leela:~$ sudo service isc-dhcp-server restart
That’s it . All the best
Step 1 » Install samba packages after updating repositories
krizna@leela:~$ sudo apt-get update
krizna@leela:~$ sudo apt-get install samba samba-common python-glade2
Everyone can access and store files without username and password .
Step 2 » Create folder for Anonymous share.
krizna@leela:~$ sudo mkdir -p /shares/anonymous
Step 3 » Change the ownership to nobody so that everyone can access and store files in that folder.
krizna@leela:~$ sudo chown nobody:nogroup /shares/anonymous/
Step 4 » Now define values in samba configuration to share /shares/anonymous/folder. /etc/samba/smb.conf is the main configurion file for samba .
Take a backup before editing that file .
krizna@leela:~$ sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.org
now add the below code at the end of the file to enable share.
krizna@leela:~$ sudo vim /etc/samba/smb.conf
1
2
3
4
5
6
7
8
9
[Anonymous]
comment = Anonymous share access
path = /shares/anonymous
browsable = yes
writable = yes
guest ok = yes
read only = no
force user = nobody
force group = nogroup
Step 5 » Now restart smbd service .
krizna@leela:~$ sudo service smbd restart
After restarting service . Try to access share from windows client (Goto -> RUN ->\\serverIP ) . you could access anonymous share folder without username and password, try to create or copy files to that folder.
Secured shares can be accessed using username and password .Here for example, I’m going to create share project1.
Step 6 » Create a folder for share .
krizna@leela:~$ sudo mkdir -p /shares/project1
Step 7 » Create a new group smbproj1,so that Users added to this group can access project1 share.
krizna@leela:~$ sudo addgroup smbproj1
Step 8 » Modify ownership and permission for the folder.
krizna@leela:~$ sudo chown root:smbproj1 /shares/project1/
krizna@leela:~$ sudo chmod 770 /shares/project1/
Step 9 » Now define values in the configuration file .
krizna@leela:~$ sudo vim /etc/samba/smb.conf
1
2
3
4
5
6
7
[Project1]
comment = Project1 Share
path = /shares/project1
valid users = @smbproj1
guest ok = no
writable = yes
browsable = yes
Step 10 » Now restart smbd service .
krizna@leela:~$ sudo service smbd restart
After restarting service, you could see Project1 share . Additional secured shares can be created in the same way.
Add new user john for accessing project1 share
Step 11 » Create a user john .
krizna@leela:~$ sudo useradd john -s /usr/sbin/nologin -G smbproj1
-s /usr/sbin/nologin : Restricting shell access
-G smbproj1 : Added to smbproj1 group
Step 12 » Create samba password for user john
krizna@leela:~$ sudo smbpasswd -a john
Now user john can access Project1 share. Additional users can be added in the same way.
For existing users use usermod command to add user in smbproj1 group and create samba password using smbpasswd.
krizna@leela:~$ sudo usermod mike -G smbproj1
For accessing multiple shares. Example: dave has access to multiple project groups like smbproj1 and smbproj2.
krizna@leela:~$ sudo usermod dave -G smbproj1,smbproj2
For troubleshooting, Use testparm command
For more info Samba file server guide
That’s it. Have a nice day.
Step 1 » Update the repositories.
sudo apt-get update
Step 2 » Install bind9 using the below command.
sudo apt-get install bind9
Now installation is over, please proceed with configuration.
Caching nameserver will remember all the DNS queries made and serves locally when the domain is queried second time. Default configuration will act as a caching nameserver, you just need is to add public DNS IPs in the configuration file.
Step 3 » Open /etc/bind/named.conf.options file and find forwarders column , uncomment and edit like the following.
1
2
3
4
forwarders {
8.8.8.8;
8.8.4.4;
};
Here 8.8.8.8 and 8.8.4.4 are google public DNS servers .
Step 4 » Now start/restart the service.
sudo service bind9 restart
Step 5 » Now test using dig command . open /etc/resolv.conf and edit nameserver ip to 127.0.0.1 or your serverIP.
nameserver 127.0.0.1
Now type the below command to see results.
krizna@ns:~$ dig www.krizna.com
................
;; Query time: 83 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
.................
It took 83 msec for the first time . Now try the same command again.
krizna@ns:~$ dig www.krizna.com
................
;; Query time: 5 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
.................
Now reduced to 5 msec . This time it serves from local.
Primary master configuration is just like managing DNS records for particular domain locally ( Eg: krizna.com ).
Scenario details:
Domain name : krizna.com
Server ip : 192.168.6.5
Server hostname : ns.krizna.com
Webserver ip : 192.168.6.10 ( www.krizna.com) .
We need to create 2 zone files , Forward zone and reverse zone.
Step 6 » Create forward zone file db.krizna.com by copying db.local conf file.
sudo cp /etc/bind/db.local /etc/bind/db.krizna.com
Step 7 » Now open /etc/bind/db.krizna.com and edit like below.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA ns.krizna.com. root.ns.krizna.com. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns.krizna.com.
@ IN A 192.168.6.5
@ IN AAAA ::1
ns IN A 192.168.6.5
www IN A 192.168.6.10
Step 7 » Create reverse zone file db.192 by copying db.172 conf file.
sudo cp /etc/bind/db.127 /etc/bind/db.192
Step 8 » Now open /etc/bind/db.192 file and edit like below.
1
2
3
4
5
6
7
8
9
10
11
12
13
; BIND reverse data file for local loopback interface
;
$TTL 604800
@ IN SOA ns.krizna.com. root.ns.krizna.com. (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns.
5 IN PTR ns.krizna.com.
10 IN PTR www.krizna.com.
Step 9 » Now open /etc/bind/named.conf.local configuration file and add the below lines to include forward and reverse zone files . 6.168.192 in reverse column is just first three octets of your network.
1
2
3
4
5
6
7
8
9
10
// Forward zone
zone "krizna.com" {
type master;
file "/etc/bind/db.krizna.com";
};
//reverse zone
zone "6.168.192.in-addr.arpa" {
type master;
file "/etc/bind/db.192";
};
Step 10 » Now restart the service.
sudo service bind9 restart
Step 11 » Now test using nslookup or dig commands.
krizna@ns:~$ nslookup www.krizna.com
Server: 127.0.0.1
Address: 127.0.0.1#53
Name: www.krizna.com
Address: 192.168.6.10
Now test reverse lookup
krizna@ns:~$ nslookup 172.27.6.10
Server: 127.0.0.1
Address: 127.0.0.1#53
10.6.27.172.in-addr.arpa name = www.krizna.com.
That’s it , Your DNS server is ready .
How to Install and Configure phpMyAdmin on Ubuntu 14.04
Filed under: Technical Support
phpMyAdmin is an open source tool used for the administration of MySQL. In addition to offering the capability to perform administration tasks such as creating, editing, or deleting databases, and managing users and permissions, phpMyAdmin provides a graphical user interface to do all of these tasks and more.
Pre-Flight Check
These instructions are intended specifically for installing phpMyAdmin 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.
A LAMP, Linux, Apache, MySQL and PHP, must be installed on your server. If you’re working from a Liquid Web Core Managed Ubuntu 14.04 LTS server as I am, then the LAMP stack is already installed!
Step 1: Install phpMyAdmin
First, you’ll follow a simple best practice: ensuring the list of available packages is up to date before installing anything new.
apt-get -y update
Then it’s a matter of just running one command for installation via apt-get:
apt-get -y install phpmyadmin
Step 2: Basic Configuration
As the installation runs you’ll be asked a few simple questions regarding the basic configuration of phpMyAdmin.
At the first screen, select apache2 by using the space bar, then hit enter to continue.
At the second screen, which asks “configure the database for phpmyadmin with dbconfig-common?”, select Yes , then hit enter to continue.
At the third screen enter your MySQL password, then hit enter to continue.
And finally at the fourth screen set the password you’ll use to log into phpmyadmin, hit enter to continue, and confirm your password.
Step 3: Finish the Configuration of Apache
For a refresher on editing files with vim see: New User Tutorial: Overview of the Vim Text Editor
vim /etc/apache2/apache2.conf
Add the following to the bottom of the file:
# phpMyAdmin Configuration
Include /etc/phpmyadmin/apache.conf
Then exit and save the file with the command :wq .
And, restart Apache 2 with the following command:
service apache2 restart
Verify that phpMyAdmin is working by visiting the_IP_of_your_server/phpmyadmin. For example: http://127.0.0.1/phpmyadmin
เผยแพร่ ธันวาคม 17, 2014 แล้ว | โดย administrator
ล้างทั้งหมด
dpkg -l *apache* *mysql* *php* phpmyadmin | grep ^ii | awk '{ print $2}' | xargs sudo apt-get -y purge --auto-remove
ตรวจสอบว่าเหลืออยู่หรือไม่
dpkg -l *apache* *mysql* *php* phpmyadmin | grep ^ii | awk '{ print $2}'
เริ่มติดตั้ง
sudo apt-get update
sudo apt-get install apache2 apache2-utils
แก้ไขไฟล์
sudo vi /etc/apache2/mods-enabled/dir.conf
แก้ไข แทนที่ ไฟล์ dir.conf
<IfModule mod_dir.c>
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>
รี apache
sudo service apache2 restart
ติดตั้ง sql
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql
ตรวจสอบติดตั้งฐาน
sudo mysql_install_db
ตรวจสอบความปลอดภัย
sudo mysql_secure_installation
ติดตั้ง php5
sudo apt-get install php5 php5-mysql php-pear php5-gd php5-mcrypt php5-curl
ยืนยันตั้งค่า LAMP กับ ubuntu
sudo apt-get install lamp-server^
ติดตั้ง phpmyadmin
sudo apt-get install phpmyadmin
โพสท์ใน Service Computer
1) ติดตั้ง lampp โดยเลือกแพกเกจที่มี PHP เวอร์ชั่น 5.3.8
1.1) ให้ดาวน์โหลดไฟล์จากเว็บ https://www.apachefriends.org/download.html
เลือกเวอร์ชั่น xampp-linux-1.7.7.tar.gz ดาวน์โหลดเสร็จย้ายไปที่ home
1.2) แตกไฟล์ไปที่ /opt
sudo tar xvfz xampp-linux-1.7.7.tar.gz -C /opt
1.3) เริ่มทำงาน
sudo /opt/lampp/lampp start
1.4) กำหนดรหัสผ่าน
sudo /opt/lampp/lampp security
อ้างอิง : http://www.youtube.com/watch?v=xaDzyo0ObvU&list=PLN-8Ywrbia66ZmYKdeu7aPEMAzd4M82IT&index=2
2)กำหนดสิทธิ์ให้เรียกไฟล์ได้
2.1 To change all the directories to 755 (-rwxr-xr-x):
find /opt/lampp/htdocs -type d -exec chmod 755 {} \;
2.2 To change all the files to 644 (-rw-r--r--):
find /opt/lampp/htdocs -type f -exec chmod 644 {} \;
3) ตั้งค่าให้ Start lampp อัตโนมัติ(เมื่อเปิดเครื่อง)
3.1) Open terminal and run following command.
sudo gedit /etc/init.d/lampp
3.2) paste following code in open file
#!/bin/bash
/opt/lampp/lampp start
save and close the file
3.3) run following command to install init scripts to all runlevel
sudo update-rc.d lampp defaults
restart the system