a) 下载各个软件
系统环境:Centos 6.2
Lighttpd:lighttpd-1.4.8 Php:php-5.2.10 Mysql:mysql-5.5.20
b) 安装Lighttpd
tar -zxvf lighttpd-1.4.8.tar.gz cd lighttpd-1.4.8 ./configure --prefix=/usr/local/lighttpd make make install
c) 配置Lighttpd
mkdir /etc/lighttpd 用来存放主配置文件 mkdir –p /usr/local/lighttpd/www/htdocs 用来存放网站 mkdir /usr/local/lighttpd/log 用来存放日志 cp /usr/local/src/lighttpd-1.4.8/doc/sysconfig.lighttpd /etc/sysconfig/lighttpd vi /etc/sysconfig/lighttpd 修改所在路径为 lighttpd="/etc/lighttpd/lighttpd.conf" cp /usr/local/src/lighttpd-1.4.8/doc/lighttpd.conf /etc/lighttpd/lighttpd.conf cp /usr/local/src/lighttpd-1.4.8/doc/rc.lighttpd.redhat /etc/rc.d/init.d/lighttpd
编辑:
#lighttpd="/usr/sbin/lighttpd" #修改为 lighttpd="/usr/local/lighttpd/sbin/lighttpd" chkconfig lighttpd on
vi lighttpd.conf(修改主配置文件)
(1)修改默认目录路径
设置错误日志文件路径
server.errorlog = "/usr/local/lighttpd/log/lighttpd.error.log" (43行)
设置访问日志文件路径
accesslog.filename = "/usr/local/lighttpd/log/access.log" (116行)
(2)修改端口号 (默认为80)
把#server.port = 81 前的#去掉
(3)用什么权限来运行lighttpd
server.username = "lighttpd" server.groupname = "lighttpd"
从安全角度来说,不建议用root权限运行web server,可以指定普通用户权限。
(后面创建用户)
(4)
#$HTTP["url"] =~ "/.pdf$" { # server.range-requests = "disable" #}
创建lighttpd用户
useradd lighttpd chown –R lighttpd:lighttpd /usr/local/lighttpd chown –R lighttpd:lighttpd /usr/local/lighttpd/www/htdocs
d) 安装php
GD库(共6 + 1 = 7个)
(1)zlib (2)jpeg6 mkdir /opt/jpeg6/ mkdir /opt/jpeg6/bin/ mkdir /opt/jpeg6/lib/ mkdir /opt/jpeg6/include/ mkdir /opt/jpeg6/man/ mkdir /opt/jpeg6/man1/ mkdir /opt/jpeg6/man/man1/ ./configure --prefix=/opt/jpeg6/ --enable-shared --enable-static make install-lib (3)libpng (4)freetype (参数:--prefix=/opt/freetype/) (5)libxml2 cp xml2-config /usr/bin (6)fontconfig
(参数:--prefix=/opt/fontconfig --with-freetype-config=/opt/freetype/bin/freetype-config)
最后按照GD,把上面6个关联起来,顺序与上面对应:
(7)gd
(参数:--prefix=/opt/gd --with-zlib-dir --with-jpeg=/opt/jpeg6/ --with-png-dir --with-freetype=/opt/freetype/ --with-libxml2-dir --with-fontconfig=/opt/fontconfig/)
cd /usr/local/src/php5.2.17 mkdir -p /usr/local/php5 ./configure --prefix=//usr/local/php5 --enable-fastcgi --enable-force-cgi-redirect --with-mysql=/usr/local/mysql/ --with-libxml-dir make make test make install
e)配置php
cp php.ini-dist /usr/local/php5/lib/php.ini
f) 将lighttpd和php关联
修改php.ini
vi /usr/local/php5/lib/php.ini cgi.fix_pathinfo=1
查找register_globals = Off,把off改成On
再查找short_open_tag = Off,把off改成On
在查找extension=php_mbstring.dll把前面"#"号都去了,这样才能启动这条参数的功能。
比如要使PHP支持mysql,那么就要吧extension=php_mysql.dll前面的"#"去掉。
修改lighttpd.conf
vim /etc/lighttpd/lighttpd.conf
在lighttpd的主配置文件里,修改与php相关联的内容
server.modules(在24行)
取消需要用到模块的注释:mod_rewrite,mod_access,mod_fastcgi,mod_simple_vhost,mod_cgi,mod_compress,mod_accesslog是一般需要用到的。
设置网站根目录路径
server.document-root = "/usr/local/lighttpd/www/htdocs"
找到fastcgi的定义
#### fastcgi module ## read fastcgi.txt for more info ## for PHP don't forget to set cgi.fix_pathinfo = 1 in the php.ini fastcgi.server = ( ".php" => ( "localhost" => ( "socket" => "/var/run/lighttpd/php-fastcgi.socket", "bin-path" => "/opt/php/bin/php-cgi" ) ) )
g)进行测试
在/usr/local/lighttpd/www/htdocs/中创建一个文件index.php,编辑内容如下:
<?php phpinfo(); ?>
启动服务lighttpd
在地址栏输入
http://127.0.0.1:81/index.php
即可打开一个页面
h) mysql安装
tar -zxvf mysql5.5.20.tar.gz cd mysql5.5.20 ./configure --prefix=/usr/lcoal/mysql make make install
i)配置mysql
cp ./support-files/my-medium.cnf /etc/my.cnf cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld chmod 755 /etc/rc.d/init.d/mysqld useradd mysql chown –R mysql:mysql /opt/mysql chown –R mysql:mysql /etc/my.cnf
修改/etc/my.cnf文件,配置端口号(3306)和socket(/tmp/mysql.sock)
./bin/mysql_install_db --basedir=/opt/mysql --datadir=/opt /mysql/data --user=mysql(初始化数据库)
mysql与lighttpd、php的相关联,仅仅在安装php时 ./configure 加上
--with-mysql=/opt/mysql/ 就可以了。
之后启动
/etc/init.d/mysqld start
修改密码
/opt/mysql/bin/mysqladmin –u root password “My_Own_Password”
登录mysql
/opt/mysql/bin/mysql –u root –p
j) 测试php与mysql相连接
先在mysql中创建一个数据库”mydb”,然后修改刚才的index.php文件
$dbhost = ‘localhost’; $dbuser = ‘root’; $dbpassword = ‘My_Own_Password’; $dbname = ‘mydb’; $connect = mysql_connect($dbhost, $dbuser, $dbpassword, $dbname); if($connect) { echo “succeed”; } else { echo “failed”; } ?>
之后在浏览器中输入127.0.0.1:81/index.php,如果成功的话,就说明数据库连接成功