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의 루트 사용자 비밀번호를 설정하라는 메시지가 표시됩니다
(2)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 구성에는 온라인에 많은 정보가 있습니다.
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; } }
Nginx는 정상적으로 시작할 수 있습니다
# vim /etc/php5/fpm/php.ini
cgi.fix_pathinfo 옵션을 찾아 주석 처리를 해제하고 변경하세요.<span style="white-space:pre"> <?php   </span> <span style="white-space:pre">phpinfo(); ?></span>
(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 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.