安装Lighttpd与PHP5(PHP-FPM)和MySQL支持在Ubuntu 12.10

在Ubuntu 12.10上安装带有PHP5(PHP-FPM)和MySQL支持的Lighttpd

Lighttpd是一款安全,快速,符合标准的Web服务器,专为速度至关重要的环境而设计。 本教程将介绍如何在支持PHP5(通过PHP-FPM)和MySQL支持的Ubuntu 12.10服务器上安装Lighttpd。 PHP-FPM(FastCGI Process Manager)是一种替代的PHP FastCGI实现,具有对任何大小的网站(特别是繁忙的站点)有用的一些附加功能。 我在本教程中使用PHP-FPM,而不是Lighttpd的spawn-fcgi。

我不会保证这将为您工作!

1初步说明

在本教程中,我使用IP地址为192.168.0.100的hostname server1.example.com 。 这些设置可能会有所不同,因此您必须在适当的情况下更换它们。

我使用root权限运行本教程中的所有步骤,因此请确保以root用户身份登录:

sudo su

2安装MySQL 5

首先我们像这样安装MySQL 5:

apt-get install mysql-server mysql-client

您将被要求为MySQL root用户提供密码 - 此密码对用户root @ localhost以及root@server1.example.com有效 ,因此我们不必在以后手动指定MySQL根密码:

MySQL“root”用户的新密码: < - yourrootsqlpassword
重复MySQL“root”用户的密码: < - yourrootsqlpassword

3安装Lighttpd

Lighttpd可作为Ubuntu软件包使用,因此我们可以像这样安装:

apt-get install lighttpd

现在直接浏览器到http://192.168.0.100/index.lighttpd.html ,你应该看到Lighttpd占位符页面:

Lighttpd的默认文档根目录是Ubuntu上的/ var / www ,配置文件为/etc/lighttpd/lighttpd.conf 。 其他配置存储在/ etc / lighttpd / conf-available目录中的文件中 - 可以使用lighttpd-enable-mod命令启用这些配置,该命令从/ etc / lighttpd / conf-enabled目录创建符号链接到适当的配置/ etc / lighttpd / conf-available中的文件 。 您可以使用lighttpd-disable-mod命令禁用配置。

4安装PHP5

我们可以通过PHP-FPM使PHP5在Lighttpd中工作,我们安装如下:

apt-get install php5-fpm php5

PHP-FPM是在/var/run/php5-fpm.socksocket上运行FastCGI服务器的守护进程(初始脚本/etc/init.d/php5-fpm )。

5配置Lighttpd和PHP5

要在Lighttpd中启用PHP5,我们必须修改/etc/php5/fpm/php.ini并取消注释行cgi.fix_pathinfo = 1

vi /etc/php5/fpm/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://php.net/cgi.fix-pathinfo
cgi.fix_pathinfo=1
[...]

PHP /etc/lighttpd/conf-available/15-fastcgi-php.conf的Lighttpd配置文件适用于spawn-fcgi,但是,我们要使用PHP-FPM,因此我们创建一个文件的备份(命名为15-fastcgi-php-spawnfcgi.conf )并修改15-fastcgi-php.conf ,如下所示:

cd /etc/lighttpd/conf-available/
cp 15-fastcgi-php.conf 15-fastcgi-php-spawnfcgi.conf
vi 15-fastcgi-php.conf
# /usr/share/doc/lighttpd-doc/fastcgi.txt.gz
# http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ConfigurationOptions#mod_fastcgi-fastcgi

## Start an FastCGI server for php (needs the php5-cgi package)
fastcgi.server += ( ".php" =>
        ((
                "socket" => "/var/run/php5-fpm.sock",
                "broken-scriptfilename" => "enable"
        ))
)

要启用fastcgi配置,请运行以下命令:

lighttpd-enable-mod fastcgi
lighttpd-enable-mod fastcgi-php

这将创建符号链接/etc/lighttpd/conf-enabled/10-fastcgi.conf ,它们指向/etc/lighttpd/conf-available/10-fastcgi.conf/ etc / lighttpd / conf-enabled / 15-fastcgi-php .conf指向/etc/lighttpd/conf-available/15-fastcgi-php.conf

ls -l /etc/lighttpd/conf-enabled
root@server1:/etc/lighttpd/conf-available# ls -l /etc/lighttpd/conf-enabled
total 0
lrwxrwxrwx 1 root root 33 Nov  4 13:40 10-fastcgi.conf -> ../conf-available/10-fastcgi.conf
lrwxrwxrwx 1 root root 37 Nov  4 13:40 15-fastcgi-php.conf -> ../conf-available/15-fastcgi-php.conf
root@server1:/etc/lighttpd/conf-available#

然后我们重新加载Lighttpd:

/etc/init.d/lighttpd force-reload
赞(52) 打赏
未经允许不得转载:优客志 » 系统运维
分享到:

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏