CentOS編譯安裝php7.2

來源:互聯網
上載者:User
這篇文章主要介紹了關於CentOS編譯安裝php7.2,有著一定的參考價值,現在分享給大家,有需要的朋友可以參考一下

介紹:

久聞php7的速度以及效能那可是比php5系列的任何一版本都要快,具體效能有多好,建議還是先嘗試下再說。如果你是升級或新安裝,那你首先需要考慮php7和程式是否存在相容性,如果程式是基於php5開發的,那麼就需要考慮php7是否適合你當前的生產環境,今天我就實操並安裝用於生產中。

先安裝php依賴包,否則在編譯安裝php7的過程當中會出現各種報錯,安裝完成後即可進入下一個環節。

安裝擴充包並更新系統核心:

yum install epel-release -yyum update

安裝php相依元件(包含Nginx依賴):

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安裝包解壓:

cd /tmpgroupadd wwwuseradd -g www wwwwget http://am1.php.net/distributions/php-7.2.1.tar.gztar xvf php-7.2.1.tar.gzcd php-7.2.1

設定變數並開始源碼編譯:

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

若無報錯執行下一步安裝,如果編譯過程中出現錯誤,根據報錯安裝依賴包,通常不會出現這種問題。

注意:–enable-gd-jis-conv 此參數會導致Zabbix中文字元亂碼,建議取消。

開始安裝:

make -j 4 && make install

完成安裝後配置php.ini檔案:

cp php.ini-development /usr/local/php/etc/php.inicp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.confcp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

修改 php.ini 相關參數:

vim /usr/local/php/etc/php.ini
expose_php = Offshort_open_tag = ONmax_execution_time = 300max_input_time = 300memory_limit = 128Mpost_max_size = 32Mdate.timezone = Asia/Shanghaimbstring.func_overload=2extension = "/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.soopcache.memory_consumption=128opcache.interned_strings_buffer=8opcache.max_accelerated_files=4000opcache.revalidate_freq=60opcache.fast_shutdown=1opcache.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#配置www.conflisten = /var/run/www/php-cgi.socklisten.owner = wwwlisten.group = wwwlisten.mode = 0660listen.allowed_clients = 127.0.0.1pm = dynamiclisten.backlog = -1pm.max_children = 180pm.start_servers = 50pm.min_spare_servers = 50pm.max_spare_servers = 180request_terminate_timeout = 120request_slowlog_timeout = 50slowlog = var/log/slow.log

配置www.conf

listen = /var/run/www/php-cgi.socklisten.owner = wwwlisten.group = wwwlisten.mode = 0660listen.allowed_clients = 127.0.0.1pm = dynamiclisten.backlog = -1pm.max_children = 180pm.start_servers = 50pm.min_spare_servers = 50pm.max_spare_servers = 180request_terminate_timeout = 120request_slowlog_timeout = 50slowlog = 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 ManagerAfter=syslog.target network.target[Service]Type=simplePIDFile=/usr/local/php/var/run/php-fpm.pidExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.confExecReload=/bin/kill -USR2 $MAINPID[Install]WantedBy=multi-user.target

啟動php-fpm服務並加入開機自啟動:

systemctl enable php-fpm.servicesystemctl restart php-fpm.service

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.