nginx 安装php
2015-10-19 14:30
826 查看
1. 安装PHP 5.5.0
下载1 2 | cd /usr/local/src/ wget http://www.php.net/get/php-5.5.0.tar.bz2/from/jp1.php.net/mirror |
安装依赖包
确保安装之前有安装gd,png,curl,xml等等lib开发库。如果不确定,执行以下命令:
1 | yum install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel -y |
以下参数支持,ftp,图片函数,pdo等支持,因为使用了php自带的mysqlnd,所以不需要额外安装mysql的lib库了.如果你是64位系统,参数后面加上--with-libdir=lib64,如果不是可以跳过。
1 2 3 4 5 | 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 |
配置php
1 2 | 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 | /usr/local/php-5.5.0/sbin/php-fpm |
1 2 | # netstat -lnt | grep 9000 tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN |
2、安装配置nginx
安装nginx请看<ttlsa教程系列之nginx - nginx安装>
配置测试站点test.ttlsa.com
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 <?php phpinfo(); ?> |
nginx配置
在nginx.conf的http断中加上如下内容:
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 { 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; } } |
nginx将会连接回环地址9000端口执行PHP文件,需要使用tcp/ip协议,速度比较慢.建议大家换成使用socket方式连接。将fastcgi_pass 127.0.0.1:9000;改成fastcgi_pass unix:/var/run/phpfpm.sock;
这里需要注意的地方:要配置fastcgi_pass通过socket的方式,还要配置php-fpm,还有phpfpm.sock的权限,要有读写权限
启动nginx
1 | /usr/local/nginx-1.4.1/sbin/nginx |
3. 访问测试
1 2 | # curl http://test.ttlsa.com/info.php test php |
相关文章推荐
- Nginx停止、卸载、configure配置
- Google perf tools for nginx
- Nginx配置文件详细说明
- Nginx下载和编译安装
- 转 Nginx+FastCGI到底是谁影响超时时间
- windows nginx +php 配置
- nginx系列(八)nginx失效转移与超时处理
- nginx-apache服务器配置
- nginx学习(一)入门
- Nginx 关于 Rewrite 执行顺序详解
- 为Mac配置服务器nginx
- 使用Nginx、Nginx Plus抵御DDOS攻击
- keepalived+haproxy实现nginx与mysql负载均衡
- nginx配置文件详解
- 在Ubuntu上使用Nginx+uwsgi部署django
- LVS Nginx HAProxy 优缺点
- Nginx
- nginx + keepalived 双机热备
- nginx location 指令说明
- nginx学习链接