php-7.2.10編譯安裝過程php
[root@localhost ~]# cat /etc/redhat-releasehtml
CentOS Linux release 7.2.1511 (Core) python
[root@localhost ~]# ifconfigmysql
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500linux
inet 192.168.10.10 netmask 255.255.255.0 broadcast 192.168.10.255nginx
inet6 fe80::20c:29ff:fe48:bb2f prefixlen 64 scopeid 0x20<link>c++
ether 00:0c:29:48:bb:2f txqueuelen 1000 (Ethernet)正則表達式
RX packets 95999 bytes 124353019 (118.5 MiB)sql
RX errors 0 dropped 0 overruns 0 frame 0shell
TX packets 39612 bytes 4818173 (4.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# getenforce
Disabled
[root@localhost ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
注意:這裏必定要配置好網絡yum源和epel源,這對於後面安裝依賴會減小麻煩,若是配置的是內網源,必定要確保內網中有相關的php依賴包,針對沒有的依賴包,能夠到相關網站下載好依賴包上傳到服務器。不然,安裝過程確定不順利。
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost ~]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
注意:這裏涉及到的軟件包最好都安裝上,若是缺乏相關依賴,後面安裝php會報錯,會給安裝增長很多麻煩,以前都是一步步踩坑過來的。
[root@localhost ~]# yum -y install gcc gcc-c++ libmcrypt-devel mcrypt mhash gd-devel ncurses-devel libxml2-devel bzip2-devel libcurl-devel curl-devel libjpeg-devel libpng-devel freetype-devel net-snmp-devel openssl-deve python-devel zlib-devel freetype libxslt* bison autoconf re2c
[root@localhost ~]# wget http://cn2.php.net/distributions/php-7.2.10.tar.gz
[root@localhost ~]# tar -xf php-7.2.10.tar.gz
[root@localhost php-7.2.10]# ./configure \
--prefix=/usr/local/php \
--exec-prefix=/usr/local/php \
--bindir=/usr/local/php/bin \
--sbindir=/usr/local/php/sbin \
--includedir=/usr/local/php/include \
--libdir=/usr/local/php/lib/php \
--mandir=/usr/local/php/php/man \
--with-config-file-path=/usr/local/php/etc \
--with-mysql-sock=/var/run/mysql/mysql.sock \
--with-mhash \
--with-openssl \
--with-mysqli=shared,mysqlnd \
--with-pdo-mysql=shared,mysqlnd \
--with-gd \
--with-iconv \
--with-zlib \
--enable-zip \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-pcntl \
--enable-calendar \
--enable-exif \
--enable-sockets \
--with-xmlrpc \
--with-libxml-dir \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-curl \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-bz2 \
--enable-opcache \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--without-gdbm \
--enable-fast-install \
--disable-fileinfo
[root@localhost php-7.2.10]# make && make install
[root@localhost php-7.2.10]# cd ..
[root@localhost ~]# /usr/local/php/bin/php -v #到這裏就說明php已經安裝成功
PHP 7.2.10 (cli) (built: Oct 3 2018 18:03:11) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
configure選項 |
選項做用 |
--prefix=/usr/local/php |
php安裝的根目錄 |
--exec-prefix=/usr/local/php |
php執行文件所在目錄 |
--bindir=/usr/local/php/bin |
php的bin目錄所在位置 |
--sbindir=/usr/local/php/sbin |
php的sbin目錄所在位置 |
--includedir=/usr/local/php/include |
php包含文件所在目錄 |
--libdir=/usr/local/php/lib/php |
php的lib目錄所在位置 |
--mandir=/usr/local/php/php/man |
php的man目錄所在位置 |
--with-config-file-path=/usr/local/php/etc |
php的配置文件目錄所在位置 |
--with-mysql-sock=/var/run/mysql/mysql.sock |
php的Unix socket通訊文件 |
--with-mcrypt |
php裏面重要的加密支持擴展庫,linux環境下該庫在默認狀況下不開啓 |
--with-mhash |
Mhash是基於離散數學原理的不可逆向的php加密方式擴展庫,其在默認狀況下不開啓 |
--with-openssl |
OpenSSL 是一個安全套接字層密碼庫 |
--with-mysqli=shared,mysqlnd |
php依賴mysql庫 |
--with-pdo-mysql=shared,mysqlnd |
php依賴mysql庫 |
--with-gd |
gd庫 |
--with-iconv |
關閉iconv函數,字符集間的轉換 |
--with-zlib |
zlib是提供數據壓縮用的函式庫 |
--enable-zip |
打開對zip的支持 |
--enable-inline-optimization |
優化線程 |
--disable-debug |
關閉調試模式 |
--disable-rpath |
關閉額外的運行庫文件 |
--enable-shared |
啓用動態庫 |
--enable-xml |
開啓xml擴展 |
--enable-bcmath |
打開圖片大小調整,用到zabbix監控的時候用到了這個模塊 |
--enable-shmop |
共享內存 |
--enable-sysvsem |
內存共享方案 |
--enable-mbregex |
開啓多字節正則表達式的字符編碼 |
--enable-mbstring |
開啓多字節字符串函數 |
--enable-ftp |
打開ftp的支持 |
--enable-pcntl |
PHP的進程控制支持實現了Unix方式的多進程建立 |
--enable-calendar |
打開日曆擴展功能 |
--enable-sockets |
開啓套接字 |
--enable-exif |
開啓圖片的元數據支持 |
--with-xmlrpc |
打開xml-rpc的c語言 |
--enable-soap |
開啓簡單對象訪問協議簡單對象訪問協議 |
--without-pear |
開啓php擴展與應用庫 |
--with-gettext |
開戶php在當前域中查找消息 |
--enable-session |
容許php會話session |
--with-curl |
容許curl擴展 |
--with-jpeg-dir |
指定jpeg安裝目錄yum安裝事後不用再次指定會自動找到 |
--with-png-dir |
打開對png圖片的支持 |
--with-freetype-dir |
指定freetype安裝目錄yum安裝事後不用再次指定會自動找到 |
--with-bz2 |
打開對bz2文件的支持 |
--with-libxml-dir |
打開libxml2庫的支持 |
--enable-opcache |
開啓使用opcache緩存 |
--enable-fpm |
開啓fpm |
--with-fpm-user=nginx |
php-fpm的用戶 |
--with-fpm-group=nginx |
php-fpm的用戶組 |
--without-gdbm |
數據庫函數使用可擴展散列和相似於標準UNIX dbm的工做 |
--enable-fast-install |
爲快速安裝優化 |
--disable-fileinfo |
禁用fileinfo支持 |
[root@localhost ~]# useradd nginx
[root@localhost ~]# cd php-7.2.10
[root@localhost php-7.2.10]# cp -a php.ini-production /usr/local/php/etc/php.ini
[root@localhost php-7.2.10]# ln -s /usr/local/php7/etc/php.ini /etc/php.ini
[root@localhost ~]# vim /usr/local/php/etc/php.ini
#找到下面的參數並修改爲下面的樣子
disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
#列出PHP能夠禁用的函數,若是某些程序須要用到這個函數,能夠刪除取消禁用
date.timezone = Asia/shanghai #指定時區爲上海
expose_php = Off #禁止顯示PHP版本
short_open_tag = ON #支持PHP短標籤
opcache.enable=1 #PHP支持opcode緩存
opcache.enable_cli=0
extension=mysqli.so
extension=pdo_mysql.so
zend_extension=opcache.so #在最後一行添加,開啓opcode緩存功能
:wq #保存退出
[root@localhost ~]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@localhost ~]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
[root@localhost ~]# cd php-7.2.10
[root@localhost php-7.2.10]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost ~]# chmod +x /etc/rc.d/init.d/php-fpm
[root@localhost ~]# chkconfig --add php-fpm
[root@localhost ~]# chkconfig php-fpm on
[root@localhost ~]# echo 'export PATH=$PATH:/usr/local/php/bin/:/usr/local/php/sbin/' >>/etc/profile
[root@localhost ~]# source /etc/profile
[root@localhost ~]# systemctl start php-fpm
[root@localhost ~]# ss -ant|grep 9000
LISTEN 0 128 127.0.0.1:9000 *:*
[root@localhost ~]# yum -y install nginx
[root@localhost ~]# vim /etc/nginx/nginx.conf
#把下面一段插入到server標籤內
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;
}
[root@localhost ~]# vim /usr/share/nginx/html/index.php #添加一個測試的php網頁文件
<?php
phpinfo();
?>
[root@localhost ~]# systemctl start nginx
訪問咱們配置的服務器IP地址192.168.10.10,就出現了下面的nginx歡迎界面。
接着瀏覽器訪問192.168.10.10/index.php,出現下面的頁面說明咱們的PHP沒有問題
到此PHP環境已經安裝並配置完成,生產環境使用時,須要根據實際需求進行配置。