1、apr安装
cd apr
./configure --prefix=/usr/local/apr/ && make && make install
2、apr-util安装
cd ../apr-util
./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr/ && make && make install
3、pcre安装
cd pcre-8.10
./configure --prefix=/usr/local/pcre && make && make install
4、openssl安装
./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl&&make && make install
可能会提示
You need a C++ compiler.
解决办法:
执行sudo apt-get install build-essential
Ubuntu并没有提供C/C++的编译环境,因此还需要手动安装。
如果想在Ubuntu中编译c/c++程序,只需要安装该软件包就可以了
ldap模块安装
如果不知道哪些apache模块跟ldap有关,我们可以使用这个命令找到相关模块:
sudo apt-cache search apache2 ldap
apt-get install 安装上面找到的模块
4 http 2.4.6安装
加入--with-included-apr 编译必须把apr,apr-util 的源文件放到 apache2.4.3源码的srclib目录下,并修改apr源码目录为apr,apr-util源码目录为apr-util
cp -rf apr-1.4.3 ./srclib/apr
cp -rf apr-util-1.4.1 ./srclib/apr-util
./configure --prefix=/usr/local/apache2 --enable-mods-shared=all --enable-deflate --enable-speling --enable-cache --enable-file-cache --enable-disk-cache --enable-mem-cache --enable-ssl --with-ssl=/usr/local/openssl/ --enable-rewrite --enable-so --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre --with-included-apr --with-mpm=worker --enable-authnz-ldap --enable-proxy-balancer --enable-proxy--enable-proxy-http --enable-proxy-ftp --enable-ssl
make && make install
5 .安装php
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-libxml-dir=/usr/local/libxml2 --with-config-file-path=/usr/local/php/etc --with-mysql --with-mysqli --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap
安装完从源码复制 php.ini 到安装目录 /usr/local/php/lib
安装完成检查http.conf是否有
LoadModule php5_module modules/libphp5.so
这行
添加下面两行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
禁止浏览目录
Options FollowSymLinks
编写php测试页面
<?php
phpinfo();
?>
可能会报错 缺少libxml2
解决方法:下载源码按装
./configure --prefix=/usr/local/libxml2 --disable-static --with-history &&make
安装libxml2可能报错 没有python.h这个目录
解决方法:apt-get install python-dev
不出意外,最后应该会看到以下结果: +--------------------------------------------------------------------+ | License: | | This software is subject to the PHP License, available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | +--------------------------------------------------------------------+ Thank you for using PHP.
编译常见问题
错误一:
configure: error: xml2-config not found. Please check your libxml2 installation.
而我已经安装过了libxml2,但是还是有这个提示:
解决办法:
# sudo apt-get install libxml2-dev
错误二:
configure: error: Please reinstall the BZip2 distribution
而我也已经安装了bzip2,网上找到得解决方案都是需要安装bzip2-dev,可是11.10里面没有这个库。
解决办法:在网上找到bzip2-1.0.5.tar.gz,解压,直接make ,sudo make install.(我使用的该源来自于http://ishare.iask.sina.com.cn/f/9769001.html)
错误三:
configure: error: Please reinstall the libcurl distribution -easy.h should be in <curl-dir>/include/curl/
解决办法:
# sudo apt-get install libcurl4-gnutls-dev
错误四:
configure: error: jpeglib.h not found.
解决办法:
# sudo apt-get install libjpeg-dev
错误五:
configure: error: png.h not found.
解决办法:
# sudo apt-get install libpng-dev
错误六:
configure: error: libXpm.(a|so) not found.
解决办法:
# sudo apt-get install libxpm-dev
错误七:
configure: error: freetype.h not found.
解决办法:
# sudo apt-get install libfreetype6-dev
错误八:
configure: error: Your t1lib distribution is not installed correctly. Please reinstall it.
解决办法:
# sudo apt-get install libt1-dev
错误九:
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决办法:
# sudo apt-get install libmcrypt-dev
错误十:
configure: error: Cannot find MySQL header files under yes.
Note that the MySQL client library is not bundled anymore!
解决办法:
# sudo apt-get install libmysql++-dev
错误十一:
configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
解决办法:
# sudo apt-get install libxslt1-dev
可见PHP源码安装之前需要先安装这些依赖,详细可见http://forum.ubuntu.org.cn/viewtopic.php?f=88&t=231159
如上错误都解决之后,再次./config….没有错误之后,
# make# sudo make install
make
//编译源码,漫长的一个过程,休息下先去喝杯茶再回来
成功后会看到:
Build complete. Don't forget to run 'make test'.
make install
如果安装成功,就此php源码编译成功;