参考先前的文章:Ubuntu 14 编译安装 PHP 5.4.45 + 1.4.7 + MySQL 5.6.26 笔记
安装过程:
################################################## ### 1、安装PHP依赖库 ################################################## # 安装依赖库 sudo apt-get -y install libxml2-dev libjpeg62-dev libpng-dev libfreetype6-dev autoconf #安装 libmcryp cd /opt/software-backup/lnmp/source2/php/lib sudo tar -xzvf ./libmcrypt-2.5.8.tar.gz cd ./libmcrypt-2.5.8 sudo ./configure --prefix=/usr sudo make && sudo make install #安装 mhash cd /opt/software-backup/lnmp/source2/php/lib sudo tar -xzvf ./mhash-0.9.9.9.tar.gz cd ./mhash-0.9.9.9 sudo ./configure --prefix=/usr sudo make && sudo make install #安装 mcrypt sudo /sbin/ldconfig #搜索出可共享的动态链接库 cd /opt/software-backup/lnmp/source2/php/lib sudo tar -xzvf ./mcrypt-2.6.8.tar.gz cd ./mcrypt-2.6.8 sudo ./configure sudo make && sudo make install #安装 libiconv cd /opt/software-backup/lnmp/source2/php/lib sudo tar -xzvf ./libiconv-1.14.tar.gz cd ./libiconv-1.14 sudo ./configure --prefix=/usr sudo make && sudo make install #安装bzip2 cd /opt/software-backup/lnmp/source2/php/lib sudo tar -xzvf ./bzip2-1.0.6.tar.gz cd ./bzip2-1.0.6 sudo make && sudo make install ################################################## ### 2、安装 PHP php-5.4.45 ################################################## cd /opt/software-backup/lnmp/source2/php sudo tar -xzvf ./php-5.4.45.tar.gz cd ./php-5.4.45 sudo mkdir /opt/software/php # 防止出现 cp:cannot stat 'sapi/cli/php.1': No such file or directory 错误 sudo ./buildconf --force #生成配置 sudo ./configure --prefix=/opt/software/php --with-config-file-path=/opt/software/php/etc --with-openssl --with-zlib --with-bz2 --with-gd --with-jpeg-dir --with-png-dir --with-gettext --with-mhash --with-freetype-dir --with-mcrypt --with-iconv --with-curl --with-curlwrappers --with-xmlrpc --with-mysql=/opt/software/mysql --with-pdo-mysql=/opt/software/mysql --with-mysqli=/opt/software/mysql/bin/mysql_config --enable-zip --enable-mbstring --enable-mbregex --enable-bcmath --enable-soap --enable-sockets --enable-ftp --enable-gd-native-ttf --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-fpm --with-fpm-user=jianbao --with-fpm-group=jianbao --without-pear #编译安装 sudo make && make install ################################################## ### 4、配置php.ini ################################################## #cp ./php.ini-production /opt/software/php/etc/php.ini #复制php配置文件到安装目录 sudo mv /etc/php.ini /etc/php.ini.old sudo cp -rf /opt/software-backup/lnmp/config/php.ini /opt/software/php/etc/php.ini sudo ln -s /opt/software/php/etc/php.ini /etc/php.ini #添加软链接 ################################################## ### 5、配置php-fpm ################################################## #cp /opt/software/php/etc/php-fpm.conf.default /opt/software/php/etc/php-fpm.conf #拷贝模板文件为php-fpm配置文件 sudo cp -rf /opt/software-backup/lnmp/config/php-fpm.conf /opt/software/php/etc/php-fpm.conf #设置 php-fpm 开机启动 sudo cp -rf /opt/software-backup/lnmp/config/php-fpm /etc/init.d/php-fpm #拷贝php-fpm到启动目录 sudo chmod +x /etc/init.d/php-fpm #添加执行权限 sudo update-rc.d php-fpm defaults #设置开机启动 sudo service php-fpm start #启动php-fpm sudo service nginx restart #重启nginx sudo cp -rf /opt/software-backup/lnmp/source2/index.php /opt/software/nginx/html sudo chmod -R +x /opt/software/nginx/html sudo chown -R jianbao:jianbao /opt/software/nginx/html
问题汇总:
问题1:在安装PHP依赖库时
$ sudo apt-get -y install libxml2-dev libjpeg-dev libpng-dev libfreetype6-dev
时,报错:
下列软件包有未满足的依赖关系:
libjpeg-dev : 依赖: libjpeg8-dev 但是它将不会被安装
E: 无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系。
解决方案:
把 libjpeg-dev 换成了 libjpeg62-dev,即
$ sudo apt-get -y install libxml2-dev libjpeg62-dev libpng-dev libfreetype6-dev
问题2:编译PHP,执行 sudo make 时,报错:
undefined reference to `libiconv_open'
undefined reference to `libiconv_close'
undefined reference to `libiconv'
解决方案:
那表示在 ./configure 沒抓好一些环境变数值。错误发生点在建立“-o sapi/cli/php”时出错,没給到要 link 的 iconv 函式库参数。
编辑 Makefile 大约77 行左右的地方: EXTRA_LIBS = ..... -lcrypt,在最后加上 -liconv,例如: EXTRA_LIBS = ..... -lcrypt -liconv
问题3:编译PHP,sudo make 通过,但是执行 sudo make install 时,又报错:
Installing PHP CLI binary: /opt/software/php/bin/
Installing PHP CLI man page: /opt/software/php/php/man/man1/
cp: cannot stat `sapi/cli/php.1': No such file or directory
make: *** [install-cli] 错误 1
网络资料说:
在执行编译PHP的 ./configure 之前,要先执行一下
sudo ./buildconf --force,为了防止出现 cp:cannot stat 'sapi/cli/php.1': No such file or directory
不过,在 执行 ./buildconf --force 之前,还要先执行一下:
sudo apt-get install autoconf
否则,报错:
Forcing buildconf
Removing configure caches
buildconf: checking installation...
buildconf: autoconf not found.
You need autoconf version 2.59 or newer installed
to build PHP from Git.
make: *** [buildmk.stamp] 错误 1
参考: