在Debian系統下配置LNMP的教程_php執行個體

來源:互聯網
上載者:User

LNMP環境的配置是需要讓我們的主機支援Nginx、MySQL、PHP、phpMyAdmin,這樣配置好之後就可以直接使用此環境,並在上面運行網站了,下面我來配置方法。

我們先來看官方說明

LNMP一鍵安裝包是一個用Linux Shell編寫的可以為CentOS/RadHat、Debian/Ubuntu VPS(VDS)或外掛式主控件安裝LNMP(Nginx、MySQL、PHP、phpMyAdmin)生產環境的Shell程式


1,安裝MySQL
執行命令:

apt-get install -y mysql-server mysql-client

即可安裝MySQL,安裝過程中會詢問 root密碼 ,鍵入你需要的密碼之後斷行符號即可。

安裝完成後,執行如下命令進行一步安全設定:

mysql_secure_installation

按照提示進行,過程中會詢問是否更改 root密碼,是否移除匿名使用者,是否禁止root遠程登入等。
2,安裝PHP
執行命令:

apt-get install php5-fpm php5-gd php5-mysql php5-memcache php5-curl

上面的命令安裝了php5-memcache的擴充,於是繼續安裝 Memcached 。

apt-get install memcached

安裝完畢之後,使用 php5-fpm -v 查看一下PHP的版本:

 root@ztbox:~# php5-fpm -v

PHP 5.4.16-1~dotdeb.1 (fpm-fcgi) (built: Jun  8 2013 22:20:42)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

3,安裝Nginx

這裡我直接安裝了Nginx的全部擴充功能(nginx-full),以應對以後可能出現的功能性增強。

apt-get install -y nginx-full

然後啟動Nginx:

service nginx start

訪問結果如上圖,接下來配置Nginx。

vim /etc/nginx/sites-available/default

……
    location ~ .php$ {
        fastcgi_split_path_info ^(.+.php)(/.+)$;
    #    # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    #
    #    # With php5-cgi alone:
    #   fastcgi_pass 127.0.0.1:9000;
    #    # With php5-fpm:
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
……

修改儲存之後重啟Nginx:

service nginx restart

接下來我們建立一個phpinfo,查看php的詳細資料:

vim /usr/share/nginx/html/phpinfo.php<?php phpinfo(); ?>

儲存之後訪問 http://ip/phpinfo.php , 如果出現 phpinfo 頁面,則大功告成。

如何建立網站
和軍哥的一鍵包不同,此方法所安裝的 LNMP 需要手動添加網站設定檔。

cd /etc/nginx/conf.d

 進入設定檔目錄,建立一個網站設定檔,比如

vi dearroy.com.confserver {  listen 80; #ipv6  #listen [::]:80 default_server;  root /usr/share/nginx/html/dearroy.com; #預設首頁檔案名稱  index index.php index.html index.htm; #綁定網域名稱  server_name localhost; #偽靜態規則 include wordpress.conf;  location / {    try_files $uri $uri/ /index.html;      } #定義錯誤頁面  #error_page 404 /404.html;   location ~ .php$ {    fastcgi_split_path_info ^(.+.php)(/.+)$;    fastcgi_pass 127.0.0.1:9000;     fastcgi_index index.php;     include fastcgi_params;   }   #PHP}

儲存之後重啟Nginx,添加及綁定網站即完成。

最後,附兩個最常用的程式Nginx偽靜態:

WordPress:
 

複製代碼 代碼如下:
location / {
if (-f $request_filename/index.html){
                rewrite (.*) $1/index.html break;
        }
if (-f $request_filename/index.php){
                rewrite (.*) $1/index.php;
        }
if (!-f $request_filename){
                rewrite (.*) /index.php;
        }
}

Discuz X:

複製代碼 代碼如下:
rewrite ^([^.]*)/topic-(.+).html$ $1/portal.php?mod=topic&topic=$2 last;
rewrite ^([^.]*)/article-([0-9]+)-([0-9]+).html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
rewrite ^([^.]*)/forum-(w+)-([0-9]+).html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
rewrite ^([^.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;
rewrite ^([^.]*)/group-([0-9]+)-([0-9]+).html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
rewrite ^([^.]*)/space-(username|uid)-(.+).html$ $1/home.php?mod=space&$2=$3 last;
rewrite ^([^.]*)/([a-z]+)-(.+).html$ $1/$2.php?rewrite=$3 last;
if (!-e $request_filename) {
        return 404;

相關文章

聯繫我們

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