Chinaunix首页 | 论坛 | 博客
  • 博客访问: 8251336
  • 博文数量: 1413
  • 博客积分: 11128
  • 博客等级: 上将
  • 技术积分: 14685
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-13 10:03
个人简介

follow my heart...

文章分类

全部博文(1413)

文章存档

2013年(1)

2012年(5)

2011年(45)

2010年(176)

2009年(148)

2008年(190)

2007年(293)

2006年(555)

分类: LINUX

2010-02-02 09:51:49

Arch下面的东东多数是需要自己去配置的,在arch下面配一个apache服务器支持php,也要比其它的OS下面麻烦一些。好在arch有一个非常棒的wiki,这样一来,多数问题参考就可迎刃而解了。
本篇内容转自(简体中文),用户可以去那边做详细参考。

这个文档描述了怎样在Archlinux系统上安装设置Apache网页服务器。以及选择安装PHP和MySQL并集成到Apache服务器中。

如果你只是用来开发和测试, Xampp 可能更简便一些。

安装

# pacman -S apache php php-apache mysql

你可以只单独安装Apache,PHP或者MySQL,也可以安装所有包。这个文档假设你安装全部,当然你可以忽略任何部分。

Note: 新默认用户和用户组: 取代了原先的用户组group "nobody" ,现在默认以user/group "http" 来运行Apache。根据这个变化,需要调整httpd.conf,虽然仍然能够用nobody来运行httpd。

配置

配置Apache

  • 添加新用户http
# useradd -d /srv/http -r -s /bin/false -U http
  • 添加以下行到文件/etc/hosts (如果文件不存在,则创建一个新的):
127.0.0.1  localhost.localdomain   localhost

注意: 如果你想要不同的域名,在末尾追加以下行:

127.0.0.1  localhost.localdomain   localhost myhostname
  • 编辑 /etc/rc.conf: 如果第一步你设置了域名,那么HOSTNAME 变量应该一致,否则使用"localhost":
#
# Networking
#
STNAME="localhost"
H
O
  • 在Apache配置文件注释一个模块
# nano /etc/httpd/conf/httpd.conf

LoadModule unique_id_module        modules/mod_unique_id.so

注释为

#LoadModule unique_id_module        modules/mod_unique_id.so
  • 在终端以root用户运行:
# /etc/rc.d/httpd start
  • 那么现在Apache应该在运行了。在网页浏览器里测试下 。应该显示一个简单的Apache测试页面。
  • 编辑 /etc/rc.conf (设置Apache为开机运行):
DAEMONS=(... some daemons ... httpd)

或者 添加以下行到 /etc/rc.local:

/etc/rc.d/httpd start
  • 如果你想使某用户目录(比如~/public_html 在机器上通过~user/访问) 可以被访问,请在/etc/httpd/conf/extra/httpd-userdir.conf取消注释以下行:
UserDir public_html

AllowOverride FileInfo AuthConfig Limit Indexes
Options MultiViews Indexes SymLinksIfOwnerMatch ExecCGI
Order allow,deny
IONS PROPFIND>
Allow from all
T Order deny,allow Deny from all

请确认你的用户目录权限正确设置使apache可以访问,你的用户目录和~/public_html/必有要有可执行权限。这样就可以了:

$ chmod o+x ~
$ chmod o+x ~/public_html

如果你对安全问题很偏执的话,还有其它更安全的方法设置权限,可以创建一个只允许apache和你可以访问特别组。

高级选项

下面这些参数可以在/etc/httpd/conf/httpd.conf 中看到,有些可能你会感兴趣:

 # Listen 80

这是Apache监听的端口。对于通过路由器的网络,应该转发这个端口。

 # ServerAdmin sample@sample.com

这是管理员admin的email地址,可以在出错页面error-pages找到,比如.

 # DocumentRoot "/srv/http"

这是你网页存放的目录,可以改变它,改了之后,还要把这也改成相应的目录


配置PHP

PHP基本上可以使用的了.

  • /etc/httpd/conf/httpd.conf中添加:
把它们添加到 "LoadModule" 列表的后面或者文件的最后。
LoadModule php5_module modules/libphp5.so
Include /etc/httpd/conf/extra/php5_module.conf
Note: 如果在Apache的modules目录中没有libphp.so,请检查是否安装了php-apache包。
  • 如果你的DocumentRoot是在/home/以外地方,在/etc/php/php.ini添加这个open_basedir 成:
open_basedir = /home/:/tmp/:/usr/share/pear/:/path/to/documentroot
  • 重启Apache服务使修改生效(以root用户):
# /etc/rc.d/httpd restart
  • 用非常简单而又强大的脚本测试:
PHP Test Page >>
h Linux, running PHP. This is Ar
chpinfo(); ?>


保存此文件为test.php 复制到/srv/http/ 或 ~/public_html如果你允许此权限。当然请把它设置为可执行文件(chmod o+x test.php).

如果php脚本没有执行 (你看到了: ...),在/etc/httpd/conf/httpd.conf中添加:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

高级选项

  • 如果有需要默认解析.phtml文件,请记住在 /etc/httpd/conf/extra/php5_module.conf中添加.phtml:
 DirectoryIndex index.php index.phtml index.html
  • 如果你要libGD模块请把/etc/php/php.ini里的
;extension=gd.so

取消注释为

extension=gd.so
  • 如果你在调试PHP时需要显示PHP的错误信息,将 /etc/php/php.ini当中的这行:
 display_errors=Off

修改为

 display_errors=On
  • 如果你需要使用 mcrypt module,安装php-mcrypt包,并将 /etc/php/php.ini这行:
 ;extension=mcrypt.so
前面的注释取消
 extension=mcrypt.so

配置MySQL

如果只要设置支持MySQL,做以下步骤就行了,至于具体配置MySQL请参考: MySQL

  • 编辑/etc/php/php.ini (旧系统在/usr/etc里) to 取消注释如下行(移除;即可):
;extension=mysql.so
  • You can add minor privileged users for your web scripts by editing the tables found in the mysql database. You have to restart MySQL for changes to take effect. Don't forget to check the mysql/users table. If there's a second entry for root and your hostname is left with no password set, everybody from your host probably could gain full access. Perhaps see next section for these jobs.
  • 在终端下运行:
 # /etc/rc.d/mysqld start
  • 有必要的话重启Apache,在终端下运行:
 # /etc/rc.d/httpd restart
  • MySQL应该在运行了。设置 root 密码并进行测试:
# mysqladmin -u root password password
# mysql -u root -p
输入 exit 退出MySQL命令行客户端
  • 编辑 /etc/rc.conf (设置MySQL开机运行):
 DAEMONS=(... mysqld ...)

或者在 rc.local中添加:

 /etc/rc.d/mysqld start
  • You can get the "error no. 2013: Lost Connection to mysql server during query" message instantly whenever you try to connect to the MySQL daemon by TCP/IP. This is the TCP wrappers system (tcpd), which uses the hosts_access(5) system to allow or disallow connections.
  • 如果你出现这个问题,请在/etc/hosts.allow 添加以下行:
# mysqld : ALL : ALLOW
# mysqld-max : ALL : ALLOW
# and similar for the other MySQL daemons.
  • 注意: The examples above are the simplest case, telling tcpd to allow connections from anywhere. You may wish to use a more-appropriate choice of permissible sources instead of ALL. Just make sure that localhost and the IP address (numeric or DNS) of the interface by which you connect are specified.
  • 你可能需要编辑/etc/my.cnfskip-networking注释掉:
skip-networking

修改为

#skip-networking
阅读(1615) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~