LNMP 구성 + yii 환경

WBOY
풀어 주다: 2016-08-08 09:20:40
원래의
1045명이 탐색했습니다.

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 설치 mysql-server php5-mysql ## 설치 과정에서 mysql의 루트 사용자 비밀번호를 설정하라는 메시지가 표시됩니다

# mysql_install_db

# mysql_secure_installation

그런 다음 루트 사용자의 원격 연결 허용 여부를 포함하여 필요에 따라 설치하도록 선택합니다.

(2)Nginx

# apt-get install nginx

(3)PHP

# apt-get install php5-fpm php5-cli

(4) Yii

Yii 공식 홈페이지에 가서 Yii 프레임워크 소스 코드를 다운로드하고 /var/www/ 디렉토리에 압축을 풀고 파일명을 yii로 변경합니다.

yii1.1.16 버전을 사용하고 있습니다.

4. 구성

구성의 주요 목적은 Nginx용 Yii 프레임워크 URL에서 index.php를 숨기는 것입니다. 및 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;
    }
}
로그인 후 복사
구성 파일주요 참조가져오기 시작됨 - Apache 및 Nginx 구성 - Nginx

Nginx는 정상적으로 시작할 수 있습니다

(2)PHP

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

cgi.fix_pathinfo 옵션을 찾아 주석 처리를 해제하고 변경하세요. cgi.fix_pathinfo 값을 0으로 변경

/var/www/ 디렉토리에 새 testphp.php를 생성합니다.

내용은

<span style="white-space:pre">		<?php
&#160;		</span>    <span style="white-space:pre">phpinfo();
		?></span>
로그인 후 복사
php가 잘 작동합니다. 4. 테스트

(1) 홈페이지 작동 여부

홈페이지에서는 홈페이지 표시에는 문제가 없으나, 모든 메뉴를 클릭하면 404에러가 발생합니다

다음은 Yii 프로젝트 URL 구성입니다(protected/config/main.php)

다음은 메뉴바

(2) Yii URL에서 index.php 숨기기

이전 nginx 구성은 yii 공식 문서에 따라 구성했지만 소용이 없었습니다. Google은 "location /"의 구성을 수정하는 것 외에 많은 정보를 검색했습니다.

1) 해결 방법 1

위치 /{

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

}

Tip$yii_bootstrap 변수의 내용은 입니다. php

그래도 404 오류가 발생합니다

2) 해결 방법 2

역시 랜덤하고 알이 없습니다

5. 결론: 아파치로 바꿔야 한다

이것은 좋은 일치입니다. 이전에 제공된 공식 링크를 사용하면 문제를 해결할 수 있습니다.

로그인 후 복사
저작권: 이 글은 해당 블로거의 원본 글이므로 블로거의 허락 없이 복제할 수 없습니다.

위 내용은 관련 측면을 포함하여 LNMP 구성 + yii 환경을 소개한 내용이 PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!