nginx php 5.5 安装,nginx连接PHP 5.5 – ttlsa教程系列之nginx

摘要

PHP从一开始的php 5.2到现在的5.3/5.4/5.5.起草这篇文章的时候发现官方已经停止了5.3的开发,最后的版本定格到了5.3.27,只会修复一些bug,宣告了5.3寿终正寝了.并且建议大家升级到5.4或者5.5, 鉴于版本更新得如此之快,决定写一片nginx连接php5.5的文章.于是乎,本草文写完了. 1. 安装PHP 5.5.0 下载

这两年IT更新换代的速度太快了,nginx从2年前的1.0版本到现在的1.5版本,各个版本共同开发。PHP从一开始的php 5.2到现在的5.3/5.4/5.5.起草这篇文章的时候发现官方已经停止了5.3的开发,最后的版本定格到了5.3.27,只会修复一些bug,宣告了5.3寿终正寝了.并且建议大家升级到5.4或者5.5, 鉴于版本更新得如此之快,决定写一片nginx连接php5.5的文章.于是乎,本草文写完了.

1. 安装PHP 5.5.0

下载

cd /usr/local/src/

wget http://www.php.net/get/php-5.5.0.tar.bz2/from/jp1.php.net/mirror

1

2

cd/usr/local/src/

wgethttp://www.php.net/get/php-5.5.0.tar.bz2/from/jp1.php.net/mirror

# 如果以上PHP不存在了,大家可以直接到官方下载. 如果还是找不到可以留言,我将会通过邮箱发送.

安装依赖包

确保安装之前有安装gd,png,curl,xml等等lib开发库。如果不确定,执行以下命令:

yum install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel -y

1

yuminstallgccmakegd-devellibjpeg-devellibpng-devellibxml2-develbzip2-devellibcurl-devel-y

编译安装PHP 5.5.0

以下参数支持,ftp,图片函数,pdo等支持,因为使用了php自带的mysqlnd,所以不需要额外安装mysql的lib库了.如果你是64位系统,参数后面加上--with-libdir=lib64,如果不是可以跳过。

tar -xjf php-5.5.0.tar.bz2

cd php-5.5.0

./configure --prefix=/usr/local/php-5.5.0 --with-config-file-path=/usr/local/php-5.5.0/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64

make

make install

1

2

3

4

5

tar-xjfphp-5.5.0.tar.bz2

cdphp-5.5.0

./configure--prefix=/usr/local/php-5.5.0--with-config-file-path=/usr/local/php-5.5.0/etc--with-bz2--with-curl--enable-ftp--enable-sockets--disable-ipv6--with-gd--with-jpeg-dir=/usr/local--with-png-dir=/usr/local--with-freetype-dir=/usr/local--enable-gd-native-ttf--with-iconv-dir=/usr/local--enable-mbstring--enable-calendar--with-gettext--with-libxml-dir=/usr/local--with-zlib--with-pdo-mysql=mysqlnd--with-mysqli=mysqlnd--with-mysql=mysqlnd--enable-dom--enable-xml--enable-fpm--with-libdir=lib64

make

makeinstall

备注:如果PHP不需要curl和ftp的支持,可以将以上的--with-curl --enable-ftp去掉. 如果你是专业的linux从业人员,你完全可以看着help来选择你的安装参数,如果你不是的话,我建议你直接复制黏贴我的配置参数.这样可以少走一些弯路.

配置php

cp php.ini-production /usr/local/php-5.5.0/etc/php.ini

cp /usr/local/php-5.5.0/etc/php-fpm.conf.default /usr/local/php-5.5.0/etc/php-fpm.conf

1

2

cpphp.ini-production/usr/local/php-5.5.0/etc/php.ini

cp/usr/local/php-5.5.0/etc/php-fpm.conf.default/usr/local/php-5.5.0/etc/php-fpm.conf

启动php-fpm

/usr/local/php-5.5.0/sbin/php-fpm

1

/usr/local/php-5.5.0/sbin/php-fpm

执行以上命令,如果没报错一般情况下表示启动正常,如果不放心,也可以通过端口判断是PHP否启动

# netstat -lnt | grep 9000

tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN

1

2

# netstat -lnt | grep 9000

tcp00127.0.0.1:90000.0.0.0:*LISTEN

2、安装配置nginx

安装nginx

请看

配置测试站点test.ttlsa.com

mkdir /data/logs/nginx/ # 用于存放nginx日志.请看2.3的配置文件

mkdir -p /data/site/test.ttlsa.com/ # 站点根目录

vim /data/site/test.ttlsa.com/info.php

phpinfo();

?>

1

2

3

4

5

6

mkdir/data/logs/nginx/# 用于存放nginx日志.请看2.3的配置文件

mkdir-p/data/site/test.ttlsa.com/# 站点根目录

vim/data/site/test.ttlsa.com/info.php

phpinfo();

?>

保存退出

nginx配置

在nginx.conf的http断中加上如下内容:

server {

listen 80;

server_name test.ttlsa.com;

access_log /data/logs/nginx/test.ttlsa.com.access.log main;

index index.php index.html index.html;

root /data/site/test.ttlsa.com;

location /

{

try_files $uri $uri/ /index.php?$args;

}

location ~ .*\.(php)?$

{

expires -1s;

try_files $uri =404;

fastcgi_split_path_info ^(.+\.php)(/.+)$;

include fastcgi_params;

fastcgi_param PATH_INFO $fastcgi_path_info;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_pass 127.0.0.1:9000;

}

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

server{

listen80;

server_nametest.ttlsa.com;

access_log/data/logs/nginx/test.ttlsa.com.access.logmain;

indexindex.phpindex.htmlindex.html;

root/data/site/test.ttlsa.com;

location/

{

try_files$uri$uri//index.php?$args;

}

location~.*\.(php)?$

{

expires-1s;

try_files$uri=404;

fastcgi_split_path_info^(.+\.php)(/.+)$;

includefastcgi_params;

fastcgi_paramPATH_INFO$fastcgi_path_info;

fastcgi_indexindex.php;

fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;

fastcgi_pass127.0.0.1:9000;

}

}

配置讲解

nginx将会连接回环地址9000端口执行PHP文件,需要使用tcp/ip协议,速度比较慢.建议大家换成使用socket方式连接。将fastcgi_pass 127.0.0.1:9000;改成fastcgi_pass unix:/var/run/phpfpm.sock;

启动nginx

/usr/local/nginx-1.4.1/sbin/nginx

1

/usr/local/nginx-1.4.1/sbin/nginx

3. 访问测试

# curl http://test.ttlsa.com/info.php

test php

1

2

# curl http://test.ttlsa.com/info.php

testphp

出现如上内容,说明PHP安装完成。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值