您的位置:首页 > 编程语言 > PHP开发

(转+原)nignx php5.5.14 安装配置

2014-07-16 14:43 337 查看


下载 PHP 源码包

# wget http://cn2.php.net/distributions/php-5.5.14.tar.bz2 # tar xf php-5.5.14.tar.bz2


添加 epel 源

# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm[/code] 


安装依赖

# yum install gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel


创建 apache 用户

groupadd apache
useradd -g apache apache

# cd /usr/local/php-5.5.14/

# ./configure\
--prefix=/usr/local/php \
--with-config-file-path=/etc \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-opcache \
--enable-fpm \
--with-fpm-user=apache \
--with-fpm-group=apache \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-gettext \
--enable-mbstring \
--with-iconv \
--with-mcrypt \
--with-mhash \
--with-openssl \
--enable-bcmath \
--enable-soap \
--with-libxml-dir \
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-sockets \
--with-curl \
--with-zlib \
--enable-zip \
--with-bz2 \
--with-readline \
--without-sqlite3 \
--without-pdo-sqlite \
--with-pear

[/code]

参数说明:
""" 安装路径 """ --prefix=/usr/local/php \
""" php.ini 配置文件路径 """ --with-config-file-path=/etc \
""" 优化选项 """ --enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
""" 启用 opcache,默认为 ZendOptimizer+(ZendOpcache) """ --enable-opcache \
""" FPM """ --enable-fpm \
--with-fpm-user=apache\
--with-fpm-group=apache \
""" MySQL """ --with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
""" 国际化与字符编码支持 """ --with-gettext \
--enable-mbstring \
--with-iconv \
""" 加密扩展 """ --with-mcrypt \
--with-mhash \
--with-openssl \
""" 数学扩展 """ --enable-bcmath \
""" Web 服务,soap 依赖 libxml """ --enable-soap \
--with-libxml-dir \
""" 进程,信号及内存 """ --enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
""" socket & curl """ --enable-sockets \
--with-curl \
""" 压缩与归档 """ --with-zlib \
--enable-zip \
--with-bz2 \
""" GNU Readline 命令行快捷键绑定 """ --with-readline \
""" 禁用 SQLite 支持扩展 """ --without-sqlite3 \
--without-pdo-sqlite \
""" 更多 PHP 扩展与应用库 """ --with-pear


配置 PHP

配置文件:
# cp php.ini-development /etc/php.ini


php-fpm 服务
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm # chmod +x /etc/init.d/php-fpm


启动 php-fpm
# service php-fpm start Starting php-fpm done


php-fpm 可用参数 start|stop|force-quit|restart|reload|status


添加 PHP 命令到环境变量

编辑
~/.bash_profile
,将:
PATH=$PATH:$HOME/bin 改为: PATH=$PATH:$HOME/bin:/usr/local/php/bin


使 PHP 环境变量生效:
# . ~/.bash_profile

查看php版本:



php –version

PHP 5.5.14 (cli) (built: Jul 15 2014 19:42:48) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologie

如果版本不对,说明有老版本没有卸载完成,可以找到旧的安装文件做卸载操作,如果不行,则可以找出相关的php目录删除即可。
Nginx 安装:

下载:

http://wiki.nginx.org/Install

选择最新或稳定版本

解压:

tar xf nginx-1.7.3.tar.gz

安装:

cd nginx-1.7.3

./configure
--prefix=/usr/local/nginx[/code]
make && make install


cp /usr/local/nginx/sbin/nginx /etc/init.d/nginx

配置nginx:

cd /usr/local/nginx/conf

vim nginx.conf


#user nobody

修改:user apache apache  #根据喜好配置

修改:

location / {

root html;#可以改成自己的web服务器根目录,同时目录用户修改为apache

index index.php index.html

}

修改:

locate ~ \.php$ {

include fastcgi.conf;#也可以把fastcgi的配置往这里写,参考默认选项

}

修改fastcgi.conf

vim fastcgi.conf

在开头增加:

fastcgi_pass 127.0.0.1:9000;#这里的id和端口一定要和php-fpm一致
fastcgi_index index.php;

新建测试php文件:

cd /usr/local/nginx/html/

vim index.php

修改访问目录所属用户:

chown -R apache:apache html

启动nginx:

service nginx start

在浏览器ip访问

看到nginx欢迎页面说明nginx安装成功

ip/index.php 看到php的输出结果则说明php fastcgi 配置成功
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: