nginx+php(5.4.14)安裝、配置詳解(單機版)

來源:互聯網
上載者:User
文章目錄
  • 1.1遇到的問題
  • 1.2編譯、安裝

環境:

系統: centos 6.2 linux2.6

php: 5.4.14 (當前最新版本)

nginx :1.3.16(當前最新版本)

1.php的安裝

安裝前.先安裝些軟體和庫檔案
yum install -y gcc gcc-c++  make zlib zlib-devel pcre pcre-devel  libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel
krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

部分不是必須的哦,必須的有:libpng,jpeg,freetype,gd

1.1遇到的問題

如果我們不用上面的命令一次安裝,則會遇到下面的問題:

error 1
checking for xml2-config path... 
configure: error: xml2-config not found. Please check your libxml2 installation.

(看提示就明白 是一個lib庫沒裝  先用 yum search 名字 看是否能搜到名字 ,找到名字後 把軟體包 開發封裝上)
解決辦法
yum install libxml2-devel.x86_64

error 2
checking for pkg-config... /usr/bin/pkg-config
configure: error: Cannot find OpenSSL's <evp.h>
這是ssl沒裝
解決辦法
 yum  install  openssl.x86_64 openssl-devel.x86_64 -y

error 3
checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution
這是bzip2軟體包沒有安裝
解決辦法
yum install bzip2-devel.x86_64 -y

error 4
configure: error: Please reinstall the libcurl distribution -
    easy.h should be in <curl-dir>/include/curl/
curl和curl庫檔案沒有安裝

解決辦法
yum install libcurl.x86_64 libcurl-devel.x86_64 -y

error 5
checking whether to enable JIS-mapped Japanese font support in GD... no
checking for fabsf... yes
checking for floorf... yes
configure: error: jpeglib.h not found

GD庫沒有安裝
解決辦法
yum install libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 -y

error 6
checking for stdarg.h... (cached) yes
checking for mcrypt support... yes
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
libmcrypt庫沒有安裝 ,要是不能用yun安裝的話  就要去下載個gz包 自己編譯安裝
給個地址:http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/
(編譯安裝  ./configure --piefix=/usr/local/libmcrypt   make && make install)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
要是錯誤裡面含有mysql的  那是mysql-devel 沒有安裝

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1.2編譯、安裝

這裡安最少的編譯,目的是能跑得出來,如果圖精簡,則執行下面命令就OK

$ yum install -y gcc-c++ gcc make libxml2-devel libjpeg-devel libpng-devel

$ /configure  --enable-fastcgi --enable-fpm
註:Nginx+PHP整合,在安裝時必須啟用--enable-fastcgi和 --enable-fpm,這兩個選項是做什麼的上面已經描述。執行完後系統會提示--enable-fastcgi是一個未知選項,我們不必理會

$ make && make install

出現
Generating files configure: creating ./config.status creating main/internal_functions.c creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License:                                                           |

| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |

| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |

+--------------------------------------------------------------------+
Thank you for using PHP.
onfig.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating main/php_config.h
config.status: executing default commands

表示PHP安裝工作成功

2.安裝nginx

可以到官網上傳最近的版本,http://nginx.org/

解壓後,直接 讓其預設安裝

$ ./configure  && make && make install

3.修改設定檔

make完成之後  到php的解壓目錄 找出php.ini-production 複製到 /usr/local/etc/ 下 檔案名稱改成php.ini

$ cp php.ini-production /usr/local/etc/php.ini 

將/usr/local/etc/php-fpm.conf.default 複製一份,並改名了php-fpm.conf.default

$ cp /usr/local/etc/php-fpm.conf.default  /usr/local/etc/php-fpm.conf


3.1.修改 /usr/local/nginx/conf/nginx.conf

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000; //監聽本地的php-fpm的9000連接埠
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html/$fastcgi_script_name;  #下畫線的是php檔案所放的路徑
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one

3.2.修改 /usr/local/etc/php-fpm.conf 檔案

*********************************************************

  1. [global]
  2. ; Pid file
  3. ; Note: the default prefix is /usr/local/webserver/php/var
  4. ; Default Value: none
  5. pid = run/php-fpm.pid

  6. ; Error log file
  7. ; If it's set to "syslog", log is sent to syslogd instead of being written
  8. ; in a local file.

***********************************************************************************************************

;                            specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 127.0.0.1:9000 #這裡不用改,但是強調一下,nginx做代理的時候需要使用

; Set listen(2) backlog.
; Default Value: 128 (-1 on FreeBSD and OpenBSD)

*************************************************************************************************************************


上面紅色部分是修改的部分,其它保持不變

4.運行測試 

運行php-fpm 和nginx

$ /usr/local/sbin/php-fpm

$ /usr/local/nginx/sbin/nginx


在niginx 的安裝目錄下找到html目錄(預設網站目錄),建立一個index.php

內容為:

<?php
echo phpinfo();
?>

最後在另外一台機器上訪問這個網頁,即可看到php的頁面資訊了

此時大功告成

配置參考:

安裝Nginx 1.2.0+PHP 5.4.3(FastCGI)+MySQL 5.5.24  http://blog.chinaunix.net/uid-20556054-id-3226209.html

編譯安裝PHP 時遇到問題解決方案.  http://www.cnblogs.com/z-ping/archive/2012/06/18/2553929.html

CentOS+Nginx+PHP+MySQL詳細配置  http://www.jb51.net/article/26597.htm

 Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建勝過Apache十倍的Web伺服器  http://blog.s135.com/nginx_php_v6/

相關文章

聯繫我們

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