编译安装 php 5.4.11


第一步 先下载 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

!!!

编译PHP5缺t1lib包解决方案

遇到这个报错:
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一行之后

这种方法只对当前登录用户生效

方法三:修改/etc/profile文件使其永久性生效,并对所有系统用户生效,在文件末尾加上如下两行代码
PATH=$PATH:/usr/local/webserver/php/bin:/usr/local/webserver/mysql/bin
export PATH

或者   export PATH=$PATH:/usr/local/webserver/php/bin:/usr/local/webserver/mysql/bin

最后:执行 命令source /etc/profile或 执行点命令 ./profile使其修改生效,执行完可通过echo $PATH命令查看是否添加成功。



启动 php 服务的时候 

sudo /usr/local/php/sbin/php-fpm 

会出现

错误:

[10-Apr-2013 18:12:02] NOTICE: PHP message: PHP Deprecated:  Comments starting with '#' are deprecated in /usr/local/php/lib/php.ini on line 1874 in Unknown on line 0
[10-Apr-2013 18:12:02] ERROR: failed to open configuration file '/usr/local/php/etc/php-fpm.conf': No such file or directory (2)
[10-Apr-2013 18:12:02] ERROR: failed to load configuration file '/usr/local/php/etc/php-fpm.conf'
[10-Apr-2013 18:12:02] ERROR: FPM initialization failed

这时候 是 php 找不到 配置文件php-fpm.conf

解决办法: 
cd /usr/local/php/etc/ 


sudo cp php-fpm.conf.default php-fpm.conf

再启动
sudo /usr/local/php/sbin/php-fpm

出现错误:

[10-Apr-2013 18:14:09] NOTICE: PHP message: PHP Deprecated:  Comments starting with '#' are deprecated in /usr/local/php/lib/php.ini on line 1874 in Unknown on line 0
[10-Apr-2013 18:14:09] ERROR: [pool www] cannot get gid for group 'nobody'
[10-Apr-2013 18:14:09] ERROR: FPM initialization failed

原因是  [pool www] cannot get gid for group 'nobody'  没有这个用户  我之前编译的时候 指定用户 是 www  所以进入 vi  /usr/local/php/etc/php-fpm.conf   
修改 

user = www
group = www
 
然后 测试PHP是否安装成功

在网站跟目录下 写入 一个测试 PHP是否安装成功的 
我的nginx 根目录是 /usr/local/nginx/html/

sudo vi   index.php

  <?php phpinfo(); ?>

保存

然后测试下即可

深入理解PHP中的ini配置

剖析PHP脚本的超时机制

Ubuntu 14.04下搭建PHP开发环境PDF 

PHP 7革新与性能优化

PHP 7 ,你值得拥有   

在 CentOS 7.x / Fedora 21 上面体验 PHP 7.0   

CentOS 6.3 安装LNMP (PHP 5.4,MyySQL5.6)  

在部署LNMP的时候遇到Nginx启动失败的2个问题  

Ubuntu安装Nginx php5-fpm MySQL(LNMP环境搭建)  

《细说PHP》高清扫描PDF+光盘源码+全套教学视频  

CentOS 6中配置PHP的LNMP的开发环境   

PHP 的详细介绍:请点这里
PHP 的下载地址:请点这里

本文永久更新链接地址

相关内容