ubuntu 13.04下编译安装php ubuntu编译安装php (亲测)
kevin.Zhu 发布于:2013-1-16 15:23 分类:Php 有 17 人浏览,获得评论 0 条
首先要安装编译php时要的几个扩展库
(1)libxml2,若无php安装一些解析xml的扩展时会提示xml2-config not found
sudo apt-get install libxml2 libxml2-dev libxslt-dev
(2)libevent1.4.11及以上版本,安装php的fpm模块时需要
sudo apt-get install libevent-1.4-2 libevent-dev
(3)libcurl,安装curl扩展需要
sudo apt-get install libcurl4-openssl-dev
(4)GD库,安装gd图片处理扩展需要
sudo apt-get install libgd2-xpm libgd2-xpm-dev
(5)zlib1g-dev,安装zlib和bz2扩展或编译mysqld阶段需要
sudo apt-get install zlib1g-dev libbz2-dev
(6) configure: error: mcrypt.h not found. Please reinstall libmcrypt.
sudo apt-get install libmcrypt-dev
安装freetype:
wget http://ftp.twaren.net/Unix/NonGNU//freetype/freetype-2.4.0.tar.gz
tar -zxf gd-2.0.33.tar.gz
cd gd-2.0.33
mkdir -p /usr/local/gd2
./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg/ --with-png=/usr/local/libpng/ --with-zlib=/usr/local/zlib/ --with-freetype=/usr/local/freetype/
make
make install
编译参数:
sudo ./configure --prefix=/usr/local/php --mandir=/usr/share/man --infodir=/usr/share/info --sysconfdir=/etc --enable-cli --with-config-file-path=/usr/local/php/etc --with-openssl --with-kerberos --with-zlib --enable-bcmath --with-bz2 --enable-calendar --with-curl --enable-exif --enable-ftp --with-gd --enable-gd-native-ttf --with-freetype --enable-magic-quotes --enable-mbstring --enable-mbregex --enable-json --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql-sock=mysqlnd --enable-mysqlnd --with-sqlite --with-pdo-sqlite --enable-pdo --enable-dba --enable-shmop --enable-soap --enable-sockets --enable-wddx --enable-fpm --with-mhash --with-mcrypt=/usr/local/libmcrypt --with-iconv --with-xsl --enable-zend-multibyte --enable-zip --with-pcre-regex --enable-dom --enable-posix --enable-fileinfo --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-libxml --with-xmlrpc --enable-xml --enable-xmlwriter --enable-xmlreader --enable-maintainer-zts --with-mpm=prefork --enable-roxen-zts --enable-maintainer-zts --with-config-file-scan-dir=/usr/local/php/conf.d
注意:在上面编译配置中去掉 gd模块 ,PHP自带gd不支持 jpeg ,gd模块需要在PHP安装好后 先整合jpeg模块 ,再动态加入到php中 ,详情见另一片记录。
说明:如果是apache,请加上
-with-apxs2=/usr/local/apache/bin/apxs
–enable-maintainer-zts 支持apache的worker或event这两个MPM
说明:这里为了支持apache的worker或event这两个MPM,编译时使用了–enable-maintainer-zts选项。
# 注:其中最后一个参数–enable-maintainer-zts在安装PHP5.4最新版本时必须添加(5.3貌似不需要),表示打开PHP进程安全Thread Safe,默认不添加为NON Thread Safe,开启apache服务会报错…..
编译通过就执行安装过程
sudo make -j 4
sudo make install
安装完成后
sudo cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm #因为php5.3开始自带fpm,使用自带的管理脚本
sudo chmod +x /etc/init.d/php-fpm
sudo ln -sf /usr/local/php/bin/php /usr/local/bin/
sudo cp /etc/php-fpm.conf.default /etc/php-fpm.conf
sudo cp php.ini-development /usr/local/php/etc/php.ini
添加执行组和用户,如果添加过,则不需要
sudo groupadd www
sudo useradd -g www www -s /bin/false
修改fpm配置
sudo vi /etc/php-fpm.conf
将user和group的值改为www,www
service php-fpm start
这样php-fpm启动成功,nginx可以fastcgi解析php。
//--------------------------------------- 无Bug库 常规配置 ------------------------------
./configure --prefix=/usr/local/php55_1 --mandir=/usr/share/man --infodir=/usr/share/info --sysconfdir=/etc --enable-cli --with-config-file-path=/usr/local/php55_1/etc --with-openssl --with-kerberos --with-zlib --enable-bcmath --with-bz2 --enable-calendar --with-curl --enable-exif --enable-ftp --with-gd --enable-gd-native-ttf --enable-magic-quotes --enable-mbstring --enable-mbregex --enable-json --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql-sock=mysqlnd --with-sqlite --with-pdo-sqlite --enable-pdo --enable-dba --enable-shmop --enable-soap --enable-sockets --enable-wddx --enable-fpm --with-mhash --with-mcrypt --with-iconv --with-xsl --enable-zend-multibyte --enable-zip --with-pcre-regex --enable-dom --enable-posix --enable-fileinfo --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-libxml --with-xmlrpc --enable-xml --enable-xmlwriter --enable-xmlreader --enable-maintainer-zts --with-mpm=prefork --enable-roxen-zts --enable-maintainer-zts --with-config-file-scan-dir=/usr/local/php55_1/conf.d --with-jpeg-dir=/usr/local/jpeg/(--with-jpeg) --with-freetype-dir=/usr/local/freetype24/ (--with-freetype)