介紹:php
久聞php7的速度以及性能那但是比php5系列的任何一版本都要快,具體性能有多好,建議仍是先嚐試下再說。若是你是升級或新安裝,那你首先須要考慮php7和程序是否存在兼容性,若是程序是基於php5開發的,那麼就須要考慮php7是否適合你當前的生產環境,今天我就實操並安裝用於生產中。mysql
先安裝php依賴包,不然在編譯安裝php7的過程中會出現各類報錯,安裝完成後便可進入下一個環節。c++
安裝擴展包並更新系統內核:sql
yum install epel-release -y yum update
安裝php依賴組件(包含Nginx依賴):shell
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
建立用戶和組,並下載php安裝包解壓:vim
cd /tmp groupadd www useradd -g www www wget http://am1.php.net/distributions/php-7.2.1.tar.gz tar xvf php-7.2.1.tar.gz cd php-7.2.1
設置變量並開始源碼編譯:centos
cp -frp /usr/lib64/libldap* /usr/lib/
./configure --prefix=/usr/local/php72 \ --with-config-file-path=/usr/local/php72/etc \ --enable-fpm \ --with-fpm-user=www \ --with-fpm-group=www \ --enable-mysqlnd \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --enable-mysqlnd-compression-support \ --with-iconv-dir \ --with-freetype-dir \ --with-jpeg-dir \ --with-png-dir \ --with-zlib \ --with-libxml-dir \ --enable-xml \ --disable-rpath \ --enable-bcmath \ --enable-shmop \ --enable-sysvsem \ --enable-inline-optimization \ --with-curl \ --enable-mbregex \ --enable-mbstring \ --enable-intl \ --with-libmbfl \ --enable-ftp \ --with-gd \ --with-openssl \ --with-mhash \ --enable-pcntl \ --enable-sockets \ --with-xmlrpc \ --enable-zip \ --enable-soap \ --with-gettext \ --disable-fileinfo \ --enable-opcache \ --with-pear \ --enable-maintainer-zts \ --with-ldap=shared \ --without-gdbm \ --with-apxs2=/usr/bin/apxs
開始安裝:緩存
make && make install
完成安裝後配置php.ini文件:安全
cp php.ini-development /usr/local/php72/etc/php.ini cp /usr/local/php72/etc/php-fpm.conf.default /usr/local/php72/etc/php-fpm.conf cp /usr/local/php72/etc/php-fpm.d/www.conf.default /usr/local/php72/etc/php-fpm.d/www.conf
修改 php.ini 相關參數:php7
vim /usr/local/php/etc/php.ini
expose_php = Off short_open_tag = ON max_execution_time = 300 max_input_time = 300 memory_limit = 128M post_max_size = 32M date.timezone = Asia/Shanghai mbstring.func_overload=2 extension = "/usr/local/php/lib/php/extensions/no-debug-zts-20170718/ldap.so" #OPcache 緩存 [opcache] zend_extension=/usr/local/php/lib/php/extensions/no-debug-zts-20170718/opcache.so opcache.memory_consumption=128 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=4000 opcache.revalidate_freq=60 opcache.fast_shutdown=1 opcache.enable_cli=1 #設置php安全函數 ;disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru disable_functions = eval,assert,popen,passthru,escapeshellarg,escapeshellcmd,passthru,exec,system,chroot,chgrp,chown,escapeshellcmd,escapeshellarg,shell_exec,proc_get_status,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,leak,popepassthru,stream_socket_server,popen,proc_open,proc_close,phpinfo #配置www.conf listen = /var/run/www/php-cgi.sock listen.owner = www listen.group = www listen.mode = 0660 listen.allowed_clients = 127.0.0.1 pm = dynamic listen.backlog = -1 pm.max_children = 180 pm.start_servers = 50 pm.min_spare_servers = 50 pm.max_spare_servers = 180 request_terminate_timeout = 120 request_slowlog_timeout = 50 slowlog = var/log/slow.log
建立php-cgi.sock存放目錄
mkdir /var/run/www/ chown -R www:www /var/run/www
配置php-fpm.conf
vim /usr/local/php/etc/php-fpm.conf
取下如下注釋並填寫完整路徑:
pid = /usr/local/php/var/run/php-fpm.pid
至此php7已經安裝完成。
說明:禁用php函數,若是程序須要這些函數,能夠取消禁止,新手建議忽略此步驟。
建立system系統單元文件php-fpm啓動腳本:
vim /usr/lib/systemd/system/php-fpm.service
添加以下變量內容:
[Unit] Description=The PHP FastCGI Process Manager After=syslog.target network.target [Service] Type=simple PIDFile=/usr/local/php/var/run/php-fpm.pid ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf ExecReload=/bin/kill -USR2 $MAINPID [Install] WantedBy=multi-user.target
啓動php-fpm服務並加入開機自啓動:
systemctl enable php-fpm.service systemctl restart php-fpm.service