源码编译安装
官网
- 官网:http://php.net/
- 官网下载:http://php.net/downloads.php
了解与准备
Apache(httpd) nginx 与 php 连接方式:
httpd与php:
- php 作为 httpd 模块
- fastcgi(php-fpm)
- cgi(此处不讲解)
nginx与php:
- fastcgi(php-fpm)
PHP安装与依赖:
yum -y install gcc gcc-c++ libxml2 libxml2-devel bzip2 bzip2-devel libmcrypt libmcrypt-devel openssl openssl-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel readline readline-devel libxslt-devel perl perl-devel psmisc.x86_64 recode recode-devel libtidy libtidy-devel |
- 上面的依赖基本解决所需要的依赖。
- 编译安装完成后可以增减所支持的php模块,此处所编译的模块已经非常完备。
- 需要编译单个模块,查看php模块编译方式:php模块编译
- 下面编译安装的配置选项:
- –prefix=/usr/local/php7 主程序文件路径
- –sysconfdir=/etc/php7 配置文件路径
- –with-config-file-path=/etc/php7 php.ini 文件路径
- –with-apxs2=/usr/local/httpd/bin/apxs 以 httpd 模块编译时需要指定 httpd 的 apxs 文件路径。
- 其他的配置可以按自己需求指定,这几个选项也可以使用默认配置。
- php7移除了 mysql 扩展,php7仅能是用 mysqli 和 pdo_mysql。php5可以使用。 php5编译时加入选项:–with-mysql 。详情查看下面的 PHP与MariaDB(mysql)连接
- 此处以 CentOs7 编译 php7 为示例,配合讲解php5安装的要点。
- php.ini 文件是在包目录下的 php.ini-development(开发), php.ini-production(生产)
编译完成后选择自己需要的 php.ini 文件 复制到 –with-config-file-path 指定的目录。
如果编译时为指定此选项,编译完成配置并启动nginx和php查看 phpinfo() 函数所指定的 php.ini 文件路径:Configuration File (php.ini) Path
默认为php目录下的 lib 目录。 - PHP安装与依赖中 psmisc.x86_64 是 killall 命令的包名,以便最小化安装时终止进程。
php编译与配置
httpd 模块
./configure –prefix=/usr/local/php5 –sysconfdir=/etc/php5 –with-config-file-path=/etc/php5 –with-apxs2=/usr/local/httpd/bin/apxs –with-mysql=mysqlnd –with-mysqli=mysqlnd –with-pdo-mysql=mysqlnd –with-mhash –with-openssl –with-zlib –with-bz2 –with-curl –with-libxml-dir –with-gd –with-jpeg-dir –with-png-dir –with-zlib –enable-mbstring –with-mcrypt –enable-sockets –with-iconv-dir –with-xsl –enable-zip –with-pcre-dir –with-pear –enable-session –enable-gd-native-ttf –enable-xml –with-freetype-dir –enable-gd-jis-conv –enable-inline-optimization –enable-shared –enable-bcmath –enable-sysvmsg –enable-sysvsem –enable-sysvshm –enable-mbregex –enable-pcntl –with-xmlrpc –with-gettext –enable-exif –with-readline –with-recode –with-tidy |
仅增加了选项--with-mysql=mysqlnd
./configure –prefix=/usr/local/php7 –sysconfdir=/etc/php7 –with-config-file-path=/etc/php7 –with-apxs2=/usr/local/httpd/bin/apxs –with-mysqli=mysqlnd –with-pdo-mysql=mysqlnd –with-mhash –with-openssl –with-zlib –with-bz2 –with-curl –with-libxml-dir –with-gd –with-jpeg-dir –with-png-dir –with-zlib –enable-mbstring –with-mcrypt –enable-sockets –with-iconv-dir –with-xsl –enable-zip –with-pcre-dir –with-pear –enable-session –enable-gd-native-ttf –enable-xml –with-freetype-dir –enable-gd-jis-conv –enable-inline-optimization –enable-shared –enable-bcmath –enable-sysvmsg –enable-sysvsem –enable-sysvshm –enable-mbregex –enable-pcntl –with-xmlrpc –with-gettext –enable-exif –with-readline –with-recode –with-tidy |
fastcgi php-fpm 模式
./configure –prefix=/usr/local/php5 –sysconfdir=/etc/php5 –with-config-file-path=/etc/php5 –enable-fpm –with-mysql=mysqlnd –with-mysqli=mysqlnd –with-pdo-mysql=mysqlnd –with-mhash –with-openssl –with-zlib –with-bz2 –with-curl –with-libxml-dir –with-gd –with-jpeg-dir –with-png-dir –with-zlib –enable-mbstring –with-mcrypt –enable-sockets –with-iconv-dir –with-xsl –enable-zip –with-pcre-dir –with-pear –enable-session –enable-gd-native-ttf –enable-xml –with-freetype-dir –enable-gd-jis-conv –enable-inline-optimization –enable-shared –enable-bcmath –enable-sysvmsg –enable-sysvsem –enable-sysvshm –enable-mbregex –enable-pcntl –with-xmlrpc –with-gettext –enable-exif –with-readline –with-recode –with-tidy |
仅增加了选项 --with-mysql=mysqlnd
./configure –prefix=/usr/local/php7 –sysconfdir=/etc/php7 –with-config-file-path=/etc/php7 –enable-fpm –with-mysqli=mysqlnd –with-pdo-mysql=mysqlnd –with-mhash –with-openssl –with-zlib –with-bz2 –with-curl –with-libxml-dir –with-gd –with-jpeg-dir –with-png-dir –with-zlib –enable-mbstring –with-mcrypt –enable-sockets –with-iconv-dir –with-xsl –enable-zip –with-pcre-dir –with-pear –enable-session –enable-gd-native-ttf –enable-xml –with-freetype-dir –enable-gd-jis-conv –enable-inline-optimization –enable-shared –enable-bcmath –enable-sysvmsg –enable-sysvsem –enable-sysvshm –enable-mbregex –enable-pcntl –with-xmlrpc –with-gettext –enable-exif –with-readline –with-recode –with-tidy |
整合httpd和fastcgi php-fpm模式
--with-apxs2(需要apxs程序) |
./configure --prefix=/opt/laohulab/php5.6.31 --sysconfdir=/opt/laohulab/php5.6.31/etc --with-config-file-path=/opt/laohulab/php5.6.31/etc --with-config-file-scan-dir=/opt/laohulab/php5.6.31/etc.d --with-apxs2 --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mhash --with-openssl --with-zlib --with-bz2 --with-curl --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-zlib --enable-mbstring --with-mcrypt --enable-sockets --with-iconv-dir --with-xsl --enable-zip --with-pcre-dir --with-pear --enable-session --enable-gd-native-ttf --enable-xml --with-freetype-dir --enable-gd-jis-conv --enable-inline-optimization --enable-shared --enable-bcmath --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-mbregex --enable-pcntl --with-xmlrpc --with-gettext --enable-exif --with-readline --with-recode --with-tidy |
php.ini 配置文件(在源码包目录下)
[root@nginx-10-20 php-5.6.31]# pwd |
php 作为 httpd 模块
不需要修改 php 配置
fastcgi php-fpm
cp /etc/php7/php-fpm.conf.default /etc/php7/php-fpm.conf |
启动与停止
httpd模块: |
加入环境变量
PHP=/opt/laohulab/php |
CentOS 系统服务(/etc/php7/php-fpm.conf 文件 pid = run/php-fpm.pid 注释需要打开:2.6 )
|
service php-fpm {start|stop|status|restart|reload|force-reload|condrestart|try-restart|configtest} |
|
systemctl (start | restart | reload | stop | enable | disable | status) php-fpm.service |
系统启动服务
|
|
加入 man 文档
vim /etc/man.config |
vi /etc/man_db.conf |
然后就可以使用 man 命令查看
httpd nginx 与 php 连接
httpd 模块 php
要点: |
httpd(fastcgi)与 php-fpm
要点: |
Nginx与php连接
要点: |
PHP与MariaDB(mysql)连接
4.1:使用 MariaDB 编译(相对于mysql安装的目录) |
测试
1.1:添加文件与内容 |
php多版本安装注意事项
6.1:httpd与php |
参考
- http://php.net/manual/zh/install.php(官网安装帮助文档)
- http://cnzhx.net/blog/apache-httpd-mod_proxy_fcgi-php-fpm/
- http://blog.csdn.net/u010861514/article/details/51926575