首頁  >  文章  >  後端開發  >  LNMP配置+yii環境

LNMP配置+yii環境

WBOY
WBOY原創
2016-08-08 09:20:401047瀏覽

1、配置環境

(1)Ubuntu14.04 x86_64 [Kernel Version: 3.16.0-30-generic]

(3) MySQL5.5

(4)PHP5.5.9

2、安裝方式ll

暫不採用源碼編譯安裝,使用install以installlled安裝。以後為了滿足自訂需求,最好做成deb安裝套件。

3、具體安裝過程(1)MySQL

apt-get install my-server

-get install my-server ##安裝過程中會提示設定mysql的root使用者密碼

#  

之後依照自己的需求選擇安裝,包括是否允許root使用者遠端連線。

   (2)Nginx# -get install naptx

(3) # apt-get install php5-fpm php5-cli (4)Yii

去Yii官網下載Yii框架源碼,解壓縮與/var/www/目錄下,並將檔名修改成yii。

我用的是yii1.1.16版本。 4、配置

配置主要的目的是隱藏Yii框架url中的index.php;對於Nginx與PHP的配置,網路資料繁多。

(1)Nginx

# vim /etc/nginx/sites-available/default

Started - Apache and 

Nginx

 configurations - 

Nginx

   Nginx能正常啟動

   (2)PHPphp

   (2)PHPphp/ 找到cgi.fix_pathinfo選項,取消註釋,將cgi.fix_pathinfo的值改為0在/var/www/目錄下新建testphp.php,

server {
    listen 80 default_server;
    #listen [::]:80 default_server ipv6  ## listen for ipv6

    root /var/www/;
    index index.html index.htm index.php;

    # Make site accessible from http://localhost/
    server_name localhost;

    set $yii_bootstrap "index.php";    

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        #try_files $uri $uri/ =404;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
        try_files $uri $uri/ /$yii_bootstrap?$args;
    }

    #avoid processing of calls to unexisting static files by yii
    location ~ ^/(protected|framework|themes/\w+/views) {
        deny  all;
    }

    location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
        try_files $uri =404;
    }


    # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
    #location /RequestDenied {
    #	proxy_pass http://127.0.0.1:8080;    
    #}

    error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /var/www/html;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

        #let yii catch the calls to unexising PHP files
        set $fsn /$yii_bootstrap;
        if (-f $document_root$fastcgi_script_name){
            set $fsn $fastcgi_script_name;
        }

        # 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;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fsn;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED  $document_root$fsn;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #	deny all;
    #}
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }
}

php運作正常。 4、測試

   (1)網站是否能運作

下面是Yii工程url的設定(protected/config/main.php)

路徑配置

(2)隱藏Yii url中的index.php

 之前nginx的配置是按照yii官方文檔配置的,然而並沒有什麼用卵。 Google搜尋了許多資料,不外乎修改"location /"中的配置。

1)解1

  location/{?

  }

提示

$yii_bootstrap變數內容就是inde.php

2)解決方案2

也是然並卵配,之前的提供的官方連結就能解決問題

<span style="white-space:pre">		<?php
&#160;		</span>    <span style="white-space:pre">phpinfo();
		?></span>
版權聲明:本文為部落客原創文章,未經博主不得轉載。

以上就介紹了LNMP配置+yii環境,包括了方面的內容,希望對PHP教程有興趣的朋友有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn