Linux下安装php-5.5.3
一、所需要的组件包:
libxml2 zlib-devel libxml2-devel bzip2 bzip2-devel libcurl autoconf automake libidn-devel libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libmcrypt libmcrypt-devel
二、安装php
tar -zxvf php-5.5.3.tar.gz
得到php-5.5.3
cd php-5.5.3
./configure --prefix=/usr/local/php --with-config-file-path=/etc/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mariadb --with-mysqli=/usr/local/mariadb/bin/mysql_config --with-pdo-mysql=/usr/local/mariadb --with-fpm-user=apache --with-fpm-group=apaches --enable-fpm --enable-mbstring --enable-sockets --enable-pcntl --enable-zip --enable-bcmath --with-zlib-dir --with-bz2 --with-freetype-dir --with-gd --with-libxml-dir --with-png-dir --with-jpeg-dir --with-mcrypt --with-curl --with-iconv --enable-libxml --enable-xml --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-ftp --enable-gd-native-ttf --with-openssl --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --enable-ctype --enable-maintainer-zts
make
make install
安装成功的提示界面为:
cp php.ini-production /etc/php/php.ini //拷贝配置文件 date.timezone = PRC //设置时区 session.save_path = "/tmp" //开启session目录
三、 接下来配置Apache,使其支持php
vi /usr/local/apache/conf/httpd.conf
在DirectoryIndex 一行后添加 index.php
添加位置以及结果图为:

找到 AddType application/x-gzip .gz .tgz 在其下添加如下内容
AddType application/x-httpd-php .php .php3 AddType application/x-httpd-php-source .phps

service httpd restart
四、配置php-fpm
修改/usr/local/php/etc/php-fpm.conf文件
参数说明:
error_log string
错误日志的位置. 默认: 安装路径#INSTALL_PREFIX#/log/php-fpm.log.
log_level string
错误级别. 可用级别为: alert(必须立即处理), error(错误情况), warning(警告情况), notice(一般重要信息), debug(调试信息). 默认: notice.
emergency_restart_threshold int
如果子进程在emergency_restart_interval设定的时间内收到该参数设定次数的SIGSEGV 或者 SIGBUS退出信息号,则FPM会重新启动。 0 表示 ‘关闭该功能’. 默认值: 0 (关闭).
emergency_restart_interval mixed
emergency_restart_interval用于设定平滑重启的间隔时间. 这么做有助于解决加速器中共享内存的使用问题. 可用单位: s(秒), m(分), h(小时), 或者 d(天). 默认单位: s(秒). 默认值: 0 (关闭).
process_control_timeout mixed
设置子进程接受主进程复用信号的超时时间. 可用单位: s(秒), m(分), h(小时), 或者 d(天) 默认单位: s(秒). 默认值: 0.
daemonize boolean
设置FPM在后台运行. 设置 ‘no’ 将 FPM 保持在前台运行用于调试. 默认值: yes.
运行配置区段
在FPM中,可以使用不同的设置来运行多个进程池。 这些设置可以针对每个进程池单独设置。
listen string
设置接受FastCGI请求的地址. 可用格式为: ‘ip:port’, ‘port’, ‘/path/to/unix/socket’. 每个进程池都需要设置.
listen.backlog int
设置 listen(2) 的半连接队列长度. ‘-1′ 表示无限制. 默认值: -1.
listen.allowed_clients string
设置允许连接到FastCGI的服务器IPV4地址. 等同于PHP FastCGI (5.2.2+)中的 FCGI_WEB_SERVER_ADDRS环境变量. 仅对TCP监听起作用. 每个地址是用逗号分隔. 如果没有设置或者为空,则允许任何服务器请求连接. 默认值: any.
listen.owner string
如果使用,表示设置Unix套接字的权限. 在Linux中,读写权限必须设置,以便用于WEB服务器连接. 在很多BSD派生的系统中可以忽略权限允许自由连接. 默认值: 运行所使用的用户合租, 权限为0666.
listen.group string
参见 listen.owner.
listen.mode string
参见 listen.owner.
user string
FPM 进程运行的Unix用户. 必须设置.
group string
FPM 进程运行的Unix用户组. 如果没有设置,则默认用户的组被使用.
pm string
设置进程管理器如何管理子进程. 可用值: static, dynamic. 必须设置.
static – 子进程的数量是固定的 (pm.max_children).
dynamic – 子进程的数量在下面配置的基础上动态设置: pm.max_children, pm.start_servers, pm.min_spare_servers, pm.max_spare_servers.
pm.max_children int
子进程的数量,pm 设置为 static 时表示创建的, pm 设置为 dynamic 时表示最大可创建的. 必须设置.
该选项设置可以同时提供服务的请求数限制. 类似 Apache 的 mpm_prefork 中 MaxClients 的设置和 普通PHP FastCGI中的 PHP_FCGI_CHILDREN 环境变量.
pm.start_servers in
设置启动时创建的子进程数目. 仅在 pm 设置为 dynamic 时使用. 默认值: min_spare_servers + (max_spare_servers – min_spare_servers) / 2.
pm.min_spare_servers int
设置空闲服务进程的最低数目. 仅在 pm 设置为 dynamic 时使用. 必须设置.
pm.max_spare_servers int
设置空闲服务进程的最大数目. 仅在 pm 设置为 dynamic 时使用. 必须设置.
pm.max_requests int
设置每个子进程重生之前服务的请求数. 对于可能存在内存泄漏的第三方模块来说是非常有用的. 如果设置为 ’0′ 则一直接受请求. 等同于 PHP_FCGI_MAX_REQUESTS 环境变量. 默认值: 0.
pm.status_path string
FPM状态页面的网址. 如果没有设置, 则无法访问状态页面. 默认值: none.
ping.path string
FPM监控页面的ping网址. 如果没有设置, 则无法访问ping页面. 该页面用于外部检测FPM是否存活并且可以响应请求. 请注意必须以斜线开头 (/).
ping.response string
用于定义ping请求的返回相应. 返回为 HTTP 200 的 text/plain 格式文本. 默认值: pong.
request_terminate_timeout mixed
设置单个请求的超时中止时间. 该选项可能会对php.ini设置中的’max_execution_time’因为某些特殊原因没有中止运行的脚本有用. 设置为 ’0′ 表示 ‘Off’. Available units: s(econds)(default), m(inutes), h(ours), or d(ays). Default value: 0.
request_slowlog_timeout mixed
当一个请求该设置的超时时间后,就会将对应的PHP调用堆栈信息完整写入到慢日志中. 设置为 ’0′ 表示 ‘Off’. 可用单位: s(秒)(默认), m(分), h(小时), 或者 d(天). 默认值: 0.
slowlog string
慢请求的记录日志. 默认值: #INSTALL_PREFIX#/log/php-fpm.log.slow.
rlimit_files int
设置文件打开描述符的rlimit限制. 默认值: 系统定义值.
rlimit_core int
设置核心rlimit最大限制值. 可用值: ‘unlimited’ 、0或者正整数. 默认值: 系统定义值.
chroot string
启动时的Chroot目录. 所定义的目录需要是绝对路径. 如果没有设置, 则chroot不被使用.
chdir string
设置启动目录,启动时会自动Chdir到该目录. 所定义的目录需要是绝对路径. 默认值: 当前目录,或者/目录(chroot时).
catch_workers_output boolean
重定向运行过程中的stdout和stderr到主要的错误日志文件中. 如果没有设置, stdout 和 stderr 将会根据FastCGI的规则被重定向到 /dev/null . 默认值: 空.
然后设置开机自动启动
cp {php-5.5.x-source-dir}/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chmod 755 /etc/init.d/php-fpm chkconfig --add php-fpm chkconfig php-fpm on
五、测试
echo "<?php phpinfo(); ?>" >/var/www/html/index.php //"/var/www/html/"为apache配置的网页存放目录
yeboyzq
php7安装编译
./configure --prefix=/usr/local/php --with-config-file-path=/etc/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysqli=/usr/local/mariadb/bin/mysql_config --with-pdo-mysql=/usr/local/mariadb --with-fpm-user=apache --with-fpm-group=apaches --enable-fpm --enable-mbstring --enable-sockets --enable-pcntl --enable-zip --enable-bcmath --with-zlib-dir --with-bz2 --with-freetype-dir --with-iconv-dir --with-gd --with-libxml-dir --with-iconv-dir --with-png-dir --with-jpeg-dir --with-mcrypt --with-curl --with-iconv --enable-libxml --enable-xml --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-ftp --enable-gd-native-ttf --with-openssl --with-mhash --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --enable-ctype --enable-maintainer-zts --disable-rpath
yeboyzq
./configure --prefix=/usr/local/php --with-config-file-path=/etc --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mariadb --with-mysqli=/usr/local/mariadb/bin/mysql_config --with-pdo-mysql=/usr/local/mariadb/ --enable-mbstring --enable-sockets --enable-pcntl --enable-zip --enable-bcmath --with-zlib-dir --with-bz2 --with-freetype-dir --with-gd --with-libxml-dir --with-png-dir --with-jpeg-dir --with-mcrypt --with-curl --with-iconv --enable-libxml --enable-xml --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-ftp --enable-gd-native-ttf --with-openssl --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --enable-ctype
yeboyzq
@yeboyzq ./configure --prefix=/usr/local/php --with-config-file-path=/etc/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mariadb --with-mysqli=/usr/local/mariadb/bin/mysql_config --with-pdo-mysql=/usr/local/mariadb/ --with-fpm-user=apache --with-fpm-group=apaches --enable-fpm --enable-mbstring --enable-sockets --enable-pcntl --enable-zip --enable-bcmath --with-zlib-dir --with-bz2 --with-freetype-dir --with-gd --with-libxml-dir --with-png-dir --with-jpeg-dir --with-mcrypt --with-curl --with-iconv --enable-libxml --enable-xml --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-ftp --enable-gd-native-ttf --with-openssl --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --enable-ctype
yeboyzq
@yeboyzq --without-pear