第一步 先下载 tzr.gz 的php源码包
然后 tar zxvf php-5.4.11.tar.gz
然后 cd php-5.4.11
然后复制如下编译代码
./configure \
--prefix=/usr/local/php \
--enable-zip \
--with-xsl \
--enable-zend-multibyte \
--enable-sockets \
--enable-soap \
--with-pdo-mysql=mysqlnd \
--with-mysql=mysqlnd \
--enable-pcntl \
--with-mcrypt \
--enable-fpm \
--enable-shmop \
--with-readline \
--enable-mbstring \
--with-mhash \
--enable-gd-native-ttf \
--with-freetype-dir \
--with-t1lib=/usr/local/share/t1lib \
--with-png-dir \
--with-jpeg-dir \
--with-gd \
--with-openssl-dir \
--enable-ftp \
--enable-exif \
--enable-dba \
--with-bz2 \
--enable-bcmath \
--with-curl
!!!
遇到这个报错:
configure: error: Your t1lib distribution is not installed correctly. Please reinstall it.
以下是解决步骤:
1. 下载t1lib-5.1.2.tar.gz
2. 解决依赖关系:apt-get build-dep t1lib
3. 安装:./configure & make without_doc & make install
4. 编译php5 时在./configure后加上 --with-t1lib=/usr/local/share/t1lib。再次编译就能通过了。
如果提示 configure: error: Please reinstall readline - I cannot find readline.h 错误!
安装 sudo apt-get install libreadline-dev
然后再编译一下 就没错误了!
‘./configure’ ‘–prefix=/usr/local/php’ ‘–with-config-file-path=/etc’ ‘–with-mysql=/usr/local/mysql’ ‘–with-mysqli=/usr/local/mysql/bin/mysql_config’ ‘–with-iconv-dir=/usr/local’ ‘–with-freetype-dir’ ‘–with-jpeg-dir’ ‘–with-png-dir’ ‘–with-zlib’ ‘–with-libxml-dir=/usr’ ‘–enable-xml’ ‘–disable-rpath’ ‘–enable-safe-mode’ ‘–enable-bcmath’ ‘–enable-shmop’ ‘–enable-sysvsem’ ‘–enable-inline-optimization’ ‘–with-curl’ ‘–with-curlwrappers’ ‘–enable-mbregex’ ‘–enable-fpm’ ‘–enable-mbstring’ ‘–with-mcrypt’ ‘–with-gd’ ‘–enable-gd-native-ttf’ ‘–with-openssl’ ‘–with-mhash’ ‘–enable-pcntl’ ‘–enable-sockets’ ‘–with-xmlrpc’ ‘–enable-zip’ ‘–enable-soap’
出现得错误如下:
报错:configure: error: png.h not found.
解决办法:
apt-get -y install libpng12-dev
错误一:
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.
错误三:
configure: error: Please reinstall the libcurl distribution -easy.h should be in /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
如上错误都解决之后,再次./config….没有错误之后,
# make
# sudo make install
将编译安装的PHP输入到环境变量中
编译后 将其PHP路径 输入到环境变量中,要不然系统执行PHP的文件时 不知道PHP安装了没有 所以要指定一个目录 让系统知道去那里能找到编译安装的PHP
Linux CentOS系统上安装完php和MySQL后,为了使用方便,需要将php和mysql命令加到系统命令中,如果在没有添加到环境变量之前,执行 “php -v”命令查看当前php版本信息时时,则会提示命令不存在的错误,下面我们详细介绍一下在linux下将php和mysql加入到环境变量中的方法(假 设php和mysql分别安装在/usr/local/webserver/php/和/usr/local/webserver/mysql/中)。
方法一:直接运行命令export PATH=$PATH:/usr/local/webserver/php/bin 和 export PATH=$PATH:/usr/local/webserver/mysql/bin
使用这种方法,只会对当前会话有效,也就是说每当登出或注销系统以后,PATH 设置就会失效,只是临时生效。
方法二:执行vi ~/.bash_profile修改文件中PATH一行,将/usr/local/webserver/php/bin 和 /usr/local/webserver/mysql/bin 加入到PATH=$PATH:$HOME/bin一行之后
这种方法只对当前登录用户生效