Linux安裝配置PHP+Nginx

來源:互聯網
上載者:User

標籤:linux   軟體下載   

一、PHP的安裝

1.安裝php7.0

    軟體下載  # wget  http://cn2.php.net/distributions/php-7.0.4.tar.gz

檢查並安裝依賴包    
[[email protected] Desktop]# rpm -qa libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 curl-devel libxslt-devel openssl-devel    
[[email protected] Desktop]# yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxslt-devel openssl-devel    
[[email protected] Desktop]# tar xf php-7.0.4.tar.gz    
[[email protected] Desktop]# cd php-7.0.4    
[[email protected] php-7.0.4]# ./configure --prefix=/usr/local/php7 --exec-prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc  --with-curl  --with-freetype-dir  --with-gd  --with-gettext  --with-iconv-dir  --with-kerberos  --with-libdir=lib64  --with-libxml-dir  --with-mysqli  --with-openssl  --with-pcre-regex  --with-pdo-mysql  --with-pdo-sqlite  --with-pear  --with-png-dir  --with-xmlrpc  --with-xsl  --with-zlib --with-zlib-dir --with-mhash --with-mcrypt --with-openssl-dir --with-jpeg-dir --enable-gd-jis-conv  --enable-fpm  --enable-bcmath  --enable-libxml  --enable-inline-optimization  --enable-gd-native-ttf  --enable-mbregex  --enable-mbstring  --enable-opcache  --enable-pcntl  --enable-shmop  --enable-soap  --enable-sockets  --enable-sysvsem  --enable-xml  --enable-zip

[[email protected] php-7.0.4]# make    
[[email protected] php-7.0.4]# make  test    
[[email protected] php-7.0.4]# make install

 

2.設定設定檔

[[email protected] php-7.0.4]# cp php.ini-production /usr/local/php7/etc/php.ini

     php.ini-development 適合開發測試,如本地測試環境,php.ini-production擁有較高的安全性設定,適合伺服器上線運營當產品。一般修改php.ini-production為php.ini,安全性更高,確保測試環境(本地)與正式環境(線上)一致

[[email protected] php-7.0.4]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf

[[email protected] php-7.0.4]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf    
[[email protected] php-7.0.4]# cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

 

3.加入啟動服務

[[email protected] php-7.0.4]# chmod +x /etc/init.d/php-fpm    
[[email protected] php-7.0.4]# chkconfig --add php-fpm

    注意的是php7中www.conf這個設定檔配置phpfpm的連接埠號碼等資訊,如果你修改預設的9000連接埠號碼需在這裡改,再改nginx的配置

 

4.啟動php服務

[[email protected] php-7.0.4]# /etc/init.d/php-fpm start

[[email protected] php-7.0.4]# ps -ef | grep php-fpm    

 

二、Nginx的安裝

1.軟體下載:

    wget http://nginx.org/download/nginx-1.6.2.tar.gz直接在Linux上用命令下載

2.安裝依賴包pcre和依賴的軟體

安裝nginx之前,確保已安裝了    
# rpm -qa gcc openssl-devel pcre zlib-devel軟體庫    
   安裝pcre庫是為了使Nginx支援HTTP Rewriter模組。若pcre預設沒有這個安裝包,安裝則需要下載手動安裝。    
   ./configure    
   make    
   make install

3. 安裝前進行安裝包最佳化

  (編譯安裝過程最佳化)減小nginx編譯後的檔案的大小在編譯nginx時,預設以debug模式下會插入很多跟蹤和ASSERT之類的資訊,編譯完成後,

[[email protected] nginx-1.6.2]# vim auto/cc/gcc

# debug    
CFLAGS="$CFLAGS -g"

   注釋或刪除這兩行,即可取消debug模式.

[[email protected] nginx-1.6.2]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-openssl=/usr/local/openssl   
[[email protected] nginx-1.6.2]# make && make install

[[email protected] nginx-1.6.2]# ps -ef | grep nginx    
[[email protected] nginx-1.6.2]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf   
[[email protected] nginx-1.6.2]# curl -i 127.0.0.1    
......    
<body>    
<h1>Welcome to nginx!</h1>    

If you see this page, the nginx web server is successfully installed and    
......

測試i頁顯示說明nginx安裝沒有問題

 

三、整合Nginx與PHP

Nginx自己並不處理動態網頁的請求,而且Nginx將得到的動態請求轉交給PHP,Nginx的設定檔

# vim /usr/local/nginx/conf/nginx.conf       //標的部分是我們後面要修改的

    650) this.width=650;" style="background-image:none;padding-left:0px;padding-right:0px;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M02/85/73/wKioL1ej64XgM9IJAAEU7MdqjRU672.png" width="729" height="362" />

    看,Nginx已經知道怎麼把得到的請求傳達給PHP,Nginx在得到*.php請求時,會把請求通過9000連接埠傳給PHP。下面我們把這些注釋給去掉即可,如

     650) this.width=650;" style="background-image:none;padding-left:0px;padding-right:0px;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M00/85/73/wKiom1ej642CB7PzAADA74TjXSQ134.png" width="722" height="291" />

      如所示,我們在前面已經看到過Nginx是通過原生9000連接埠將PHP請求轉寄給PHP的,而我們可以看到PHP自己是從原生9000連接埠偵聽資料 ,Nginx與PHP通過原生9000連接埠完成了資料請求。

 

四、測試

我們在nginx的設定檔裡面已經定義了PHP網站的存放路徑,路徑是/usr/local/nginx/html

下面我們在這個目錄下建立一個PHP頁面測試網頁,檔案名稱為test.php,內容如下

<?php 

     phpinfo(); 

?> 

關閉php

killall php-fpm

php重啟

/usr/local/php7/sbin/php-fpm &

關閉nginx

/usr/local/nginx/sbin/nginx -s stop       //關閉伺服器

重啟nginx

/usr/local/nginx/sbin/nginx       開啟伺服器

重啟PHP與nginx後 我們在瀏覽器中輸入http://localhost/test.php,出現如下介面算成功

650) this.width=650;" style="background-image:none;padding-left:0px;padding-right:0px;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M01/85/73/wKiom1ej64_jgnwGAAHv65N-X_U813.png" width="716" height="393" />

 

 

安裝過程中遇到的問題:

報錯資訊1:

     650) this.width=650;" style="background-image:none;padding-left:0px;padding-right:0px;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M01/85/73/wKioL1ej65CD8IdKAADBm01pq0U981.png" width="630" height="187" />

解決方案:

      tar -zxvf libmcrypt-2.5.8.tar.gz    
      cd /usr/local/src/libmcrypt-2.5.8    
     ./configure --prefix=/usr/local    
     make    
     make install

     error:  checking for C++ compiler default output file name... configure: error: C++ compiler cannot create executablesSee `config.log‘ for more details.

   # yum -y install gcc-c++

 

報錯資訊2:

configure: error: Don‘t know how to define struct flock on this system, set --enable-opcache=no

解決辦法:

# vim /etc/ld.so.conf    
     /usr/local/lib       檢查是否有此行,若沒有則添加    
#ldconfig    
或者    
./configure後添加上 --with-libdir=lib64 根據官方文檔添加這個參數

 

報錯資訊3:

collect2: ld returned 1 exit status      
make: *** [sapi/cli/php] Error 1

      在安裝 PHP 到系統中時要是發生「undefined reference to libiconv_open‘」之類的錯誤資訊,那表示在「./configure 」沒抓好一些環境變數值。錯誤發生點在建立「-o sapi/cli/php」是出錯,沒給到要 link 的 iconv 函式庫參數。

解決方案:

      編輯Makefile 檔案中找到 EXTRA_LIBS = ..... -lcrypt 在最後加上 -liconv,例如: EXTRA_LIBS = ..... -lcrypt -liconv 然後重新再次 make 即可。    
或者用另一種辦法    
make ZEND_EXTRA_LIBS=‘-liconv‘    
ln -s /usr/local/lib/650) this.width=650;" style="background-image:none;padding-left:0px;padding-right:0px;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="%W@GJ$ACOF(TYDYECOKVDYB" border="0" alt="%W@GJ$ACOF(TYDYECOKVDYB" src="http://s3.51cto.com/wyfs02/M02/85/73/wKioL1ej65HjR_3yAAAFa0jX9cY905.png" width="24" height="19" />libiconv.so.2 /usr/lib64/


本文出自 “願與您分享” 部落格,請務必保留此出處http://pengjc.blog.51cto.com/9255463/1834608

Linux安裝配置PHP+Nginx

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.