0%

Ubuntu下编译安装php5.4.15(支持GD库)

环境ubuntu 12.04 server+nginx 1.4.1 nginx安装教程 PHP编译参数列表 http://www.php.net/manual/en/configure.about.php中文的,http://php.net/manual/zh/configure.about.php,我这被和谐了。 tar zvxf php-5.4.15.tar.gz cd php-5.4.15 ./configure --prefix=/home/server/php-5.4.15 --enable-fpm --enable-mbstring --enable-ftp --with-bz2 --with-jpeg-dir --with-png-dir --with-freetype-dir --with-libxml-dir --with-xmlrpc --with-zlib-dir --with-curl --with-curlwrappers --enable-calendar --enable-sockets --enable-exif --enable-magic-quotes make make install configure时如果提示xml2-config not found,安装libxml2和libxml2-dev 提示configure: error: Please reinstall the BZip2 distribution 安装libbz2-dev 提示Please reinstall the libcurl distribution 安装 libcurl4-gnutls-dev make时,如果报undefined reference to libiconv_*' 需要安装libconv库,下载地址http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz configure加上参数 –with-iconv=/usr/local/lib安装完, vi /home/server/php-5.4.15/etc/php-fpm.conf 这里主要是修改user和group,我这改成wwwuser = www group = www把pid = run/php-fpm.pid前的分号删掉,这样在php-fpm运行时会生成相应的pid文件。 启动php-fpm:/home/server/php-5.4.15/sbin/php-fpm 修改/home/server/nginx-1.4.1/conf/nginx.conf: server下增加root /home/www; location ~ .php$ { root /home/www; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }删除:location / { root /home/www; index index.html index.htm; }设置静态文件缓存: location ~ .*\\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\\.(js|css)?$ { expires 12h; } 默认没有生成php.ini,从源代码里拷一个: cp /root/download/php-5.4.15/php.ini-production /home/server/php-5.4.15/lib/php.ini 2013-09-08更新: 如果要让php支持GD库,需要在编译PHP前先安装 zlib([http://www.zlib.net/](http://www.zlib.net/)) libpng([http://sourceforge.net/projects/libpng/](http://sourceforge.net/projects/libpng/)) freetype([http://download.savannah.gnu.org/releases/freetype/](http://download.savannah.gnu.org/releases/freetype/)) libJpeg([http://www.ijg.org/files/](http://www.ijg.org/files/)) gd([https://bitbucket.org/libgd/gd-libgd/downloads](https://bitbucket.org/libgd/gd-libgd/downloads) 安装方法参考INSTALL文档,基本上都是:./configure make make install编译PHP的时候,在原参数后加上--with-gd --enable-gd-native-ttf 如果编译报错:checking for png_write_image in -lpng… no configure: error: Problem with libpng.(a|so) or libz.(a|so). Please check config.log for more information.基本上是libpng有问题,重新安装,或换一个版本,我之前用1.6.3就一直有这个问题,换了1.6.4rc后,解决. 记录一下编译参数:./configure –prefix=/home/fhp/server/php –enable-fpm –enable-mbstring –enable-ftp –with-bz2 –with-jpeg-dir –with-png-dir –with-freetype-dir –with-libxml-dir –with-xmlrpc –with-zlib-dir –with-curl –enable-calendar –enable-sockets –enable-exif –with-gd –enable-gd-native-ttf –with-iconv=/usr/local/lib`