Linux下安装配置php
工具
php版本:php-5.5.35.tar.gz
解压移动当前文件至创建好的/usr/local/php文件夹下
tar -xf php-5.5.35.tar.gz
mv php-5.5.35 /usr/local/php/
配置
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath
如果出现报错configure: error: xml2-config not found. Please check your libxml2 installation.;需要安装libxml2依赖包
yum search libxml2
安装
yum install libxml2.x86_64
yum install libxml2-devel.x86_64
再次执行
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath
报错:configure: error: Please reinstall the BZip2 distribution,需要安装BZip2依赖包
yum search BZip2
安装
yum install bzip2-devel.x86_64
yum install bzip2.x86_64
再次执行
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath
报错: configure: error: Please reinstall the libcurl distribution -
easy.h should be in /include/curl/,需要安装curl依赖包
安装
yum search curl
yum install libcurl-devel.x86_64
再次执行
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath
报错:configure: error: jpeglib.h not found,需要安装jpeglib依赖
安装:
yum search libjpeg
yum install libjpeg-turbo-devel.x86_64
再次执行
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath
报错:configure: error: png.h not found.需要安装png.依赖
安装:
yum search png
yum install libpng-devel.x86_64
再次执行
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath
报错:configure: error: freetype-config not found.需要安装freetype依赖
安装:
yum search freetype
yum install freetype-devel.x86_64
配置完成
编译
make && make install
复制:
cp php.ini-production /usr/local/php/etc/php.ini
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
可选修改php.ini参数:(zabbix环境需要修改的参数)
max_execution_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
max_input_time = 300
date.timezone = PRC
启动
/usr/local/phh/sbin/php-fpm
在这里可以修改vim .bash_profile,把php启动路径放进去为后期启动更加方便。
后续 安装zabbix时报错:PHP ldap Warning
需要安装ldap
/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212路径下面未发现ldap.so,需要重新安装编译
进入模块所在的源码位置/usr/local/php/php-5.5.35/ext/ldap
编译PHP扩展的工具,主要是根据系统信息生成对应的configure文件
此时出现Cannot find autoconf报错,需要安装autoconf依赖包
yum search autoconf
yum install yum install autoconf-archive.noarch
再次执行/usr/local/php/bin/phpize
配置./configure --with-php-config=/usr/local/php/bin/php-config --with-ldap
需要安装openldap依赖
yum install openldap*
编译安装make && make install
修改配置文件:vim /usr/local/php/etc/php.ini
找到 ;extension=ldap 的行 把注销去掉 , 5版本的php添加extension=ldap.so
保存退出重新启动项目即可