下载 PHP 源码包并解压php
$ wget https://www.php.net/distributions/php-7.2.19.tar.bz2 $ yum -y install bzip2 # 若是有能够不用安装 $ tar -jxvf php-7.2.19.tar.bz2
进入 PHP 源码包目录html
$ cd php-7.2.19
经常使用配置项及其说明 若是看着麻烦能够直接看下面的总结步骤mysql
--prefix=/usr/local/php7 # 配置安装目录 --with-config-file-path=/usr/local/php7 # 配置文件 php.ini 的路径 --enable-sockets # 开启 socket --enable-fpm # 启用 fpm 扩展 --enable-cli # 启用 命令行模式 (从 php 4.3.0 以后这个模块默认开启因此能够不用再加此命令) --enable-mbstring # 启用 mbstring 库 --enable-pcntl # 启用 pcntl (仅 CLI / CGI) --enable-soap # 启用 soap --enable-opcache # 开启 opcache 缓存 --disable-fileinfo # 禁用 fileinfo (因为 5.3+ 以后已经再也不持续维护了,但默认是开启的,因此仍是禁止了吧)(1G如下内存服务器直接关了吧) --disable-rpath #禁用在搜索路径中传递其余运行库。 --with-mysqli # 启用 mysqli 扩展 --with-pdo-mysql # 启用 pdo 扩展 --with-iconv-dir # 启用 XMLRPC-EPI 字符编码转换 扩展 --with-openssl # 启用 openssl 扩展 (须要 openssl openssl-devel) --with-fpm-user=www #设定 fpm 所属的用户 --with-fpm-group=www #设定 fpm 所属的组别 --with-curl # 启用 curl 扩展 --with-mhash # 开启 mhash 基于离散数学原理的不可逆向的php加密方式扩展库 # GD --with-gd # 启用 GD 图片操做 扩展 --with-jpeg-dir # 开启对 jpeg 图片的支持 (须要 libjpeg) --with-png-dir # 开启对 png 图片支持 (须要 libpng) --with-freetype-dir # 开启 freetype # 压缩 --enable-zip # 启用 zip --with-zlib # 启用对 zlib 支持 # xml --enable-simplexml # 启用对 simplexml 支持 --with-libxml-dir # 启用对 libxml2 支持
一些不经常使用的选项nginx
--enable-debug 开启 debug 模式
执行 configure 配置 若是看着麻烦能够直接看下面的总结步骤sql
$ ./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7 --enable-sockets --enable-fpm --enable-cli --enable-mbstring --enable-pcntl --enable-soap --enable-opcache --disable-fileinfo --disable-rpath --with-mysqli --with-pdo-mysql --with-iconv-dir --with-openssl --with-fpm-user=www --with-fpm-group=www --with-curl --with-mhash --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-zip --with-zlib --enable-simplexml --with-libxml-dir === 第 [1] 尝试 === ... configure: error: libxml2 not found. Please check your libxml2 installation. # 安装 libxml2 库 $ yum -y install libxml2 libxml2-devel === 第 [2] 尝试 === ... configure: error: Cannot find OpenSSL\'s <evp.h> # 安装 openssl 库 $ yum -y install openssl openssl-devel === 第 [3] 尝试 === ... checking for cURL 7.10.5 or greater... configure: error: cURL version 7.10.5 or later is required to compile php with cURL support # 安装 curl 库 $ yum -y install libcurl libcurl-devel === 第 [4] 尝试 === ... configure: error: jpeglib.h not found. # 安装 libjpeg 顺便 把 libpng 也装上 $ yum -y install libjpeg libjpeg-devel libpng libpng-devel === 第 [5] 尝试 === ... configure: error: freetype-config not found. # 安装 freetype 库 $ yum -y install freetype freetype-devel === 第 [6] 尝试 === +--------------------------------------------------------------------+ | License: | | This software is subject to the PHP License, available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | +--------------------------------------------------------------------+ Thank you for using PHP. ... # 成功 $ make && make install
安装总结vim
$ wget https://www.php.net/distributions/php-7.2.19.tar.bz2 $ yum -y install bzip2 # 若是有能够不用安装 $ tar -jxvf php-7.2.19.tar.bz2 $ cd php-7.2.19 $ yum -y install libxml2 libxml2-devel openssl openssl-devel libcurl libcurl-devel install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel # **此处的 —prefix 安装目录能够不和我同样** $ ./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7 --enable-sockets --enable-fpm --enable-cli --enable-mbstring --enable-pcntl --enable-soap --enable-opcache --disable-fileinfo --disable-rpath --with-mysqli --with-pdo-mysql --with-iconv-dir --with-openssl --with-fpm-user=www --with-fpm-group=www --with-curl --with-mhash --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-zip --with-zlib --enable-simplexml --with-libxml-dir $ make && make install
$ cp php-7.2.19/php.ini-production /usr/local/php/php.ini # 复制 php.ini 文件到目录 $ vi /usr/local/nginx/conf/nginx.conf ... http { ... server { ... # 把 [1] 换成 [2] # 让 nginx 支持 php 文件 #[1] location / { root html; index index.html index.htm; } #[2] location / { root html; index index.php index.html index.htm; } ... # 把 [1] 换成 [2] # 配置监听 php 端口 # 注意: 要把 /scripts 换成 $document_root #[1] #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} #[2] location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } ... } # 重启 php-fpm $ pkill -9 php-fpm $ /usr/local/php7/sbin/php-fpm
# 复制启动脚本到 init.d 目录 $ cp php-7.2.19/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm # 增长执行权限 $ chmod +x /etc/init.d/php-fpm # 配置 php-fpm 文件 $ cd /usr/local/php7/etc/ $ cp php-fpm.conf.default php-fpm.conf # 进入 php-fpm.conf , 并去除 pid = run/php-fpm.pid 的注释 $ vim php-fpm.conf === ... [global] ; Pid file ; Note: the default prefix is /usr/local/php7/var ; Default Value: none # 取消下面的注释 pid = run/php-fpm.pid ... === # 复制 www.conf 文件 $ cp php-fpm.d/www.conf.default php-fpm.d/www.conf # 重启 php 服务器 $ pkill -9 php-fpm $ /usr/local/nginx/php7/sbin/php-fpm # 测试 $ /etc/init.d/php-fpm stop # 中止服务 Gracefully shutting down php-fpm . done $ /etc/init.d/php-fpm start # 启动服务 Starting php-fpm done $ /etc/init.d/php-fpm restart # 重启服务 Gracefully shutting down php-fpm . done Starting php-fpm done
# 启动(由于上面已经配置好启动脚本了,而且放到了 /etc/init.d 中因此下面命令是能够用的) # 在 centos7 中 systemctl 是找 /etc/init.d 中的脚本 $ systemctl start php-fpm # 启动 $ systemctl enable php-fpm # 自启动 php-fpm.service is not a native service, redirecting to /sbin/chkconfig. Executing /sbin/chkconfig php-fpm on # 这里他提示我 php-fpm 并非系统服务因此不能使用 systemctl 推荐我使用 /sbin/chkconfig php-fpm on 来实现自启动 $ /sbin/chkconfig php-fpm on 再次重启便可完成自启动 # 注: 若是不想配置 php-fpm 服务器化到此已经能够结束了,若是想看服务化能够看如下操做
# 在 centos 7 以后咱们可使用 systemctl 更好的管理系统服务 # 因此咱们也要让 php-fpm 支持 # 由于 php 7.2 源码包里面含有 systemctl 所须要的脚本文件 # 咱们只要复制过去便可,咱们来开始配置 # 进入下载的 php源码包 $ cd php-7.2.19/sapi/fpm # 复制其中的 php-fpm.service 到 /usr/lib/systemd/system/ $ cp php-fpm.service /usr/lib/systemd/system/ # 再次使用 systemctl enable php-fpm 进行配置自启动 $ systemctl enable php-fpm # 重启测试一下看看本身服务器的 php-fpm 是否成功运行