LINUX下NGINX+PHP+YAF环境搭建
自己搭建了一下NGINX+PHP+YAF的生产环境,在这里记录一下,避免遗忘
yaf是一套用PHP扩展实现的PHP框架,底层用C语言实现,据yaf作者描述其效率是Zend的50-60倍,性能高而又不失开发效率。
操作系统是CentOS release 6.5
整个过程主要分为三个部分:
1.编译安装PHP
2.编译安装NGINX
3.编译安装YAF
一、编译安装PHP
1.下载PHP源码,我这里下载得版本是5.6.29(php-5.6.29.tar.gz)
http://www.php.net/downloads.php
2.安装各依赖包
yum -y install gcc gcc-c++ libxml2 libxml2-devel bzip2 bzip2-devel libmcrypt libmcrypt-devel openssl openssl-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel readline readline-devel libxslt-devel perl perl-devel psmisc.x86_64 recode recode-devel libtidy libtidy-devel
3.解压源码包至当前目录
tar zxvf php-5.6.29.tar.gz
4.进入解压的文件夹编译PHP源码
cd php-5.6.29
5.生成makefile文件并构建
./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=www --with-fpm-group=www --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
注释:
--prefix=/usr/local/php 程序安装的路径
--with-config-file-path=/etc/ php.ini 文件路径
--enable-fpm 编译 PHP-FastCGI管理器
在阿里云上编译时,因为内存过小,报了[ext/fileinfo/libmagic/apprentice.lo]的错,加上--disable-fileinfo编译选项后编译通过
其他编译选项查阅相关文章(http://www.t086.com/code/php/2.3.php.php)
make
make install
中间过程中报错,大多数情况可能是缺少依赖包所导致
6.将源代码目录中的php.ini-development(开发),php.ini-production(生产)复制到 --with-config-file-path 指定的目录,并改名为php.ini.
7.将PHP程序加入环境变量,方便直接作为命令调用
vim /etc/profile
在末尾加入
PATH=$PATH:/usr/local/php/bin
export PATH
要使改动立即生效执行
. /etc/profile 或 source /etc/profile
查看环境变量
echo $PATH
查看php版本
php -v
8.配置启动php-fpm
配置php-fpm
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
启动php-fpm
sudo /usr/local/php/sbin/php-fpm
二、编译安装NGINX
1.下载NGINX源码,我这里下载的版本是nginx-1.1.8(nginx-1.1.8.tar.gz)
http://nginx.org/
2.安装依赖包
yum -y install gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel open openssl-devel
3.解压源码包
tar xf nginx-1.1.8.tar.gz
cd nginx-1.1.8
4.生成makefile与构建
./configure --prefix=/usr/local/nginx
注释:
--prefix=/usr/local/nginx 主程序安装目录
还有很多其他编译选项,请查阅其他相关资料
make
make install
5.修改配置文件
cd /usr/local/nginx/conf
对nginx的主配置文件nginx.conf进行修改
location / {
root web根目录;
index index.html index.htm index.php;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME web根目录$fastcgi_script_name;
include fastcgi_params;
}
6.启动nginx
./usr/local/nginx/sbin/nginx
7.通过ps命令观察nginx是否启动成功
ps -elf | grep nginx
nginx启动的过程中还遇见了一个端口占用的问题,启动时报如下错
Starting nginx daemon: nginx[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: still could not bind()
nginx already running.
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
[emerg]: still could not bind()
nginx already running.
原因是对80端口重复绑定,在配置中把ipv6的80端口绑定注释掉以后就好了(http://bbs.archlinuxcn.org/viewtopic.php?id=420)
三、编译安装YAF
1.下载yaf源码,这里下载的是2.3.3版本(yaf-2.3.3.tgz)
http://pecl.php.net/package/yaf
这里有两个坑,
最开始是用3.0.4版本编译的,但是3.0.4需要PHP7的支持,所以就歇菜了
用2.2.9版本编译出错,上网查了下yaf作者建议直接用2.3.3版本,于是换2.3.3版本就直接成功了,囧
2.给PHP添加动态扩展
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
3.在上面所提到的php.ini文件中加入
extension=yaf.so
4.重启PHP-FPM
至此,基本环境搭建结束,然后就可以按照http://www.laruence.com/manual/中所述写一个hello world了~
posted on 2017-01-04 23:58 少壮不努力1991 阅读(2869) 评论(0) 编辑 收藏 举报