参考先前的文章:
安装过程:
##################################################### 1、安装PHP依赖库################################################### 安装依赖库sudo apt-get -y install libxml2-dev libjpeg62-dev libpng-dev libfreetype6-dev autoconf libcurl3-openssl-dev#安装 libmcrypcd /opt/software-backup/lnmp/source2/php/libsudo tar -xzvf ./libmcrypt-2.5.8.tar.gzcd ./libmcrypt-2.5.8sudo ./configure --prefix=/usrsudo make && sudo make install #安装 mhashcd /opt/software-backup/lnmp/source2/php/libsudo tar -xzvf ./mhash-0.9.9.9.tar.gzcd ./mhash-0.9.9.9sudo ./configure --prefix=/usrsudo make && sudo make install #安装 mcryptsudo /sbin/ldconfig #搜索出可共享的动态链接库cd /opt/software-backup/lnmp/source2/php/libsudo tar -xzvf ./mcrypt-2.6.8.tar.gzcd ./mcrypt-2.6.8sudo ./configuresudo make && sudo make install #安装 libiconvcd /opt/software-backup/lnmp/source2/php/libsudo tar -xzvf ./libiconv-1.14.tar.gzcd ./libiconv-1.14sudo ./configure --prefix=/usrsudo make && sudo make install#安装bzip2cd /opt/software-backup/lnmp/source2/php/libsudo tar -xzvf ./bzip2-1.0.6.tar.gzcd ./bzip2-1.0.6sudo make && sudo make install##################################################### 2、安装 PHP php-5.4.45##################################################cd /opt/software-backup/lnmp/source2/phpsudo tar -xzvf ./php-5.4.45.tar.gzcd ./php-5.4.45sudo 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.oldsudo cp -rf /opt/software-backup/lnmp/config/php.ini /opt/software/php/etc/php.inisudo 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-fpmsudo service nginx restart #重启nginx sudo cp -rf /opt/software-backup/lnmp/source2/index.php /opt/software/nginx/htmlsudo chmod -R +x /opt/software/nginx/htmlsudo chown -R jianbao:jianbao /opt/software/nginx/html
##把PHP的相关命令路径添加到 系统环境变量
$sudo vim /etc/bash.bashrc // 在文件末追加以下文本
export PATH=$PATH:/opt/software/php/bin:
问题汇总:
问题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
参考:
【荐】