Linux操作系统下NTP服务器简单配置过程
* 2008-01-10 17:00:02 作者: 来源:赛迪网 浏览次数:261 文字大小:【大】【中】【小】
简介: 关于时间服务 Network Time Protocol(NTP,网络时间协议)用于同步它所有客户端时钟的服务。NTP服务器将本地系统的时钟与一个公共的NTP服务器同步然后作为时间主机提供服务,使本地网络的所有客户端能同步时 ...
关键字: Linux操作系统 NTP服务器 配置
热点:
Ctrix,HP,EMC,CIW,Oracle,Comptia,IBM,Certification Exams Questions;Bootcamp Braindumps-TestInside
中国网络
关于时间服务
Network Time Protocol(NTP,网络时间协议)用于同步它所有客户端时钟的服务。NTP服务器将本地系统的时钟与一个公共的NTP服务器同步然后作为时间主机提供服务,使本地网络的所有客户端能同步时钟。
同步时钟最大的好处就是相关系统上日志文件中的数据,如果网络中使用中央日志主机集中管理日志,得到的日志结果就更能反映真实情况。在同步了时钟的网络中,集中式的性能监控、服务监控系统能实时的反应系统信息,系统管理员可以快速的检测和解决系统错误。
安装配置NTP服务
下面将介绍NTP服务器的简单配置:
一般的Linux发行版都会带ntp软件包,如果你的系统中还没有安装,就使用rpm命令安装此包,以下以fedora core 6系统为例配置一台时间服务器:
[root@supersun.biz root]# rpm -ivh ntp-4.2.2p1-3.i386.rpm
warning: ntp-4.2.2p1-3.i386.rpm: V3 DSA signature: NOKEY, key ID db42a60e
Preparing... ########################################### [100%]
1:ntp ########################################### [100%]
编辑配置文件/etc/ntp.conf
restrict default nomodify notrap noquery
restrict 127.0.0.1
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap
server 0.asia.pool.ntp.org
server 1.asia.pool.ntp.org
server 2.asia.pool.ntp.org
server 3.asia.pool.ntp.org
server 127.127.1.0
fudge 127.127.1.0 stratum 10
斜体部分是我添加的部分,设定可以使用时间服务器的两个网段的内网地址及使用的外部的时间服务器。现在我们对配置做一个简要的解释:
第一行restrict、default定义默认访问规则,nomodify禁止远程主机修改本地服务器配置,notrap拒绝特殊的ntpdq捕获消息,noquery拒绝btodq/ntpdc查询(这里的查询是服务器本身状态查询)。
配置文件的最后两行作用是当服务器与公用的时间服务器失去联系时以本地时间为客户端提供时间服务。
端口
ntp使用udp协议,记得开放其123端口。
启动NTPD
启动ntpd守护进程:
service ntpd start
客户端的配置
以root身份运行周期性任务:
[root@supersun root]# crontab -e
添加以下内容,每15分钟更新一下时间:
*/15 * * * * ntpdate ntp.supersun.biz
此处的ntpdate命令包含在ntp软件包中,记得确认系统中是否已安装。
2008年3月6日星期四
2008年3月5日星期三
NTP Server and Client Configuration in debian
NTP Server and Client Configuration in debian
by Admin @ 11:24 am. Filed under General
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
The Network Time Protocol (NTP) is a protocol for synchronizing the clocks of computer systems over packet-switched, variable-latency data networks. NTP uses UDP port 123 as its transport layer. It is designed particularly to resist the effects of variable latency (Jitter).
Using NTP is a great way to keep your system clock set correctly. It works by contacting a number of servers around the world, asking them for the time and then calculating what the correct local time is from their responses.
Install NTP server in Debian
#apt-get install ntp ntpdate ntp-server
This will install all the required packages for NTP
Configuring NTP Server
By Default main configuration file located at /etc/ntp.conf
Default configuration file looks like below
#/etc/ntp.conf, configuration for ntpd
driftfile /var/lib/ntp/ntp.drift
statsdir /var/log/ntpstats/
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
# You do need to talk to an NTP server or two (or three).
#server ntp.your-provider.example
# pool.ntp.org maps to more than 300 low-stratum NTP servers.
# Your server will pick a different set every time it starts up.
# *** Please consider joining the pool! ***
# *** ***
server 0.debian.pool.ntp.org iburst
server 1.debian.pool.ntp.org iburst
server 2.debian.pool.ntp.org iburst
server 3.debian.pool.ntp.org iburst
# By default, exchange time with everybody, but don't allow configuration.
# See /usr/share/doc/ntp-doc/html/accopt.html for details.
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery
# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1
# Clients from this (example!) subnet have unlimited access,
# but only if cryptographically authenticated
#restrict 192.168.123.0 mask 255.255.255.0 notrust
# If you want to provide time to your local subnet, change the next line.
# (Again, the address is an example only.)
#broadcast 192.168.123.255
# If you want to listen to time broadcasts on your local subnet,
# de-comment the next lines. Please do this only if you trust everybody
# on the network!
#disable auth
#broadcastclient
Example Configuration
You need to add a number of servers to the server list. The Debian default is pool.ntp.org which works but isn’t always amazingly accurate because it makes no attempt to use time servers near you. If you want more accuracy use the time servers either on your continent (for instance europe.pool.ntp.org) or your country (for instance uk.pool.ntp.org) one of your local country servers.The optimal number of servers to listen to is three but two will also give a good accuracy. If your ISP runs a time server for you it is worth including it in your server list as it will often be more accurate than the pooled servers and will help keep the load down on the pool.
I am using the following two servers for my configuration
server ntp0.pipex.net
server ntp1.pipex.net
Restrict the type of access you allow these servers. In this example the servers are not allowed to modify the run-time configuration or query your Linux NTP server.
restrict otherntp.server.org mask 255.255.255.255 nomodify notrap noquery
restrict ntp.research.gov mask 255.255.255.255 nomodify notrap noquery
The mask 255.255.255.255 statement is really a subnet mask limiting access to the single IP address of the remote NTP servers.
If this server is also going to provide time for other computers, such as PCs, other Linux servers and networking devices, then you’ll have to define the networks from which this server will accept NTP synchronization requests. You do so with a modified restrict statement removing the noquery keyword to allow the network to query your NTP server. The syntax is:
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
In this case the mask statement has been expanded to include all 255 possible IP addresses on the local network.
We also want to make sure that localhost (the universal IP address used to refer to a Linux server itself) has full access without any restricting keywords
restrict 127.0.0.1
Save the file and exit
Now you need to run the ntpdate command against your server
#ntpdate ntp0.pipex.net
restart NTP for these settings to take effect using the following command
#/etc/init.d/ntp restart
You can now configure other Linux hosts on your network to synchronize with this new master NTP server in a similar fashion.
Determining If NTP Is Synchronized Properly
Use the ntpq command to see the servers with which you are synchronized. It provided you with a list of configured time servers and the delay, offset and jitter that your server is experiencing with them. For correct synchronization, the delay and offset values should be non-zero and the jitter value should be under 100.
#ntpq -p
Output looks like below
A star by any one of the names means that the system clock is synchronising with the NTP clock. If you don’t have a star (as in the example above) it means that the clocks are unreachable, already synchronized to this server or has an outrageous synchronization distance. Try running ntpdate (you will need to stop the ntp server) with your first ntp server as an argument. This will set your system clock fairly accuratly and mean that the server will be able to choose a clock to synchronize with.
Firewall Configuration for NTP
NTP servers communicate with one another using UDP with a destination port of 123. Unlike most UDP protocols, the source port isn’t a high port (above 1023), but 123 also. You’ll have to allow UDP traffic on source/destination port 123 between your server and the Stratum 1/2 server with which you are synchronizing.
NTP Client Configuration
If you want to configure ntp client you need to install the following packages
#apt-get install ntp ntp-simple ntpdate
Configuring NTP client
You need to edit the /etc/ntp.conf file you need to point the following settings to NTP server ip address
Server configuration settings
server 192.168.1.1
Restrict the type of access you allow these servers. In this example the servers are not allowed to modify the run-time configuration or query your Linux NTP server.
restrict default notrust nomodify nopeer
Localhost configuration
restrict 192.168.1.1
In this case the mask statement has been expanded to include all 255 possible IP addresses on the local network.
We also want to make sure that localhost (the universal IP address used to refer to a Linux server itself) has full access without any restricting keywords
restrict 127.0.0.1
Now you need to save and exit the file
run ntpdate command against your server
ntpdate 192.168.1.1
Restart ntp service using the following command
/etc/init.d/ntp restart
If you use the date command to change time, it is worth setting also the hardware clock to the correct time. Otherwise, the time is wrong after the next reboot, since the hardware clock keeps the time when power is turned off. When the clock in the operating system shows the correct time, set the hardware clock like this
#hwclock --systohc
se the ntpq command to see the servers with which you are synchronized
#ntpq
#ntpdc -p
by Admin @ 11:24 am. Filed under General
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
The Network Time Protocol (NTP) is a protocol for synchronizing the clocks of computer systems over packet-switched, variable-latency data networks. NTP uses UDP port 123 as its transport layer. It is designed particularly to resist the effects of variable latency (Jitter).
Using NTP is a great way to keep your system clock set correctly. It works by contacting a number of servers around the world, asking them for the time and then calculating what the correct local time is from their responses.
Install NTP server in Debian
#apt-get install ntp ntpdate ntp-server
This will install all the required packages for NTP
Configuring NTP Server
By Default main configuration file located at /etc/ntp.conf
Default configuration file looks like below
#/etc/ntp.conf, configuration for ntpd
driftfile /var/lib/ntp/ntp.drift
statsdir /var/log/ntpstats/
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
# You do need to talk to an NTP server or two (or three).
#server ntp.your-provider.example
# pool.ntp.org maps to more than 300 low-stratum NTP servers.
# Your server will pick a different set every time it starts up.
# *** Please consider joining the pool! ***
# *** ***
server 0.debian.pool.ntp.org iburst
server 1.debian.pool.ntp.org iburst
server 2.debian.pool.ntp.org iburst
server 3.debian.pool.ntp.org iburst
# By default, exchange time with everybody, but don't allow configuration.
# See /usr/share/doc/ntp-doc/html/accopt.html for details.
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery
# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1
# Clients from this (example!) subnet have unlimited access,
# but only if cryptographically authenticated
#restrict 192.168.123.0 mask 255.255.255.0 notrust
# If you want to provide time to your local subnet, change the next line.
# (Again, the address is an example only.)
#broadcast 192.168.123.255
# If you want to listen to time broadcasts on your local subnet,
# de-comment the next lines. Please do this only if you trust everybody
# on the network!
#disable auth
#broadcastclient
Example Configuration
You need to add a number of servers to the server list. The Debian default is pool.ntp.org which works but isn’t always amazingly accurate because it makes no attempt to use time servers near you. If you want more accuracy use the time servers either on your continent (for instance europe.pool.ntp.org) or your country (for instance uk.pool.ntp.org) one of your local country servers.The optimal number of servers to listen to is three but two will also give a good accuracy. If your ISP runs a time server for you it is worth including it in your server list as it will often be more accurate than the pooled servers and will help keep the load down on the pool.
I am using the following two servers for my configuration
server ntp0.pipex.net
server ntp1.pipex.net
Restrict the type of access you allow these servers. In this example the servers are not allowed to modify the run-time configuration or query your Linux NTP server.
restrict otherntp.server.org mask 255.255.255.255 nomodify notrap noquery
restrict ntp.research.gov mask 255.255.255.255 nomodify notrap noquery
The mask 255.255.255.255 statement is really a subnet mask limiting access to the single IP address of the remote NTP servers.
If this server is also going to provide time for other computers, such as PCs, other Linux servers and networking devices, then you’ll have to define the networks from which this server will accept NTP synchronization requests. You do so with a modified restrict statement removing the noquery keyword to allow the network to query your NTP server. The syntax is:
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
In this case the mask statement has been expanded to include all 255 possible IP addresses on the local network.
We also want to make sure that localhost (the universal IP address used to refer to a Linux server itself) has full access without any restricting keywords
restrict 127.0.0.1
Save the file and exit
Now you need to run the ntpdate command against your server
#ntpdate ntp0.pipex.net
restart NTP for these settings to take effect using the following command
#/etc/init.d/ntp restart
You can now configure other Linux hosts on your network to synchronize with this new master NTP server in a similar fashion.
Determining If NTP Is Synchronized Properly
Use the ntpq command to see the servers with which you are synchronized. It provided you with a list of configured time servers and the delay, offset and jitter that your server is experiencing with them. For correct synchronization, the delay and offset values should be non-zero and the jitter value should be under 100.
#ntpq -p
Output looks like below
A star by any one of the names means that the system clock is synchronising with the NTP clock. If you don’t have a star (as in the example above) it means that the clocks are unreachable, already synchronized to this server or has an outrageous synchronization distance. Try running ntpdate (you will need to stop the ntp server) with your first ntp server as an argument. This will set your system clock fairly accuratly and mean that the server will be able to choose a clock to synchronize with.
Firewall Configuration for NTP
NTP servers communicate with one another using UDP with a destination port of 123. Unlike most UDP protocols, the source port isn’t a high port (above 1023), but 123 also. You’ll have to allow UDP traffic on source/destination port 123 between your server and the Stratum 1/2 server with which you are synchronizing.
NTP Client Configuration
If you want to configure ntp client you need to install the following packages
#apt-get install ntp ntp-simple ntpdate
Configuring NTP client
You need to edit the /etc/ntp.conf file you need to point the following settings to NTP server ip address
Server configuration settings
server 192.168.1.1
Restrict the type of access you allow these servers. In this example the servers are not allowed to modify the run-time configuration or query your Linux NTP server.
restrict default notrust nomodify nopeer
Localhost configuration
restrict 192.168.1.1
In this case the mask statement has been expanded to include all 255 possible IP addresses on the local network.
We also want to make sure that localhost (the universal IP address used to refer to a Linux server itself) has full access without any restricting keywords
restrict 127.0.0.1
Now you need to save and exit the file
run ntpdate command against your server
ntpdate 192.168.1.1
Restart ntp service using the following command
/etc/init.d/ntp restart
If you use the date command to change time, it is worth setting also the hardware clock to the correct time. Otherwise, the time is wrong after the next reboot, since the hardware clock keeps the time when power is turned off. When the clock in the operating system shows the correct time, set the hardware clock like this
#hwclock --systohc
se the ntpq command to see the servers with which you are synchronized
#ntpq
#ntpdc -p
Configure Linux NTP Time Synchronization Server In A Minute
Configure Linux NTP Time Synchronization Server In A Minute
Copyright © reserved by Walker on Thursday, March 8th, 2007 at 22:53 PM
You may not care about time synchronization of a personal computer, but it’s critical to most server applications. Hence, server system administrators have to ensure that NTP server is working at all time!
NTP, or Network Time Protocol, is a TCP/IP protocol used for time synchronization. NTP client (such as ntpdate) synchronize system time with designated NTP time servers (such as ntpd of Linux), which are generally classified in stratum 1 and stratum 2.
Stratum 1 NTP server is using an atomic clock for precise timing, while stratum 2 NTP server is using non-atomic clock that produce slightly less accurate timing. NTP.org is generally a creditable site for reference of public-available, Internet NTP time servers of both stratum 1 and stratum 2.
Steps to setup Linux NTP time synchronization
(applicable to Redhat, Debian, Linux / UNIX alike)
WalkerNews is a Linux machine in DMZ segment, running ntpd to synchronize its system time with Internet NTP servers, and is in turn function as a local master NTP server for other networked computer devices in the internal local area network.
WN2 is a Linux server in 172.20.1.x segment (internal local area network) that’s request time synchronization with WalkerNews via NTP client ntpdate.
1) Install Linux NTP time server ntpd and NTP client ntpdate that come with respective Linux distribution. For example,
Redhat Linux » rpm -Uvh ntp-4.1.2-4.EL3.1.rpm
Debian Sarge » apt-get install ntp
2) Edit WalkerNews Linux NTP server configuration file /etc/ntp.conf (create this file if it’s not exists)
a) Add in the at least two public NTP servers to reduce dependencies on any single external time server. For example,
server time.nist.gov
server stdtime.gov.hk
b) Define the way of these Internet NTP servers to behave. For example, following setting defined that Internet NTP servers are not allow to modify WalkerNews run-time configuration or query WalkerNews ntpd server:
restrict time.nist.gov mask 255.255.255.255 nomodify notrap noquery
restrict stdtime.gov.hk mask 255.255.255.255 nomodify notrap noquery
c) Since WalkerNews Linux NTP time server is also serving internal servers time synchronization, I’ll also have to define respective network segments which is sending NTP time synchronization requests to WalkerNews. For example,
restrict 172.20.1.0 mask 255.255.255.0 notrust nomodify notrap
This is to allow servers and/or networked devices in 172.20.1.x segment (with a maximum of 255 devices) sending NTP time synchronization requests to reach at WalkerNews Linux NTP server.
d) It’s also nice to allow 127.0.0.1 localhost to query WalkerNews Linux NTP server. The reason is to make troubleshooting easier, when it happens that other local servers are unable to synchronize time with WalkerNews.
restrict 127.0.0.1
e) That’s all for now. Save the ntp.conf file and restart ntpd time server with this command
Redhat Linux » service ntpd restart
Debian Sarge » /etc/init.d/ntp restart
It’ll takes some times to complete initial time synchronization, probably few ten seconds, when the ntpd starting for the first time. To confirm WalkerNews Linux NTP time server is synchronizing system clock with those Internet NTP servers specified in step 2a, try to execute ntpq -q command in root command prompt. If time synchronization is working fine, the ntpq -p command output (as shown below) should show non-zero figures in both delay and offset columns, while jitter value should be well below 100.
remote refid st t when poll reach delay offset jitter
=====================================================
time.nis 10.4.1.2 6 u 27 64 37 22.84 13.85 11.350
*LOCAL(0) LOCAL(0) 10 l 31 64 37 0.00 0.00 0.004
If ntpd time synchronization fails, try to replace FQDN of Internet NTP server with its IP address. Also, make sure that the firewall is not blocking NTP traffic.
Next, to confirm WN2 on 172.20.1.x segment is able to perform time synchronization with WalkerNews Linxu NTP time server, type ntpdate -q WalkerNews.net. This command output should show non-zero figures of both delay and offset as well. Otherwise, you’ll also see “no server suitable for synchronization found” error in the ntpdate -q command output!
Copyright © reserved by Walker on Thursday, March 8th, 2007 at 22:53 PM
You may not care about time synchronization of a personal computer, but it’s critical to most server applications. Hence, server system administrators have to ensure that NTP server is working at all time!
NTP, or Network Time Protocol, is a TCP/IP protocol used for time synchronization. NTP client (such as ntpdate) synchronize system time with designated NTP time servers (such as ntpd of Linux), which are generally classified in stratum 1 and stratum 2.
Stratum 1 NTP server is using an atomic clock for precise timing, while stratum 2 NTP server is using non-atomic clock that produce slightly less accurate timing. NTP.org is generally a creditable site for reference of public-available, Internet NTP time servers of both stratum 1 and stratum 2.
Steps to setup Linux NTP time synchronization
(applicable to Redhat, Debian, Linux / UNIX alike)
WalkerNews is a Linux machine in DMZ segment, running ntpd to synchronize its system time with Internet NTP servers, and is in turn function as a local master NTP server for other networked computer devices in the internal local area network.
WN2 is a Linux server in 172.20.1.x segment (internal local area network) that’s request time synchronization with WalkerNews via NTP client ntpdate.
1) Install Linux NTP time server ntpd and NTP client ntpdate that come with respective Linux distribution. For example,
Redhat Linux » rpm -Uvh ntp-4.1.2-4.EL3.1.rpm
Debian Sarge » apt-get install ntp
2) Edit WalkerNews Linux NTP server configuration file /etc/ntp.conf (create this file if it’s not exists)
a) Add in the at least two public NTP servers to reduce dependencies on any single external time server. For example,
server time.nist.gov
server stdtime.gov.hk
b) Define the way of these Internet NTP servers to behave. For example, following setting defined that Internet NTP servers are not allow to modify WalkerNews run-time configuration or query WalkerNews ntpd server:
restrict time.nist.gov mask 255.255.255.255 nomodify notrap noquery
restrict stdtime.gov.hk mask 255.255.255.255 nomodify notrap noquery
c) Since WalkerNews Linux NTP time server is also serving internal servers time synchronization, I’ll also have to define respective network segments which is sending NTP time synchronization requests to WalkerNews. For example,
restrict 172.20.1.0 mask 255.255.255.0 notrust nomodify notrap
This is to allow servers and/or networked devices in 172.20.1.x segment (with a maximum of 255 devices) sending NTP time synchronization requests to reach at WalkerNews Linux NTP server.
d) It’s also nice to allow 127.0.0.1 localhost to query WalkerNews Linux NTP server. The reason is to make troubleshooting easier, when it happens that other local servers are unable to synchronize time with WalkerNews.
restrict 127.0.0.1
e) That’s all for now. Save the ntp.conf file and restart ntpd time server with this command
Redhat Linux » service ntpd restart
Debian Sarge » /etc/init.d/ntp restart
It’ll takes some times to complete initial time synchronization, probably few ten seconds, when the ntpd starting for the first time. To confirm WalkerNews Linux NTP time server is synchronizing system clock with those Internet NTP servers specified in step 2a, try to execute ntpq -q command in root command prompt. If time synchronization is working fine, the ntpq -p command output (as shown below) should show non-zero figures in both delay and offset columns, while jitter value should be well below 100.
remote refid st t when poll reach delay offset jitter
=====================================================
time.nis 10.4.1.2 6 u 27 64 37 22.84 13.85 11.350
*LOCAL(0) LOCAL(0) 10 l 31 64 37 0.00 0.00 0.004
If ntpd time synchronization fails, try to replace FQDN of Internet NTP server with its IP address. Also, make sure that the firewall is not blocking NTP traffic.
Next, to confirm WN2 on 172.20.1.x segment is able to perform time synchronization with WalkerNews Linxu NTP time server, type ntpdate -q WalkerNews.net. This command output should show non-zero figures of both delay and offset as well. Otherwise, you’ll also see “no server suitable for synchronization found” error in the ntpdate -q command output!
2008年3月3日星期一
在Debian中架设PHP论坛
在Debian中架设PHP论坛
[ 2005-11-01 10:18:01 | Author: songzi ]
Font Size: Large | Medium | Small
在linux中架设论坛,当然要选择黄金组合Lamp(Linux/Apache/MySQL/PHP)了,
由于是初学,没有选编译安装,直接apt,感觉比windows下方便多了。
#apt-get install apache php4 php4-gd php4-mysql mysql-server mysql-client
敲一下回车,就安装完成了,如果在windows下在还得去各个官方网站下载安装包,真是麻烦。
好了,软件包是安装完成了,接下来就是调试了
先是配置apache,打开/etc/apache/httpd.conf ,找到DirectoryIndex 修改成:
DirectoryIndex index.html index.htm index.shtml index.cgi index.php default.php index.php3
其实是增加对默认主页的支持。
把默认字符改为:AddDefaultCharset gb2312,保存后重启apache。
#/etc/init.d/apache restart
接下来是配置mysql,由于默认的root 帐户,没有设密码,为了安全先给root加上密码:
#mysqladmin -u root password 'xxx'
再编辑/etc/init.d/mysql,找到这一行:
/usr/bin/safe_mysqld > /dev/null 2>&1 &
改成:/usr/bin/safe_mysqld > --default-character-set=gb2312 /dev/null 2>&1 &
重启mysql: # /etc/init.d/mysql restart
同理,修改/etc/php4/apache/php.ini ,将default_charset改为 "gb2312", 就行了。
和在windows下一样,先做个小测试,建立一个phpinfo.php 文件,里面 输入放在/var/www下面,再在浏览器里输入http://ip/phpinf.php 如果出现下php的一些信息,就说明php和apache已经成功配置了。
紧接着我们开始架设论坛,去www.phpbb.cn下载新版的phpbb中文版,回来后解压,接着在放在./var/www目录下,然后运行,就会出现安装论坛向导,在这里会要求你指定一个数据库名称,所以得先在mysql里新建一个数据库。
#mysql -u root -p password
mysql>create database bbs;
然后在安装页面,数据库一栏里输入bbs就行了。
运行:
attachments/200511/01_102233_php.jpg
很喜欢phpbb,到不是因为其它什么原因,只是因为它很漂亮,而且可以轻松的更换各种样式。
[ 2005-11-01 10:18:01 | Author: songzi ]
Font Size: Large | Medium | Small
在linux中架设论坛,当然要选择黄金组合Lamp(Linux/Apache/MySQL/PHP)了,
由于是初学,没有选编译安装,直接apt,感觉比windows下方便多了。
#apt-get install apache php4 php4-gd php4-mysql mysql-server mysql-client
敲一下回车,就安装完成了,如果在windows下在还得去各个官方网站下载安装包,真是麻烦。
好了,软件包是安装完成了,接下来就是调试了
先是配置apache,打开/etc/apache/httpd.conf ,找到DirectoryIndex 修改成:
DirectoryIndex index.html index.htm index.shtml index.cgi index.php default.php index.php3
其实是增加对默认主页的支持。
把默认字符改为:AddDefaultCharset gb2312,保存后重启apache。
#/etc/init.d/apache restart
接下来是配置mysql,由于默认的root 帐户,没有设密码,为了安全先给root加上密码:
#mysqladmin -u root password 'xxx'
再编辑/etc/init.d/mysql,找到这一行:
/usr/bin/safe_mysqld > /dev/null 2>&1 &
改成:/usr/bin/safe_mysqld > --default-character-set=gb2312 /dev/null 2>&1 &
重启mysql: # /etc/init.d/mysql restart
同理,修改/etc/php4/apache/php.ini ,将default_charset改为 "gb2312", 就行了。
和在windows下一样,先做个小测试,建立一个phpinfo.php 文件,里面 输入放在/var/www下面,再在浏览器里输入http://ip/phpinf.php 如果出现下php的一些信息,就说明php和apache已经成功配置了。
紧接着我们开始架设论坛,去www.phpbb.cn下载新版的phpbb中文版,回来后解压,接着在放在./var/www目录下,然后运行,就会出现安装论坛向导,在这里会要求你指定一个数据库名称,所以得先在mysql里新建一个数据库。
#mysql -u root -p password
mysql>create database bbs;
然后在安装页面,数据库一栏里输入bbs就行了。
运行:
attachments/200511/01_102233_php.jpg
很喜欢phpbb,到不是因为其它什么原因,只是因为它很漂亮,而且可以轻松的更换各种样式。
PHP初学者:配置Apache服务器并且设置DNS
PHP初学者:配置Apache服务器并且设置DNS
http://www.webjx.com 更新日期:2007-09-19 08:12 出处:网页教学网 作者:
当然主要有技术含量的是点DNS的解析,我正给我们公司负责,先查资料的说...‘
我们通常所说的虚拟主机技术就是将一台(或者一组)服务器的资源(系统资源、网络带宽、存储空间等)按照一定的比例分割成若干台相对独立的“小主机”的技术。每一台这样的“小主机”在功能上都可以实现WWW、FTP、Mail等基本的Internet服务,就像使用独立的主机一样。
目前网站服务器的虚拟主机平台使用以开放的Apache为最多,其次是微软的Windows IIS。Apache具有跨平台(FreeBSD/Linux/Windows/Solaris/Other UNIX)、易于维护与最佳安全性等优点。
Apache是率先支持基于IP虚拟主机的服务器之一。 Apache 1.1及其更新版本同时支持基于IP和基于主机名的虚拟主机,不同的虚拟主机有时会被称为基于主机(host-based) 或非IP虚拟主机(non-IP virtual hosts)。
用Apache设置虚拟主机服务通常可以采用两种方案:基于IP地址的虚拟主机和基于主机名字的虚拟主机,下面我们分别介绍一下它们的实现方法以及优缺点。以便大家在具体的应用中能够选择最合适的实现方法。
一、Apache实现基于IP地址的虚拟主机(每个站点拥有一个独立IP地址)
使用这种虚拟主机方式,首先要在服务器上为每个虚拟主机单独设置一个IP地址。这些IP地址可以通过增加多个网卡或者在一个网卡上设立多个IP地址来完成。有了多个IP地址后,可以采用以下两种方式之一来设置Apache。
1、为每个虚拟主机运行一份Apache
采用这种方式,每一份Apache程序可以以单独的用户运行,因此各个虚拟主机之间互不影响。设置这种虚拟主机时,只要为每一份Apache设置一套配置文件就可以了,唯一需要注意的是:必须使用“Listen”语句,强制每一份Apache 仅仅在属于“自己”的IP地址上接收服务请求。
优点:各个虚拟主机之间互不干扰,安全性高。
缺点:占用系统资源较多。
2、多个虚拟主机共享同一份Apache
采用这种方式,各个虚拟主机共享同一份Apache,因此各个虚拟主机之间有一定的影响,尤其是执行CGI程序时,可能会带来一些严重的安全问题。设置这种虚拟主机时,只要为每一个虚拟主机设置类似如下的信息即可:
DocumentRoot /www/ghq1
…
优点:占用系统资源比上一种方式少。
缺点:安全性低,每个虚拟主机仍然需要占用一个IP地址。
例如服务器一个网卡上绑定有两个IP地址(172.16.3.40和 172.16.3.50)分别对应域名 www.ghq1.com和www.ghq2.org的服务,配置如下:
服务器配置(apache的配置文件httpd.conf)
Listen 80
DocumentRoot /www/ghq1
ServerName www.ghq1.com
DocumentRoot /www/ghq2
ServerName www.ghq2.org
配置简单说明:“Listen”默认httpd服务会监控第80号通信端口, “Listen”选项让用户自行指定apache 服务器监控的IP地址或通信端口。
“DocumentRoot”:指定apache 服务器存放网页的根目录;“ServerName”:允许用户自行设置主机名,这个名称将被送到远程连接程序,以取代安装apache 服务器主机的真实名称。和 构成虚拟主机的语法结构,其中的IP就是我们在服务器上绑定的不同的IP地址,也可以是IP地址加上通信端口号(见下面的例子)。
如果服务器有两个IP地址(172.16.3.40和 172.16.3.50)分别对应域名 www.ghq1.com和www.ghq2.org。对每个域名,我们都希望在80端口和8080端口发布我们的网站。可以这样配置:
服务器配置(apache的配置文件httpd.conf)
Listen 172.16.3.40:80
Listen 172.16.3.40:8080
Listen 172.16.3.50:80
Listen 172.16.3.50:8080
DocumentRoot /www/ghq1-80
ServerName www.ghq1.com
DocumentRoot /www/ghq1-8080
ServerName www.ghq1.com
DocumentRoot /www/ghq2-80
ServerName www.ghq1.org
DocumentRoot /www/ghq2-8080
ServerName www.ghq2.org
因此,建立虚拟主机,我们要做好不同的IP对应的域名解析工作,建立相应的目录(如/www/ghq1),将相应的主页内容存放在相应的目录中即可。
二、Apache实现基于主机名的虚拟主机服务(一个IP地址实现多个网站)
基于主机名字的虚拟主机服务,是目前虚拟主机比较常用的一种方案。因为它不需要更多的IP地址,无须什么特殊的软硬件支持。而且现在的浏览器大都支持这种虚拟主机的实现方法。基于域名的的虚拟主机是根据客户端提交的HTTP头中的关于主机名的部分决定的。使用这种技术,很多虚拟主机可以享用同一个IP地址。
基于域名的虚拟主机相对比较简单,因为我们只需要配置DNS服务器将每个主机名映射(CNAMES)到正确的IP地址,然后配置Apache HTTP服务器,令其辨识不同的主机名就可以了。基于域名的服务器也可以缓解IP地址(IPV4)不足的问题。这种方式下,各个虚拟主机共享同一份 Apache,因此有CGI程序运行时,安全性也不高。
优点:只要一个IP地址就可以提供大量的虚拟主机服务。
缺点:安全性差。维护这些虚拟主机时需要更改配置文件,并且需要重新启动Apache进程才能起作用。因此不适合进行大规模的虚拟主机服务。
如果服务器只有一个IP地址,而在DNS中有很多映射到这个机器。我们想要在这个机器上运行www.ghq1.com和 www.ghq2.org两个站点。在Apache服务器的配置中创建一个虚拟主机并不会自动在DNS中对主机名做相应更新。我们必须自己在DNS中添加域名来指向我们的IP地址。否则别人是无法看到我们的web 站点。
服务器配置(apache的配置文件httpd.conf)
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *
DocumentRoot /www/ghq1
ServerName www.ghq1.com
# Other directives here
DocumentRoot /www/ghq2
ServerName www.ghq2.org
# Other directives here
因为*(星号)匹配所有的地址,所以主服务器不接收任何请求。因为 www.ghq1.com首先出现在配置文件中,所以它拥有最高优先级,可以认为是默认或首要服务器。这意味着如果一个接受的请求不能与某个ServerName指令相匹配, 它将会由第一个VirtualHost所伺服。
当我们的IP地址无法确定的时候,使用*是很方便的--比如说, ISP给我们配置的是动态IP地址(如ADSL拨号上网),而我们有使用了某种动态域名解析系统时。因为*匹配任何IP 地址,所以在这样的情况下,不论IP地址如何变化,我们都不需要另外进行配置。上述配置就是我们在绝大多数情况下使用基于域名的虚拟主机时将要用到的。
关于DNS和Apache
本文档的涵义一言以蔽之就是:不要让Apache在解析配置文件的时候用到DNS。 如果Apache在解析配置文件时用到了DNS,您的服务器就会发生可靠性的问题(也可能根本无法启动), 或者遭致拒绝(偷窃)服务攻击(包括用户可以从其他用户那里偷窃点击)。
一个简单示例
拒绝服务
"main server"地址
避免这些问题的小技巧
附录:进一步的提示
一个简单示例
ServerAdmin webgirl@abc.dom
DocumentRoot /www/abc
为了让Apache功能正常,一个虚拟主机绝对需要以下两部分的信息: ServerName和与服务器对应的至少一个IP地址。 这个示例没有包括IP地址,于是Apache必须用DNS来查询www.abc.dom的地址。 如果在某些不可预料的情况下,当您的服务器解析配置文件时没有得到DNS的支持, 那么这个虚拟主机 将不会被配置。 它将不会对任何请求作出反应。(在Apache的1.2版本之前,服务器甚至无法启动)。
假设www.abc.dom的IP地址是10.0.0.1。那么看看以下这个配置片断:
ServerAdmin webgirl@abc.dom
DocumentRoot /www/abc
现在Apache需要DNS对这个虚拟主机进行反向域名解析来确定ServerName。如果反向解析失败,那么这将导致这个虚拟主机部分功能丧失。 (在Apache的1.2版本之前,服务器将不能启动)。如果虚拟主机是基于域名的,它将完全不能使用,但如果它是基于IP的,那么它将很有可能工作。然而,如果Apache不得不为一个已经包含了服务器域名的服务器产生一个完整的URL, 那么它将可能产生一个无效的URL。
以下是一个可以避免上述两个问题的配置片断.
ServerName www.abc.dom
ServerAdmin webgirl@abc.dom
DocumentRoot /www/abc
拒绝服务
拒绝服务主要由(至少)两种形式导致。 如果您在运行Apache 1.2以前的版本,在上述两种情况下,如果您的任何一个虚拟主机的DNS解析失败,您都会无法启动服务。在一些情况下,DNS解析甚至不在您的控制范围之内。 比如说,如果abc.dom是您的一个客户,而且他们自己控制着DNS。那么仅仅是因为他们删除了www.abc.dom这个记录, 都会导致您的服务器(1.2之前的版本)无法启动。
另外一种形式就更隐蔽了。比如说下面这个配置片断:
ServerAdmin webgirl@abc.dom
DocumentRoot /www/abc
ServerAdmin webguy@def.dom
DocumentRoot /www/def
假设您已经为www.abc.dom设定了10.0.0.1, 而为www.def.dom设定了10.0.0.2。 更进一步,假设def.com自己控制DNS。在这种配置下, 您已经把def.com放到了一个可以将所有指向abc.com 的所有流量据为己有的情况之下。为了达到这样的目的, 他们只需要把www.def.dom的地址解析设置成10.0.0.1就可以了。 因为他们控制着自己的DNS服务, 所以您无法阻止他们把www.def.com这个记录指向任何一个IP地址。
然后,所有向10.0.0.1发出的请求 (包括用户所有类似http://www.abc.dom/任何字符的URL) 都将会为def.com这个虚拟主机所接收。 为了更好的理解着一切是怎样发生的, 您需要一个关于Apache是怎样将进入的请求分配给它的虚拟主机的深入说明。 您可以在这里发现一个完整的文档。
"main server"地址
在Apache 1.1中,基于域名的虚拟主机支持需要Apache知道运行着httpd的主机的IP地址。 一般来说可以用全局变量ServerName(如果存在) 或者调用C的方法gethostname(与在命令行模式下键入hostname得到的返回值一样)。接着它就会利用DNS来查找这个地址。目前还没有办法避免这样的查找。
如果您担心这样的查找会因为您的DNS服务器没有启动而遭到失败的结果, 您就可以在/etc/hosts中插入一条记录来确定主机名 (此文件中应该已经存在这条记录了,否则您的机器无法正常启动)。 然后,您要确认您的机器已经配置为当DNS解析失败的情况下,它将会使用/etc/hosts根据所使用的操作系统不同, 您可能需要在/etc/resolv.conf或/etc/nsswitch.conf 两个文件中选择一个进行编辑。
如果您的服务器不必因为其他理由而使用DNS,您也许不必在把HOSTRESORDER环境变量设置为"local"的情况下运行Apache。 这都取决于您所使用的操作系统和解析库。如果您没有使用mod_env来控制环境变量,它还将影响到CGI。 强烈建议您参考一下您所使用的操作系统附带的man帮助或FAQ。
避免这些问题的小技巧
在VirtualHost中使用IP地址
在Listen中使用IP地址
确保所有的虚拟主机拥有显式的ServerName定义。
创建一个不包含任何服务页面的服务器
附录:进一步的提示
涉及到DNS的情况都很让人不舒服。 在Apache 1.2 中,我们努力想让服务器在DNS解析失败的情况下至少保持能够启动, 但可能我们还是没能做到最好。在当今重编号成了必须的Internet上面, 在配置文件中显式的写明IP地址已经成为不合时宜的行为了。
上述盗窃攻击的解决办法是, 在一个正向的DNS查询结果后部署一个逆向DNS解析并将两个域名进行比较。 如果不同,就禁用相应的虚拟主机。这个方法需要一个正确配置了的逆向域名解析服务器 (因为FTP服务器和TCP封装进行的“双重逆向”DNS处理的普遍应用,这已为大部分管理员所熟知了)。
在某些情况下,如果没有使用IP地址而DNS解析又失败了, 那么正常启动一个基于域名的虚拟主机看来是不可能的。 一些诸如禁用部分配置文件这样的权宜之计会带来比根本不能启动更遭的不可预测的结果。
随着HTTP/1.1的部署以及浏览器和代理服务器开始支持Host头, 我们完全避免使用基于IP的虚拟主机也逐渐成为可能。这种状况下,web服务器也不必在配置时进行DNS的查询。 但在1997年3月,这些特性的采用还没有广泛到可以在重要的web服务器应用的地步。
http://www.uplinux.com/download/doc/apache/ApacheManual/dns-caveats.html#example
http://www.uplinux.com/download/doc/apache/ApacheManual/mod/core.html#virtualhost
和 用于封装一组仅施用于特定虚拟主机的指令。任何在虚拟主机配置中可以使用的指令也同样可以在这里使用。当服务器接受了一个特定虚拟主机的文档请求时,它会使用封装在配置段中的指令。地址可以是
虚拟主机的IP地址;
虚拟主机IP地址对应的完整域名;
字符*,仅与NameVirtualHost *配合使用以匹配所有 的IP地址;或是
字符串_default_,与基于IP的虚拟主机联用以捕获所 有没有匹配的IP地址。
示例
ServerAdmin webmaster@host.foo.com
DocumentRoot /www/docs/host.foo.com
ServerName host.foo.com
ErrorLog logs/host.foo.com-error_log
TransferLog logs/host.foo.com-access_log
IPv6的地址必须放入方括号中指定,否则作为可选项的端口号将无法确定。一个IPv6的示例如下:
ServerAdmin webmaster@host.foo.com
DocumentRoot /www/docs/host.foo.com
ServerName host.foo.com
ErrorLog logs/host.foo.com-error_log
TransferLog logs/host.foo.com-access_log
每个虚拟主机必须对应不同的IP地址、端口号或是不同的主机名。在第一种情况下,服务器所在物理机器必须配置为可以为多个地址接受IP包。(在机器没有多个网络硬件界面的情况下,如果您的操作系统支持,您可以使用ifconfig alias命令来达到这个目的。)。
当使用基于IP的虚拟主机时,特殊的名称_default_可以在没有匹配上其它列出的虚拟主机的情况下作为匹配任何IP地址的虚拟主机。在没有进行_default_虚拟主机的设定时,在没有IP与请求匹配的情况下,将使用“主服务器”(包括所有在虚拟主机配置段之外的配置)的配置。(但请注意:任何匹配NameVirtualHost指令的IP地址既不会使用"main"服务器配置,也不会使用_default_虚拟主机的配置。参阅基于域名的虚拟主机文档获得更多详情。)
您可以指定一个:端口来改变匹配的端口。如果没有指定,它将沿用主服务器中离它最近的那个Listen语句指定的值。您也可以指定:*来匹配那个地址上的所有端口。(当您使用_default_时,这是推荐采用的方法。)
安全提示:参阅安全提示文档获得为什么当您存储日志文件的目录对于启动服务器以外的用户来说是可写的会危及服务器安全的详细资料。
注意:的使用不会影响到Apache侦听的地址。您也许需要使用Listen来确保Apache侦听着正确的地址。
为调试程序,本机安装iis与apache,无法同时使用80端口,现给出解决方法:
方法一:
IIS5,多IP下共存,IIS为192.168.0.1,apache为192.168.0.2 原文地址
c:\Inetpub\Adminscripts
cscript adsutil.vbs set w3svc/disablesocketpooling true
该命令反馈如下disablesocketpooling : (BOOLEAN) True
重启IIS
Inetpub\AdminScripts>cscript adsutil.vbs set w3svc/disablesocketpooling true
由于 DisableSocketPooling 在 IIS 6.0 元数据库架构 (MBSchema.xml) 中被定义为有效属性,所以,您仍然可以使用 Adsutil.vbs 设置该属性,但这种设置不起作用。IIS 6.0 中的功能是新增的核心级别驱动程序 HTTP.sys 的一部分。要配置 HTTP.sys,您必须使用 Httpcfg.exe
方法二:
IIS6,多IP下共存,IIS为192.168.0.1,apache为192.168.0.2 原文地址
到2003的CD下的 support/tools/Support.cab。解压出httpcfg.exe文件,COPY到windows/system32/目录下,用法自己看帮助
命令行
绑定到某IP: httpcfg set iplisten -i 192.168.0.1
即命令使用IIS的只监听指定的IP及端口
查看绑定: httpcfg query iplisten
删除绑定: httpcfg delete iplisten -i 192.168.0.1
命令行
net stop Apache2
net stop iisadmin /y
net START Apache2
net START w3svc
保证iis下的ip设置为全局默认,Apache中httpconf设置listen 192.168.0.2:80,就应该可以两个服务同时运行,相互不冲突了。
IIS的访问地址为http://192.168.0.1,Apache访问地址为http://192.168.0.2
方法三:
网上常用的单IP共用80端口方法,不过不推荐,只是使用Apache的代理,速度有影响将apache设为使用80端口,IIS使用其它端口,比如81,然后将apache作为IIS的代理。
在httpd.conf里面,取消下面四行的注释:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
然后建立一个虚拟主机,将该域名的所有访问转向81端口。
ServerName iloves.vicp.net
ProxyPass / http://localhost:81/
ProxyPassReverse / http://localhost:81/
这样,对外就可以只需要一个端口,即可同时使用apache和IIS的功能了
类推,使用第二种方法,你可以在IIS上配置PHP4,Apache2中配置PHP5,只需要IIS中安装PHP4,把php.ini复制到\windows目录即可,这个就不用说了吧,Apache2中,只要把PHP5的php.ini放在PHP5安装目录里面就行了
配置Apache以支持PHP5:
LoadModule php5_module "D:/PHPServer/PHP5/php5apache2.dll"
AddType application/x-httpd-php .php
DirectoryIndex index.html index.php
PHPIniDir "D:/PHPServer/PHP5"
其中最重要的一条就是 PHPIniDir,用来指明php.ini文件所在位置,即PHP5的安装目录,注意所有目录的应该改为D:/PHPServer/PHP5这种格式,而非D:\PHPServer\PHP5,IIS的访问地址为http://192.168.0.1,Apache访问地址为http://192.168.0.2
http://www.webjx.com 更新日期:2007-09-19 08:12 出处:网页教学网 作者:
当然主要有技术含量的是点DNS的解析,我正给我们公司负责,先查资料的说...‘
我们通常所说的虚拟主机技术就是将一台(或者一组)服务器的资源(系统资源、网络带宽、存储空间等)按照一定的比例分割成若干台相对独立的“小主机”的技术。每一台这样的“小主机”在功能上都可以实现WWW、FTP、Mail等基本的Internet服务,就像使用独立的主机一样。
目前网站服务器的虚拟主机平台使用以开放的Apache为最多,其次是微软的Windows IIS。Apache具有跨平台(FreeBSD/Linux/Windows/Solaris/Other UNIX)、易于维护与最佳安全性等优点。
Apache是率先支持基于IP虚拟主机的服务器之一。 Apache 1.1及其更新版本同时支持基于IP和基于主机名的虚拟主机,不同的虚拟主机有时会被称为基于主机(host-based) 或非IP虚拟主机(non-IP virtual hosts)。
用Apache设置虚拟主机服务通常可以采用两种方案:基于IP地址的虚拟主机和基于主机名字的虚拟主机,下面我们分别介绍一下它们的实现方法以及优缺点。以便大家在具体的应用中能够选择最合适的实现方法。
一、Apache实现基于IP地址的虚拟主机(每个站点拥有一个独立IP地址)
使用这种虚拟主机方式,首先要在服务器上为每个虚拟主机单独设置一个IP地址。这些IP地址可以通过增加多个网卡或者在一个网卡上设立多个IP地址来完成。有了多个IP地址后,可以采用以下两种方式之一来设置Apache。
1、为每个虚拟主机运行一份Apache
采用这种方式,每一份Apache程序可以以单独的用户运行,因此各个虚拟主机之间互不影响。设置这种虚拟主机时,只要为每一份Apache设置一套配置文件就可以了,唯一需要注意的是:必须使用“Listen”语句,强制每一份Apache 仅仅在属于“自己”的IP地址上接收服务请求。
优点:各个虚拟主机之间互不干扰,安全性高。
缺点:占用系统资源较多。
2、多个虚拟主机共享同一份Apache
采用这种方式,各个虚拟主机共享同一份Apache,因此各个虚拟主机之间有一定的影响,尤其是执行CGI程序时,可能会带来一些严重的安全问题。设置这种虚拟主机时,只要为每一个虚拟主机设置类似如下的信息即可:
DocumentRoot /www/ghq1
…
优点:占用系统资源比上一种方式少。
缺点:安全性低,每个虚拟主机仍然需要占用一个IP地址。
例如服务器一个网卡上绑定有两个IP地址(172.16.3.40和 172.16.3.50)分别对应域名 www.ghq1.com和www.ghq2.org的服务,配置如下:
服务器配置(apache的配置文件httpd.conf)
Listen 80
DocumentRoot /www/ghq1
ServerName www.ghq1.com
DocumentRoot /www/ghq2
ServerName www.ghq2.org
配置简单说明:“Listen”默认httpd服务会监控第80号通信端口, “Listen”选项让用户自行指定apache 服务器监控的IP地址或通信端口。
“DocumentRoot”:指定apache 服务器存放网页的根目录;“ServerName”:允许用户自行设置主机名,这个名称将被送到远程连接程序,以取代安装apache 服务器主机的真实名称。
如果服务器有两个IP地址(172.16.3.40和 172.16.3.50)分别对应域名 www.ghq1.com和www.ghq2.org。对每个域名,我们都希望在80端口和8080端口发布我们的网站。可以这样配置:
服务器配置(apache的配置文件httpd.conf)
Listen 172.16.3.40:80
Listen 172.16.3.40:8080
Listen 172.16.3.50:80
Listen 172.16.3.50:8080
DocumentRoot /www/ghq1-80
ServerName www.ghq1.com
DocumentRoot /www/ghq1-8080
ServerName www.ghq1.com
DocumentRoot /www/ghq2-80
ServerName www.ghq1.org
DocumentRoot /www/ghq2-8080
ServerName www.ghq2.org
因此,建立虚拟主机,我们要做好不同的IP对应的域名解析工作,建立相应的目录(如/www/ghq1),将相应的主页内容存放在相应的目录中即可。
二、Apache实现基于主机名的虚拟主机服务(一个IP地址实现多个网站)
基于主机名字的虚拟主机服务,是目前虚拟主机比较常用的一种方案。因为它不需要更多的IP地址,无须什么特殊的软硬件支持。而且现在的浏览器大都支持这种虚拟主机的实现方法。基于域名的的虚拟主机是根据客户端提交的HTTP头中的关于主机名的部分决定的。使用这种技术,很多虚拟主机可以享用同一个IP地址。
基于域名的虚拟主机相对比较简单,因为我们只需要配置DNS服务器将每个主机名映射(CNAMES)到正确的IP地址,然后配置Apache HTTP服务器,令其辨识不同的主机名就可以了。基于域名的服务器也可以缓解IP地址(IPV4)不足的问题。这种方式下,各个虚拟主机共享同一份 Apache,因此有CGI程序运行时,安全性也不高。
优点:只要一个IP地址就可以提供大量的虚拟主机服务。
缺点:安全性差。维护这些虚拟主机时需要更改配置文件,并且需要重新启动Apache进程才能起作用。因此不适合进行大规模的虚拟主机服务。
如果服务器只有一个IP地址,而在DNS中有很多映射到这个机器。我们想要在这个机器上运行www.ghq1.com和 www.ghq2.org两个站点。在Apache服务器的配置中创建一个虚拟主机并不会自动在DNS中对主机名做相应更新。我们必须自己在DNS中添加域名来指向我们的IP地址。否则别人是无法看到我们的web 站点。
服务器配置(apache的配置文件httpd.conf)
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *
DocumentRoot /www/ghq1
ServerName www.ghq1.com
# Other directives here
DocumentRoot /www/ghq2
ServerName www.ghq2.org
# Other directives here
因为*(星号)匹配所有的地址,所以主服务器不接收任何请求。因为 www.ghq1.com首先出现在配置文件中,所以它拥有最高优先级,可以认为是默认或首要服务器。这意味着如果一个接受的请求不能与某个ServerName指令相匹配, 它将会由第一个VirtualHost所伺服。
当我们的IP地址无法确定的时候,使用*是很方便的--比如说, ISP给我们配置的是动态IP地址(如ADSL拨号上网),而我们有使用了某种动态域名解析系统时。因为*匹配任何IP 地址,所以在这样的情况下,不论IP地址如何变化,我们都不需要另外进行配置。上述配置就是我们在绝大多数情况下使用基于域名的虚拟主机时将要用到的。
关于DNS和Apache
本文档的涵义一言以蔽之就是:不要让Apache在解析配置文件的时候用到DNS。 如果Apache在解析配置文件时用到了DNS,您的服务器就会发生可靠性的问题(也可能根本无法启动), 或者遭致拒绝(偷窃)服务攻击(包括用户可以从其他用户那里偷窃点击)。
一个简单示例
拒绝服务
"main server"地址
避免这些问题的小技巧
附录:进一步的提示
一个简单示例
ServerAdmin webgirl@abc.dom
DocumentRoot /www/abc
为了让Apache功能正常,一个虚拟主机绝对需要以下两部分的信息: ServerName和与服务器对应的至少一个IP地址。 这个示例没有包括IP地址,于是Apache必须用DNS来查询www.abc.dom的地址。 如果在某些不可预料的情况下,当您的服务器解析配置文件时没有得到DNS的支持, 那么这个虚拟主机 将不会被配置。 它将不会对任何请求作出反应。(在Apache的1.2版本之前,服务器甚至无法启动)。
假设www.abc.dom的IP地址是10.0.0.1。那么看看以下这个配置片断:
ServerAdmin webgirl@abc.dom
DocumentRoot /www/abc
现在Apache需要DNS对这个虚拟主机进行反向域名解析来确定ServerName。如果反向解析失败,那么这将导致这个虚拟主机部分功能丧失。 (在Apache的1.2版本之前,服务器将不能启动)。如果虚拟主机是基于域名的,它将完全不能使用,但如果它是基于IP的,那么它将很有可能工作。然而,如果Apache不得不为一个已经包含了服务器域名的服务器产生一个完整的URL, 那么它将可能产生一个无效的URL。
以下是一个可以避免上述两个问题的配置片断.
ServerName www.abc.dom
ServerAdmin webgirl@abc.dom
DocumentRoot /www/abc
拒绝服务
拒绝服务主要由(至少)两种形式导致。 如果您在运行Apache 1.2以前的版本,在上述两种情况下,如果您的任何一个虚拟主机的DNS解析失败,您都会无法启动服务。在一些情况下,DNS解析甚至不在您的控制范围之内。 比如说,如果abc.dom是您的一个客户,而且他们自己控制着DNS。那么仅仅是因为他们删除了www.abc.dom这个记录, 都会导致您的服务器(1.2之前的版本)无法启动。
另外一种形式就更隐蔽了。比如说下面这个配置片断:
ServerAdmin webgirl@abc.dom
DocumentRoot /www/abc
ServerAdmin webguy@def.dom
DocumentRoot /www/def
假设您已经为www.abc.dom设定了10.0.0.1, 而为www.def.dom设定了10.0.0.2。 更进一步,假设def.com自己控制DNS。在这种配置下, 您已经把def.com放到了一个可以将所有指向abc.com 的所有流量据为己有的情况之下。为了达到这样的目的, 他们只需要把www.def.dom的地址解析设置成10.0.0.1就可以了。 因为他们控制着自己的DNS服务, 所以您无法阻止他们把www.def.com这个记录指向任何一个IP地址。
然后,所有向10.0.0.1发出的请求 (包括用户所有类似http://www.abc.dom/任何字符的URL) 都将会为def.com这个虚拟主机所接收。 为了更好的理解着一切是怎样发生的, 您需要一个关于Apache是怎样将进入的请求分配给它的虚拟主机的深入说明。 您可以在这里发现一个完整的文档。
"main server"地址
在Apache 1.1中,基于域名的虚拟主机支持需要Apache知道运行着httpd的主机的IP地址。 一般来说可以用全局变量ServerName(如果存在) 或者调用C的方法gethostname(与在命令行模式下键入hostname得到的返回值一样)。接着它就会利用DNS来查找这个地址。目前还没有办法避免这样的查找。
如果您担心这样的查找会因为您的DNS服务器没有启动而遭到失败的结果, 您就可以在/etc/hosts中插入一条记录来确定主机名 (此文件中应该已经存在这条记录了,否则您的机器无法正常启动)。 然后,您要确认您的机器已经配置为当DNS解析失败的情况下,它将会使用/etc/hosts根据所使用的操作系统不同, 您可能需要在/etc/resolv.conf或/etc/nsswitch.conf 两个文件中选择一个进行编辑。
如果您的服务器不必因为其他理由而使用DNS,您也许不必在把HOSTRESORDER环境变量设置为"local"的情况下运行Apache。 这都取决于您所使用的操作系统和解析库。如果您没有使用mod_env来控制环境变量,它还将影响到CGI。 强烈建议您参考一下您所使用的操作系统附带的man帮助或FAQ。
避免这些问题的小技巧
在VirtualHost中使用IP地址
在Listen中使用IP地址
确保所有的虚拟主机拥有显式的ServerName定义。
创建一个不包含任何服务页面的
附录:进一步的提示
涉及到DNS的情况都很让人不舒服。 在Apache 1.2 中,我们努力想让服务器在DNS解析失败的情况下至少保持能够启动, 但可能我们还是没能做到最好。在当今重编号成了必须的Internet上面, 在配置文件中显式的写明IP地址已经成为不合时宜的行为了。
上述盗窃攻击的解决办法是, 在一个正向的DNS查询结果后部署一个逆向DNS解析并将两个域名进行比较。 如果不同,就禁用相应的虚拟主机。这个方法需要一个正确配置了的逆向域名解析服务器 (因为FTP服务器和TCP封装进行的“双重逆向”DNS处理的普遍应用,这已为大部分管理员所熟知了)。
在某些情况下,如果没有使用IP地址而DNS解析又失败了, 那么正常启动一个基于域名的虚拟主机看来是不可能的。 一些诸如禁用部分配置文件这样的权宜之计会带来比根本不能启动更遭的不可预测的结果。
随着HTTP/1.1的部署以及浏览器和代理服务器开始支持Host头, 我们完全避免使用基于IP的虚拟主机也逐渐成为可能。这种状况下,web服务器也不必在配置时进行DNS的查询。 但在1997年3月,这些特性的采用还没有广泛到可以在重要的web服务器应用的地步。
http://www.uplinux.com/download/doc/apache/ApacheManual/dns-caveats.html#example
http://www.uplinux.com/download/doc/apache/ApacheManual/mod/core.html#virtualhost
虚拟主机的IP地址;
虚拟主机IP地址对应的完整域名;
字符*,仅与NameVirtualHost *配合使用以匹配所有 的IP地址;或是
字符串_default_,与基于IP的虚拟主机联用以捕获所 有没有匹配的IP地址。
示例
ServerAdmin webmaster@host.foo.com
DocumentRoot /www/docs/host.foo.com
ServerName host.foo.com
ErrorLog logs/host.foo.com-error_log
TransferLog logs/host.foo.com-access_log
IPv6的地址必须放入方括号中指定,否则作为可选项的端口号将无法确定。一个IPv6的示例如下:
ServerAdmin webmaster@host.foo.com
DocumentRoot /www/docs/host.foo.com
ServerName host.foo.com
ErrorLog logs/host.foo.com-error_log
TransferLog logs/host.foo.com-access_log
每个虚拟主机必须对应不同的IP地址、端口号或是不同的主机名。在第一种情况下,服务器所在物理机器必须配置为可以为多个地址接受IP包。(在机器没有多个网络硬件界面的情况下,如果您的操作系统支持,您可以使用ifconfig alias命令来达到这个目的。)。
当使用基于IP的虚拟主机时,特殊的名称_default_可以在没有匹配上其它列出的虚拟主机的情况下作为匹配任何IP地址的虚拟主机。在没有进行_default_虚拟主机的设定时,在没有IP与请求匹配的情况下,将使用“主服务器”(包括所有在虚拟主机配置段之外的配置)的配置。(但请注意:任何匹配NameVirtualHost指令的IP地址既不会使用"main"服务器配置,也不会使用_default_虚拟主机的配置。参阅基于域名的虚拟主机文档获得更多详情。)
您可以指定一个:端口来改变匹配的端口。如果没有指定,它将沿用主服务器中离它最近的那个Listen语句指定的值。您也可以指定:*来匹配那个地址上的所有端口。(当您使用_default_时,这是推荐采用的方法。)
安全提示:参阅安全提示文档获得为什么当您存储日志文件的目录对于启动服务器以外的用户来说是可写的会危及服务器安全的详细资料。
注意:
为调试程序,本机安装iis与apache,无法同时使用80端口,现给出解决方法:
方法一:
IIS5,多IP下共存,IIS为192.168.0.1,apache为192.168.0.2 原文地址
c:\Inetpub\Adminscripts
cscript adsutil.vbs set w3svc/disablesocketpooling true
该命令反馈如下disablesocketpooling : (BOOLEAN) True
重启IIS
Inetpub\AdminScripts>cscript adsutil.vbs set w3svc/disablesocketpooling true
由于 DisableSocketPooling 在 IIS 6.0 元数据库架构 (MBSchema.xml) 中被定义为有效属性,所以,您仍然可以使用 Adsutil.vbs 设置该属性,但这种设置不起作用。IIS 6.0 中的功能是新增的核心级别驱动程序 HTTP.sys 的一部分。要配置 HTTP.sys,您必须使用 Httpcfg.exe
方法二:
IIS6,多IP下共存,IIS为192.168.0.1,apache为192.168.0.2 原文地址
到2003的CD下的 support/tools/Support.cab。解压出httpcfg.exe文件,COPY到windows/system32/目录下,用法自己看帮助
命令行
绑定到某IP: httpcfg set iplisten -i 192.168.0.1
即命令使用IIS的只监听指定的IP及端口
查看绑定: httpcfg query iplisten
删除绑定: httpcfg delete iplisten -i 192.168.0.1
命令行
net stop Apache2
net stop iisadmin /y
net START Apache2
net START w3svc
保证iis下的ip设置为全局默认,Apache中httpconf设置listen 192.168.0.2:80,就应该可以两个服务同时运行,相互不冲突了。
IIS的访问地址为http://192.168.0.1,Apache访问地址为http://192.168.0.2
方法三:
网上常用的单IP共用80端口方法,不过不推荐,只是使用Apache的代理,速度有影响将apache设为使用80端口,IIS使用其它端口,比如81,然后将apache作为IIS的代理。
在httpd.conf里面,取消下面四行的注释:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
然后建立一个虚拟主机,将该域名的所有访问转向81端口。
ServerName iloves.vicp.net
ProxyPass / http://localhost:81/
ProxyPassReverse / http://localhost:81/
这样,对外就可以只需要一个端口,即可同时使用apache和IIS的功能了
类推,使用第二种方法,你可以在IIS上配置PHP4,Apache2中配置PHP5,只需要IIS中安装PHP4,把php.ini复制到\windows目录即可,这个就不用说了吧,Apache2中,只要把PHP5的php.ini放在PHP5安装目录里面就行了
配置Apache以支持PHP5:
LoadModule php5_module "D:/PHPServer/PHP5/php5apache2.dll"
AddType application/x-httpd-php .php
DirectoryIndex index.html index.php
PHPIniDir "D:/PHPServer/PHP5"
其中最重要的一条就是 PHPIniDir,用来指明php.ini文件所在位置,即PHP5的安装目录,注意所有目录的应该改为D:/PHPServer/PHP5这种格式,而非D:\PHPServer\PHP5,IIS的访问地址为http://192.168.0.1,Apache访问地址为http://192.168.0.2
2008年3月2日星期日
cherry blog
http://cherry.ur-solution.com/?p=509
1、先添加Debian的国内安装源:
在/etc/apt/sources.list
几个速度比较快的apt源中根据自己的情况添加:
教科网
中科大
deb http://debian.ustc.edu.cn/debian testing main non-free contrib
deb-src http://debian.ustc.edu.cn/debian testing main non-free contrib
deb http://debian.ustc.edu.cn/debian-non-US testing/non-US main non-free contrib
deb-src http://debian.ustc.edu.cn/debian-non-US testing/non-US main non-free contrib
deb http://debian.ustc.edu.cn/debian-security testing/updates main
公网
# ftp.linuxforum.net 61.152.210.194
deb ftp://ftp.linuxforum.net/debian/ unstable main non-free contrib
deb ftp://ftp.linuxforum.net/debian-non-US/ unstable/non-US main non-free contrib
# mirrors.geekbone.org 61.172.200.169
deb http://mirrors.geekbone.org/debian/ unstable main non-free contrib
deb http://mirrors.geekbone.org/debian-non-US/ unstable/non-US main non-free contrib
# debian.cn99.com 61.132.102.124
deb http://debian.cn99.com/debian/ unstable main non-free contrib
deb http://debian.cn99.com/debian-non-US/ unstable/non-US main non-free contrib
#
deb http://packages.dotdeb.org stable all
deb-src http://packages.dotdeb.org stable all
添加过后执行apt-get update更新可下载的软件列表。
安装Apache2/PHP/Mysql服务器
方式一:
apt-get install php5
apt-get install apache2
apt-get install mysql-server mysql-client
apt-get install php5-mysql php5-curl php5-gd
dpkg -l 'php5-*'
aptitude install libapache2-mod-php5 php5-mysql
3、/etc/apache2/httdpd.conf 添加:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
4、ln -s /etc/apache2/mods-available/php5.* /etc/apache2//mods-enabled
5、apt-get install apache2-mpm-prefork
6、/etc/init.d/apache2 restart
方式二:
11.安装Web/FTP服务器
安装操作需要以root用户来操作,需要装的软件有Apache2/php/mysql,ftp选用的是proftpd,另外有phpmyadmin和webalizer:
# apt-get install \
apache2-mpm-prefork \
libapache2-mod-php4 \
php4-pear \
php4-gd \
mysql-server \
mysql-client \
php4-mysql \
phpmyadmin \
proftpd \
webalizer
安装到Webalizer的时候,提示webalizer设置目录,填写/home/qingmedia/www/webalizer, 提示what is the filename of ...log时候,改为/var/log/apache2/access.log.1,因为apache2目录是/var/log/apache2。其他基本都按默认设置,回车即可。
12.安装Webmin管理软件
我对配置文件很头疼,因此喜欢webmin。我装了一大堆模块,如果用不上,可以去掉一些:
# apt-get install \
webmin-mailboxes \
webmin-htaccess \
webmin-bind \
webmin-exports \
webmin-quota \
webmin-virtual-server \
webmin-sshd \
webmin-inetd \
webmin-core \
webmin-mysql \
webmin-dhcpd \
webmin-fsdump \
webmin-slbackup \
webmin-ssl \
webmin-exim \
webmin-software \
webmin-logrotate \
webmin-samba \
webmin-grub \
webmin-firewall \
webmin-xinetd \
webmin-burner \
webmin-updown \
webmin-status \
webmin-webalizer \
webmin-adsl
一些模块有提示,我都是按默认的,因为不是很清楚。
二、软件配置
1.设置Webmin访问控制
webmin默认是只允许本地访问的,需要修改一下配置文件/etc/webmin/miniserv.conf
# nano /etc/webmin/miniserv.conf
把"allow=127.0.0.1"改为"allow="即可,重新启动webmin:
# /etc/init.d/webmin restart
2.设置mysql密码:
给mysql的root用户加密码(默认密码为空), (xxxxxx为新密码):
* mysqladmin -u root -p password xxxxxx
然后提示“Enter password:“,因原密码为空,因此直接敲回车键。
设置mysql默认语言:
3.修改/etc/mysql/my.cnf:
# nano /etc/mysql/my.cnf
在[mysqld]下加入一行“default-character-set=gbk“就可以正确查找汉字,否则在查单个汉字时,会出现错误的结果。
设置PHP
# nano /etc/php4/apache2/php.ini
4.修改register_globals:
把register_globals = Off 改为On (某些php程序需要这个设置)。
5.设置Apache2
默认的web网页目录在/var/www/,定义在/etc/apache2/sites-enabled/000-default中,我在前面把网页目录定在“/home/dvhome/www“,因此修改如下:
# nano /etc/apache2/sites-enabled/000-default
如DocumentRoot /var/www/改为 DocumentRoot /home/dvhome/www/,并取掉Indexs和重定向 RedirectMatch:
NameVirtualHost *
......
DocumentRoot /home/dvhome/www/
......
......
# RedirectMatch ^/$ /apache2-default/
......
......
三、网站资料上传
最后,把网页文件上传到/home/dvhome/www里面即可。
===========
1、先添加个源:
在/etc/apt/sources.list中添加:
deb http://packages.dotdeb.org stable all
deb-src http://packages.dotdeb.org stable all
apt-get update
2、apt-get install php5
apt-get install apache2
apt-get install mysql-server mysql-client
apt-get install php5-mysql php5-curl php5-gd
dpkg -l 'php5-*'
aptitude install libapache2-mod-php5 php5-mysql
3、/etc/apache2/httdpd.conf 添加:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
4、ln -s /etc/apache2/mods-available/php5.* /etc/apache2//mods-enabled
5、apt-get install apache2-mpm-prefork
6、/etc/init.d/apache2 restart
1、先添加Debian的国内安装源:
在/etc/apt/sources.list
几个速度比较快的apt源中根据自己的情况添加:
教科网
中科大
deb http://debian.ustc.edu.cn/debian testing main non-free contrib
deb-src http://debian.ustc.edu.cn/debian testing main non-free contrib
deb http://debian.ustc.edu.cn/debian-non-US testing/non-US main non-free contrib
deb-src http://debian.ustc.edu.cn/debian-non-US testing/non-US main non-free contrib
deb http://debian.ustc.edu.cn/debian-security testing/updates main
公网
# ftp.linuxforum.net 61.152.210.194
deb ftp://ftp.linuxforum.net/debian/ unstable main non-free contrib
deb ftp://ftp.linuxforum.net/debian-non-US/ unstable/non-US main non-free contrib
# mirrors.geekbone.org 61.172.200.169
deb http://mirrors.geekbone.org/debian/ unstable main non-free contrib
deb http://mirrors.geekbone.org/debian-non-US/ unstable/non-US main non-free contrib
# debian.cn99.com 61.132.102.124
deb http://debian.cn99.com/debian/ unstable main non-free contrib
deb http://debian.cn99.com/debian-non-US/ unstable/non-US main non-free contrib
#
deb http://packages.dotdeb.org stable all
deb-src http://packages.dotdeb.org stable all
添加过后执行apt-get update更新可下载的软件列表。
安装Apache2/PHP/Mysql服务器
方式一:
apt-get install php5
apt-get install apache2
apt-get install mysql-server mysql-client
apt-get install php5-mysql php5-curl php5-gd
dpkg -l 'php5-*'
aptitude install libapache2-mod-php5 php5-mysql
3、/etc/apache2/httdpd.conf 添加:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
4、ln -s /etc/apache2/mods-available/php5.* /etc/apache2//mods-enabled
5、apt-get install apache2-mpm-prefork
6、/etc/init.d/apache2 restart
方式二:
11.安装Web/FTP服务器
安装操作需要以root用户来操作,需要装的软件有Apache2/php/mysql,ftp选用的是proftpd,另外有phpmyadmin和webalizer:
# apt-get install \
apache2-mpm-prefork \
libapache2-mod-php4 \
php4-pear \
php4-gd \
mysql-server \
mysql-client \
php4-mysql \
phpmyadmin \
proftpd \
webalizer
安装到Webalizer的时候,提示webalizer设置目录,填写/home/qingmedia/www/webalizer, 提示what is the filename of ...log时候,改为/var/log/apache2/access.log.1,因为apache2目录是/var/log/apache2。其他基本都按默认设置,回车即可。
12.安装Webmin管理软件
我对配置文件很头疼,因此喜欢webmin。我装了一大堆模块,如果用不上,可以去掉一些:
# apt-get install \
webmin-mailboxes \
webmin-htaccess \
webmin-bind \
webmin-exports \
webmin-quota \
webmin-virtual-server \
webmin-sshd \
webmin-inetd \
webmin-core \
webmin-mysql \
webmin-dhcpd \
webmin-fsdump \
webmin-slbackup \
webmin-ssl \
webmin-exim \
webmin-software \
webmin-logrotate \
webmin-samba \
webmin-grub \
webmin-firewall \
webmin-xinetd \
webmin-burner \
webmin-updown \
webmin-status \
webmin-webalizer \
webmin-adsl
一些模块有提示,我都是按默认的,因为不是很清楚。
二、软件配置
1.设置Webmin访问控制
webmin默认是只允许本地访问的,需要修改一下配置文件/etc/webmin/miniserv.conf
# nano /etc/webmin/miniserv.conf
把"allow=127.0.0.1"改为"allow="即可,重新启动webmin:
# /etc/init.d/webmin restart
2.设置mysql密码:
给mysql的root用户加密码(默认密码为空), (xxxxxx为新密码):
* mysqladmin -u root -p password xxxxxx
然后提示“Enter password:“,因原密码为空,因此直接敲回车键。
设置mysql默认语言:
3.修改/etc/mysql/my.cnf:
# nano /etc/mysql/my.cnf
在[mysqld]下加入一行“default-character-set=gbk“就可以正确查找汉字,否则在查单个汉字时,会出现错误的结果。
设置PHP
# nano /etc/php4/apache2/php.ini
4.修改register_globals:
把register_globals = Off 改为On (某些php程序需要这个设置)。
5.设置Apache2
默认的web网页目录在/var/www/,定义在/etc/apache2/sites-enabled/000-default中,我在前面把网页目录定在“/home/dvhome/www“,因此修改如下:
# nano /etc/apache2/sites-enabled/000-default
如DocumentRoot /var/www/改为 DocumentRoot /home/dvhome/www/,并取掉Indexs和重定向 RedirectMatch:
NameVirtualHost *
......
DocumentRoot /home/dvhome/www/
......
......
# RedirectMatch ^/$ /apache2-default/
......
......
三、网站资料上传
最后,把网页文件上传到/home/dvhome/www里面即可。
===========
1、先添加个源:
在/etc/apt/sources.list中添加:
deb http://packages.dotdeb.org stable all
deb-src http://packages.dotdeb.org stable all
apt-get update
2、apt-get install php5
apt-get install apache2
apt-get install mysql-server mysql-client
apt-get install php5-mysql php5-curl php5-gd
dpkg -l 'php5-*'
aptitude install libapache2-mod-php5 php5-mysql
3、/etc/apache2/httdpd.conf 添加:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
4、ln -s /etc/apache2/mods-available/php5.* /etc/apache2//mods-enabled
5、apt-get install apache2-mpm-prefork
6、/etc/init.d/apache2 restart
在 Debian 安裝 Apache + MySQL + PHP
9
在 Debian 安裝 Apache + MySQL + PHP
tags | 人氣 : 380 | 文章分類 : 網站架設 |
最早先的時候,我使用 Debian 架設網站,後來評估使用外面的虛擬主機可以節省電腦,同時也省下很多的管理時間,所以租用了虛擬主機,一年的費用是 6000 元,的確是省下一些電費,但是也犧牲了很多的便利性、自主性。這半年下來,我發現其實一年節省電費大約 2 千元吧。平均一個月 1 百多元。但是犧牲的便利性卻讓我覺得不划算。
因為我不光只是架設 Blogs 而已,因為工作的關係,我需要 SVN 做專案的控管,光是這一點,虛擬主機就無法做到,所以又開始準備自己架設了,我依然愛好使用 Debian ,以前架設的時候,都沒有留下筆記,所以利用這次的機會作一個完整的過程記錄。
*
安裝 MySQL
apt-get install mysql-server
安裝完之後,不要忘記設定 root 帳號的密碼。
mysqladmin -u root password yourpassword
*
安裝 Apache 與 PHP5
apt-get install apache2 php5 php5-mysql php5-gd
安裝完之後,我們還要去修該 apache2 的參數。apache2 的預設站點是:/etc/apache2/sites-enabled/000-default,000-default 是一個 link, 指向到 /etc/apache2/sites-available/default , 這就是預設站點的地方。請注意 /etc/apache2/apache2.conf 為 Global 環境的設定,若要設定虛擬站台(default 亦為虛擬站台之一),至 /etc/apache2/sites-available 目錄下新增或修改。
因為 php5 預設沒有支援 mysql ,所以我們修改 php.ini ,請執行:vi /etc/php5/apache2/php.ini
將 ;extension=mysql.so 前面的 ; 取消
要如何驗證您的 php 已經可以工作了呢?請執行:
vim /var/www/apache2-default/test.php
輸入:
然後存檔,在瀏覽器中輸入: http://xxx.xxx.xxx.xxx/apache2-default/test.php
如果您可以看到 php 的版本資訊,那表示您的 php 已經可以工作了。
後記:
上面的測試網址,為什麼我們要加入:apache-default 呢?因為在 /etc/apache2/sites-enabled/000-default 設定中有下面的設定:
# This directive allows us to have apache2’s default start page
# in /apache2-default/, but still have / go to the right place
RedirectMatch ^/$ /apache2-default/
也就是說如果您的網址列只有輸入 / ,他會轉向到 apache2-default 目錄。您可以測試看看將這一行 mark 起來,然後重新啟動 apache2 ( /etc/init.d/apache2 restart ) ,然後再連線看看會有什麼變化。
在 Debian 安裝 Apache + MySQL + PHP
tags | 人氣 : 380 | 文章分類 : 網站架設 |
最早先的時候,我使用 Debian 架設網站,後來評估使用外面的虛擬主機可以節省電腦,同時也省下很多的管理時間,所以租用了虛擬主機,一年的費用是 6000 元,的確是省下一些電費,但是也犧牲了很多的便利性、自主性。這半年下來,我發現其實一年節省電費大約 2 千元吧。平均一個月 1 百多元。但是犧牲的便利性卻讓我覺得不划算。
因為我不光只是架設 Blogs 而已,因為工作的關係,我需要 SVN 做專案的控管,光是這一點,虛擬主機就無法做到,所以又開始準備自己架設了,我依然愛好使用 Debian ,以前架設的時候,都沒有留下筆記,所以利用這次的機會作一個完整的過程記錄。
*
安裝 MySQL
apt-get install mysql-server
安裝完之後,不要忘記設定 root 帳號的密碼。
mysqladmin -u root password yourpassword
*
安裝 Apache 與 PHP5
apt-get install apache2 php5 php5-mysql php5-gd
安裝完之後,我們還要去修該 apache2 的參數。apache2 的預設站點是:/etc/apache2/sites-enabled/000-default,000-default 是一個 link, 指向到 /etc/apache2/sites-available/default , 這就是預設站點的地方。請注意 /etc/apache2/apache2.conf 為 Global 環境的設定,若要設定虛擬站台(default 亦為虛擬站台之一),至 /etc/apache2/sites-available 目錄下新增或修改。
因為 php5 預設沒有支援 mysql ,所以我們修改 php.ini ,請執行:vi /etc/php5/apache2/php.ini
將 ;extension=mysql.so 前面的 ; 取消
要如何驗證您的 php 已經可以工作了呢?請執行:
vim /var/www/apache2-default/test.php
輸入:
然後存檔,在瀏覽器中輸入: http://xxx.xxx.xxx.xxx/apache2-default/test.php
如果您可以看到 php 的版本資訊,那表示您的 php 已經可以工作了。
後記:
上面的測試網址,為什麼我們要加入:apache-default 呢?因為在 /etc/apache2/sites-enabled/000-default 設定中有下面的設定:
# This directive allows us to have apache2’s default start page
# in /apache2-default/, but still have / go to the right place
RedirectMatch ^/$ /apache2-default/
也就是說如果您的網址列只有輸入 / ,他會轉向到 apache2-default 目錄。您可以測試看看將這一行 mark 起來,然後重新啟動 apache2 ( /etc/init.d/apache2 restart ) ,然後再連線看看會有什麼變化。
订阅:
博文 (Atom)