ホームページ  >  記事  >  バックエンド開発  >  LNMP 構成 + yii 環境

LNMP 構成 + yii 環境

WBOY
WBOYオリジナル
2016-08-08 09:20:401047ブラウズ

1. 構成環境

(1)Ubuntu14.04 x86_64 [カーネルバージョン: 3.16.0-30-generic]

(2)Nginx1.4.6

(3) MySQL5.5

(4)PHP5.5.9

2.インストール方法

当面はソースコードのコンパイルとインストールを使用せず、apt-get installメソッドを使用してインストールします。将来のカスタム ニーズを満たすには、deb インストール パッケージを作成するのが最善です。

3. 具体的なインストール手順

(1)MySQL

# apt-get install mysql-server php5-mysql ## インストールプロセス中に、mysql の root ユーザーパスワードを設定するよう求められます

# mysql_install_db

# _安全な_インストール

そして、あなた自身に従ってください。 root ユーザーにリモート接続を許可するかどうかを含めて、インストールを選択する必要があります。

(2)Nginx

#apt-get install nginx

#ap t-get install php5-fpm php5-cli

(4) Yいいですね

Yii 公式 Web サイトにアクセスして Yii フレームワークのソース コードをダウンロードし、/var/www/ ディレクトリで解凍し、ファイル名を yii に変更します。

バージョン yii1.1.16 を使用しています。

4. 設定

設定の主な目的は、Nginx と PHP の設定に関する Yii フレームワーク URL の Index.php を非表示にすることです。

(1)Nginx

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

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;
    }
}
設定ファイル

主なリファレンスGetting 開始しました - Apache と Nginx の構成 - Nginx Nginx は正常に起動できます

(2)PHP

# vim /etc/php5/fpm/php.ini

cgi.fix_pathinfo オプション、/var/www/directoryで新しいtestphp.phpを作成するためにcgi.fix_pathinfoの値を解除して変更します。

phpは正常に動作しています。 4. テスト (1) ウェブサイトが動作するかどうか

ウェブサイトは、ホームページに問題はありませんが、すべてをクリックすると 404 エラーが発生しますメニュー

以下は Yii プロジェクトの URL (protected/config/main.php) の設定です

以下はメニューバーへのパス Configuration

(2) Yii urlのindex.phpを隠す

以前のnginx設定はyii公式ドキュメントに従って設定されましたが、それはありませんでした使用。 Google は多くの情報を検索しましたが、「location /」の設定を変更するだけでした。

1) 解決策 1

location /{

try_files $uri $uri/ /index.php?$request_uri;

}

ヒント$yii_bootstrap変数の内容はinde.php

しかし、まだ404エラーがあります

2) 解決策 2

5. 結論: Apache に変更する必要があります

これは良いです 以前に提供された公式リンクでは、あなたは問題を解決することができます

<span style="white-space:pre">		<?php
&#160;		</span>    <span style="white-space:pre">phpinfo();
		?></span>
著作権表示: この記事はブロガーによるオリジナルの記事であり、ブロガーの許可なく複製することはできません。

以上、LNMP 構成 + yii 環境を内容も含めて紹介しましたが、PHP チュートリアルに興味のある友人の参考になれば幸いです。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。