(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已完全安裝。