在CentOS 5.6 上安装 Lighttpd + PHP5 + MySQL
CentOS 6.0 已经发布,但是不敢保证能安装顺利,还是先在CentOS 5.6 上安装,lighttpd是一个安全,快速,标准的Web服务器。本教程演示如何安装一台CentOS 5.6的web服务器与PHP5支持(通过的FastCGI)和MySQL支持lighttpd的。
1.初步说明
在本教程中我使用主机名server1.example.com,IP 地址 192.168.0.100 。这些设置可能会有所不同,所以你必须在适当情况下替换他们。
2,安装MySQL 5.0
首先,我们安装了MySQL 5.0,像这样:yum install mysql mysql-server
然后为MySQL创建系统启动链接(这样MySQL在系统启动时,就可以自动启动,),并启动MySQL服务器:chkconfig --levels 235 mysqld on<br />/etc/init.d/mysqld start
为MySQL root帐户设置密码:mysql_secure_installation
[root@server1 ~]# mysql_secure_installation
终端会由如下显示,红色的部分是操作提示:
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we’ll need the current
password for the root user. If you’ve just installed MySQL, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] <– ENTER
New password: <– 输入密码
Re-enter new password: <– 再输入一次密码
Password updated successfully!
Reloading privilege tables..
… Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] <– ENTER
… Success!
Normally, root should only be allowed to connect from ’localhost’. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] <– ENTER
… Success!
By default, MySQL comes with a database named ’test’ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] <– ENTER
- Dropping test database…
… Success!
- Removing privileges on test database…
… Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] <– ENTER
… Success!
Cleaning up…
All done! If you’ve completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
[root@server1 ~]#
(network.c.203) socket failed: Address family not supported by protocol
… … 打开/ etc /的lighttpd / lighttpd.conf的 … …vi /etc/lighttpd/lighttpd.conf
… … 改变server.use从启用的IPv6禁用 :[...]<br />##<br />## Use IPv6?<br />##<br />server.use-ipv6 = "disable"<br />[...]
然后尝试再次启动lighttpd – 应该没有任何问题:
/etc/init.d/lighttpd start
现在直接到http://192.168.0.100您的浏览器,你应该看到以下页面:
Lighttpd默认web根目录: /srv/www/lighttpd (上面的页面制作显示404错误,是因为没有主页index.html), 配置文件 /etc/lighttpd/lighttpd.conf 。
4.安装php,我们可以在通过FastCGI的Lighttpd的PHP5的工作。yum install lighttpd-fastcgi php-cli
5.配置lighttpd和PHP5vi /etc/php.ini
[...]
cgi.fix_pathinfo = 1
配置/etc/lighttpd/modules.confvi /etc/lighttpd/modules.conf
[...]
##
## FastCGI (mod_fastcgi)
##
include “conf.d/fastcgi.conf”
[...]
vi /etc/lighttpd/conf.d/fastcgi.conf
[...]
fastcgi.server = ( “.php” =>
( “php-local” =>
(
“socket” => “/tmp/php-fastcgi-1.socket”,
“bin-path” => “/usr/bin/php-cgi”,
“max-procs” => 1,
“broken-scriptfilename” => “enable”,
)
),
( “php-tcp” =>
(
“host” => “127.0.0.1″,
“port” => 9999,
“check-local” => “disable”,
“broken-scriptfilename” => “enable”,
)
),( “php-num-procs” =>
(
“socket” => “/tmp/php-fastcgi-2.socket”,
“bin-path” => “/usr/bin/php-cgi”,
“bin-environment” => (
“PHP_FCGI_CHILDREN” => “16″,
“PHP_FCGI_MAX_REQUESTS” => “10000″,
),
“max-procs” => 5,
“broken-scriptfilename” => “enable”,
)
),
)
[...]
然后我们重新启动Lighttpd/etc/init.d/lighttpd restart
6.测试PHP5/获取PHP5安装的细节
默认的Web站点的文档根目录是/SRV/WWW/lighttpd的 。现在,我们将在该目录中创建一个小型PHP文件(info.php),并在浏览器中调用它 。该文件将显示很多有用的细节,我们的PHP安装,如安装的PHP版本。
vi /srv/www/lighttpd/info.php
现在,在浏览器(如文件http://192.168.0.100/info.php):
7.获得在PHP5 MySQL支持
搜索模块:yum search php
安装模块:yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
重启lighttpd:/etc/init.d/lighttpd restart