介紹:
久聞php7的速度以及性能那可是比php5系列的任何一版本都要快,具體性能有多好,建議還是先嘗試下再說(shuō)。如果你是升級(jí)或新安裝,那你首先需要考慮php7和程序是否存在兼容性,如果程序是基于php5開(kāi)發(fā)的,那么就需要考慮php7是否適合你當(dāng)前的生產(chǎn)環(huán)境,今天我就實(shí)操并安裝用于生產(chǎn)中。
先安裝php依賴包,否則在編譯安裝php7的過(guò)程當(dāng)中會(huì)出現(xiàn)各種報(bào)錯(cuò),安裝完成后即可進(jìn)入下一個(gè)環(huán)節(jié)。
安裝擴(kuò)展包并更新系統(tǒng)內(nèi)核:
$ yum install epel-release -y
$ yum update
安裝php依賴組件(包含Nginx依賴):
復(fù)制代碼 代碼如下:
$ 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
創(chuàng)建用戶和組,并下載php安裝包解壓:
$ 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
設(shè)置變量并開(kāi)始源碼編譯:
$ cp -frp /usr/lib64/libldap* /usr/lib/
$ ./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/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-mcrypt \
--with-libmbfl \
--enable-ftp \
--with-gd \
--enable-gd-jis-conv \
--enable-gd-native-ttf \
--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 \
若無(wú)報(bào)錯(cuò)執(zhí)行下一步安裝,如果編譯過(guò)程中出現(xiàn)錯(cuò)誤,根據(jù)報(bào)錯(cuò)安裝依賴包,通常不會(huì)出現(xiàn)這種問(wèn)題。
注意:–enable-gd-jis-conv 此參數(shù)會(huì)導(dǎo)致Zabbix中文字符亂碼,建議取消。
開(kāi)始安裝:
$ make -j 4 && make install
完成安裝后配置php.ini文件:
$ cp php.ini-development /usr/local/php/etc/php.ini
$ cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
$ cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
修改 php.ini 相關(guān)參數(shù):
$ 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-20160303/ldap.so"
設(shè)置 OPcache 緩存:
[opcache]
zend_extension=/usr/local/php/lib/php/extensions/no-debug-zts-20160303/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
設(shè)置php安全函數(shù):
$ vim /usr/local/php/etc/php.ini
默認(rèn)值:
修改為:
復(fù)制代碼 代碼如下:
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
或通配:
復(fù)制代碼 代碼如下:
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
配置www.conf
取消以下注釋并修改優(yōu)化其參數(shù):
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
創(chuàng)建php-cgi.sock存放目錄
$ mkdir /var/run/www/
$ chown -R www:www /var/run/www
配置php-fpm.conf
取下以下注釋并填寫完整路徑:
pid = /usr/local/php/var/run/php-fpm.pid
至此php7已經(jīng)安裝完成。
說(shuō)明:禁用php函數(shù),如果程序需要這些函數(shù),可以取消禁止,新手建議忽略此步驟。
創(chuàng)建system系統(tǒng)單元文件php-fpm啟動(dòng)腳本:
$ vim /usr/lib/systemd/system/php-fpm.service
添加如下變量?jī)?nèi)容:
[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
啟動(dòng)php-fpm服務(wù)并加入開(kāi)機(jī)自啟動(dòng):
$ systemctl enable php-fpm.service
$ systemctl restart php-fpm.service
PHP整個(gè)安裝過(guò)程已經(jīng)完成。如果你是按照本文安裝未成功的,希望你能留言說(shuō)明錯(cuò)誤原因,我將無(wú)償協(xié)助你配置。
如果你有好的建議完善該文章,非常歡迎你提出和改進(jìn),我們一起共同學(xué)習(xí)和進(jìn)步。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。