日期:2011-05-11 22:57:00  来源:本站整理

在Fedora 14中安装Lighttpd+PHP5+MySQL[服务器安全]

赞助商链接



  本文“在Fedora 14中安装Lighttpd+PHP5+MySQL[服务器安全]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:

Lighttpd是一款安全,高效,基于尺度且为高速环境计划的web服务器.这篇教程将教你如安在一台Fedora 14中安装Lighttpd+PHP5(FastCGI情势)+MySQL.
我已经测试无误,这将保证为你工作!

1 前言备注

在这篇教程中我利用的用户名是www.unixbar.net,IP地址是192.168.0.100.这些设置大概与你的有所差别,因此 你需求在得当的地方改正一下.

1.安装MySQL

[root@server ~]# yum -y install mysql mysql-server

为MySQL增添自启动,让MySQL伴随系统启动:

[root@server ~]# chkconfig --levels 235 mysqld on
[root@server ~]# /etc/init.d/mysqld start


为root用户设置一个密码(不然任何人都可以拜候到你的MySQL数据库):

[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): <--敲 ENTER键
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 ~]#

3.安装Lighttpd

Fedora官方源中默许有Lighttpd这个包,所以我们直接用下列号令安装:

[root@server ~]# yum -y install lighttpd

为Lighttpd成立自启动,让Lighttpd伴随系统启动

[root@server ~]# chkconfig --levels 235 lighttpd on
[root@server ~]# /etc/init.d/lighttpd start

目前你便可以在浏览器中直接拜候http://192.168.0.100了,就可以看到Lighttpd的预留页:

4 安装PHP5

我们让PHP5工作在Lighttpd的FastCGI情势下.因此我们安装lighttpd-fastcgi和php-cli这两个包:

yum install lighttpd-fastcgi php-cli

5 配置 Lighttpd 和 PHP5

要让PHP5和Lighttpd都正常工作,我们必须改正两个文件,/etc/php.ini 和/etc/lighttpd/lighttpd.conf.首先我们翻开/etc/php.ini,撤消评注cgi.fix_pathinfo=1这一行:

vi /etc/php.ini
[...]
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting
; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://www.php.net/manual/en/ini.core.php#ini.cgi.fix-pathinfo
cgi.fix_pathinfo=1
[...]

然后我们翻开/etc/lighttpd/lighttpd.conf这个文件,并撤消评注”mod_fastcgi”,在server.modules中:

vi /etc/lighttpd/lighttpd.conf
[...]
server.modules              = (
#                               "mod_rewrite",
#                               "mod_redirect",
#                               "mod_alias",
                                "mod_access",
#                               "mod_trigger_b4_dl",
#                               "mod_auth",
#                               "mod_status",
#                               "mod_setenv",
                                "mod_fastcgi",
#                               "mod_proxy",
#                               "mod_simple_vhost",
#                               "mod_evhost",
#                               "mod_userdir",
#                               "mod_cgi",
#                               "mod_compress",
#                               "mod_ssi",
#                               "mod_usertrack",
#                               "mod_expire",
#                               "mod_secdownload",
#                               "mod_rrdtool",
                                "mod_accesslog" )
[...]

下面,我们翻到这个文件的下边,我们一样对fastcgi.server这个参数撤消评注:

[...]
#### 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" => "/usr/bin/php-cgi"
                                 )
                               )
                            )
[...]

然后我们重启Lighttpd:

/etc/init.d/lighttpd restart

6.测试PHP5/得到PHP5安装的相关参数信息

目前在文档途径var/www/lighttpd中成立info.php文件,并在浏览器中拜候.这个文件会显示大量的PHP安装的信息,比方PHP的版本:

vi /var/www/lighttpd/info.php
<?php
phpinfo();
?>

目前我们在浏览器中拜候它(比方:http://192.168.0.100/info.php):

正如你在Server API这一行中所看到的一样,PHP5目前已经以FPM/FastCGI情势正常运行了.假如你持续向下翻看,你就可以过看到PHP5所支持的模块,此中未包含 MySQL模块:

7 让PHP5支持MySQL

我们安装php-mysql这个包既可以使MySQL支持php了.在这里最好也安装其他的PHP5模块,这些模块大概你会在其他的利用顶用到.你可以利用下列号令先搜索一下PHP5的模块:

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

目前在浏览器中革新http://192.168.0.100/info.php

,并再次翻到模块部份.你就应当能在这里找到很多新模块,此中就包含了MySQL模块:

8 相关链接

本文地址: 与您的QQ/BBS好友分享!
  • 好的评价 如果您觉得此文章好,就请您
      0%(0)
  • 差的评价 如果您觉得此文章差,就请您
      0%(0)

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
Copyright © 2020-2022 www.xiamiku.com. All Rights Reserved .