ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
## 安装环境准备 ### 系统和软件版本 centos 6 php-5.4.22 ### 相关依赖软件 ~~~ yum install libmcrypt libmcrypt-devel php53-mbstring freetype zlib zlib-devel \ openssl openssl-devel libxml libxml-devel bzip2 bzip-devel libjpeg libjpeg-devel \ libpng libpng-devel libcurl libcurl-devel freetype freetype-devel libxml2 \ libxml2-devel xz xz-devel bzip2 bzip2-devel ~~~ 说明 * libmcrypt、libmcrypt-devel 使php支持mcrypt扩展加密功能(可选) * php53-mbstring multibyte用来支持中文或者一个字节无法表示的文字 * freetype 字体库,使php可以引用各种字体 * zlib zlib-devel 通过用格式压缩库,先压缩再传送 * openssl openssl-devel * libxml libxml-devel * bzip2 bzip-devel * libjpeg libjpeg-devel libpng libpng-devel ### 部分编译选项说明 ~~~ --with-mysqli=/usr/local/mysql/bin/mysql_config:php和mysql交互接口 --with-apxs2=/usr/local/apache/bin/apxs 安装httpd扩展 --enable-maintainer-zts prefork不启用此项,worker和event启用此选项 --enable-fpm 支持fastcgi ~~~ mysqlnd ~~~ mysqlnd从php 5.3开始可用,可以编译时绑定到它(而不用和具体的MySQL客户端库绑定形成依赖),从PHP 5.4开始它就是默认设置了。 # ./configure --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd ~~~ ### apxs apache扩展 如果是yum安装的httpd,则需要安装httpd-devel开发包才能有apxs,编译安装的httpd带有此命令 ### 软件下载 [官方网站][1] --- ## 正式安装 ~~~ # httpd -M | grep mpm mpm_worker_module (shared) ~~~ >[danger] 查看httpd的模块,来确定php的工作模式,这里是worker模型,因此需要启用zts ### configure ~~~ ./configure \ --prefix=/usr/local/php \ --sysconfdir=/usr/local/php/etc \ --with-config-file-path=/usr/local/php/etc \ --with-config-file-scan-dir=/usr/local/php/etc/php.d \ --with-apxs2=/usr/local/apache/bin/apxs \ --enable-maintainer-zts \ --with-mysql=mysqlnd \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-iconv-dir \ --with-freetype-dir \ --with-jpeg-dir \ --with-png-dir \ --with-zlib \ --with-libxml-dir \ --enable-xml \ --disable-rpath \ --enable-bcmath \ --enable-shmop \ --enable-sysvsem \ --enable-inline-optimization \ --with-curl \ --with-mcrypt \ --enable-mbregex \ --enable-mbstring \ --with-gd \ --enable-gd-native-ttf \ --with-openssl \ --with-mhash \ --enable-pcntl \ --enable-sockets \ --with-xmlrpc \ --enable-zip \ --with-bz2 \ --enable-soap \ --without-pear ~~~ ### make && make install httpd配置文件中多了一段 ~~~ LoadModule php5_module modules/libphp5.so ~~~ ## php提供配置文件 在php源码文件下 ~~~ # cp php.ini-production /usr/local/php/etc/php.ini ~~~ 暂不用修改,php配置到此告一段落 编辑apache配置文件httpd.conf,使apache支持php ~~~ # vim /etc/httpd/httpd.conf ~~~ 定位至DirectoryIndex index.html修改为 ### httpd 2.4 ~~~ <FilesMatch \.php$> DirectoryIndex index.php index.html SetHandler application/x-httpd-php </FilesMatch> ~~~ ### http 2.2 ~~~ DirectoryIndex index.php index.html AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps php源码 ~~~ 而后重新启动httpd,可测试php是否已经可以正常使用。使用phpinfo()注意测试页面要以php结尾。 若此处测试页面不正常,说明此处配置有问题。 >[danger] 报错1 此处需要restart,否则出现如下错误 [Fri Oct 07 16:14:13.545279 2016] [core:notice] [pid 76492:tid 139657221011200] AH00052: child pid 46888 exit signal Segmentation fault (11) 报错2 configure: error: xml2-config not found. Please check your libxml2 installation. find / -name "xml2-config" /usr/bin/xml2-config --with-libxml-dir=/usr/bin 或者--with-libxml-dir [1]:http://php.net/downloads.php