因系统Ubuntu12.04,官方源能升级到最新的PHP版本为5.3.10,感觉版本太旧有漏洞,所以决定编译升级到最新的nginx和php。下面是安装笔记。
注:MySQL用的依然是源里的二进制包,编译MySQL耗时太久,所以就放弃了。
1.编译安装Nginx
#安装nginx依赖
apt-get install build-essential libpcre3-dev libssl-dev
wget http://nginx.org/download/nginx-1.5.4.tar.gz
tar -zxf nginx-1.5.4.tar.gz
cd nginx-1.5.4/
./configure --with-http_ssl_module
make
make install
安装后默认目录在/usr/local/nginx,执行/usr/local/nginx/sbin/nginx 测试是否安装成功。
2.编译安装PHP
#安装PHP依赖,重要
apt-get install libiconv-hook-dev libmcrypt-dev libxml2-dev libmysqlclient-dev libcurl4-openssl-dev libjpeg8-dev libpng12-dev libfreetype6-dev
#下载源码,用的是美国镜像
wget -O php5.5.3.tar.gz http://cn2.php.net/get/php-5.5.3.tar.gz/from/us1.php.net/mirror
tar -zxf php5.5.3.tar.gz
cd php-5.5.3/
#配置,MySql用的是mysqlnd
./configure -prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-iconv-dir --with-freetype-dir --with
-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr -enable-xml -disable-rpath -enable-bcmath -enable-shmop -enable-sysv
sem -enable-inline-optimization --with-curl -enable-mbregex -enable-fpm -enable-mbstring --with-mcrypt -enable-ftp --with-gd -e
nable-gd-native-ttf --with-openssl --with-mhash -enable-pcntl -enable-sockets --with-xmlrpc -enable-zip -enable-soap --without-p
ear --with-gettext --with-mysqli=mysqlnd --with-mysql=mysqlnd --with-pdo-mysql
make
make install
默认安装目录在/usr/local/php
3.配置nginx+php
#进入/usr/local/php/etc目录,复制一份php-fpm配置
cp php-fpm.conf.default php-fpm.conf
#从源码目录复制一份php.ini文件到/usr/local/php
cp {PHP_SOURCE_PATH}/php.ini-production /usr/local/php/etc/php.ini
#准备php-fpm服务脚本
cp {PHP_SOURCE_PATH}/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
4.结束
启动php-fpm
/etc/init.d/php-fpm start
启动nginx
/usr/local/nginx/sbin/nginx
最后收尾工作就是权限配置和nginx的站点配置了。