首頁 > 後端開發 > PHP7 > 主體

怎麼安裝php7和php5共存

藏色散人
發布: 2023-02-18 08:06:02
轉載
1639 人瀏覽過

開始

之前在伺服器搭建了lamp環境,想換用效能更強的nginx作為伺服器軟體,又想將php5升級為php7.
安裝nginx無需贅述:sudo apt-get install nginx,啟動ng前修改apache的連接埠。

安裝php7

原始碼在http://php.net/downloads.php 下載,並解壓縮。

# cd php7***
# ./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-mcrypt=/usr/include --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gd --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache

# make
# make install
登入後複製

為不與5衝突,資料夾都用php7,安裝過程中報錯的安裝回應的依賴。

對接nginx

nginx本身不能處理php腳本,需要發給php解釋器處理。 nginx通常是把請求發fastcgi管理進程處理,fascgi管理程序選擇cgi子程序處理結果並回傳被nginx。

# cp php.ini-production /usr/local/php7/etc/php.ini
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php7-fpm
# chmod +x /etc/init.d/php7-fpm
# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
登入後複製

啟動php-fpm

# service php7-fpm start
登入後複製

中途如遇到日誌檔案路徑不存在就手動建立並給予寫入的權限。

# service php7-fpm start
Starting php-fpm [07-Apr-2016 11:16:11] ERROR: [pool www] cannot get gid for group 'nobody'
[07-Apr-2016 11:16:11] ERROR: FPM initialization failed
 failed
登入後複製

遇到這個錯誤時,要新增個nobody群組groupadd nobody再重新啟動。

nginx的配置

這是存取php檔案是變成下載文件,因為ng並未配置回應處理。

location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
登入後複製

推薦學習:《PHP7教學

#

以上是怎麼安裝php7和php5共存的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:segmentfault.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!