(1)源码包下载
百度云下载地址:https://pan.baidu.com/s/1xH7aiGYaX62wij4ul5P-ZQ
提取码:m9zc
(2)安装php依赖组件:
yum -y install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel
(3)解压源码包并进入目录配置
cp -frp /usr/lib64/libldap* /usr/lib/
./configure \ --prefix=/usr/local/php \ --with-apxs2=/usr/local/apache2/bin/apxs \ --with-config-file-path=/usr/local/php/etc \ --enable-mysqlnd \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --enable-pdo \ --with-iconv-dir \ --with-freetype-dir \ --with-jpeg-dir \ --with-png-dir \ --with-zlib \ --with-libxml-dir= \ --enable-xml \ --enable-session \ --disable-rpath \ --enable-bcmath \ --enable-shmop \ --enable-sysvsem \ --enable-inline-optimization \ --with-curl \ --enable-mbregex \ --enable-mbstring \ --enable-intl \ --enable-pcntl \ --enable-ftp \ --with-gd \ --with-openssl \ --with-mhash \ --enable-pcntl \ --enable-sockets \ --with-xmlrpc \ --enable-zip \ --enable-soap \ --with-gettext \ --disable-fileinfo \ --enable-opcache \ --enable-maintainer-zts \ --with-xsl \ --enable-tokenizer
(4)编译与安装
make -j 4 && make install
(5)完成安装后配置php.ini文件:
cp /usr/local/src/php-7.2.12/php.ini-development /usr/local/php/etc/php.ini
修改 php.ini 相关参数:
mysqli.default_socket = /usr/local/mysql/mysql.sock ;将php与mysql关联 date.timezone = Asia/Shanghai ;时区设置 expose_php = Off ;隐藏 “X-Powered-By: PHP/5.2.13” 这个信息。 short_open_tag = ON ;开启短标签 max_execution_time = 300 ;脚本的最大执行时间 max_input_time = 300 memory_limit = 128M post_max_size = 32M
(6)验证安装的模块
/usr/local/php/bin/php –m
(7)关联php与apache服务
编辑Apache配置文件,使httpd支持php网页解析:
添加以下两行内容:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
修改以下内容:
DirectoryIndex index.php index.html ;此处注意,php文件必须放前面,优先读取
至此,PHP已完全安装。