设为首页 收藏本站
查看: 2028|回复: 0

LNMP配置+yii环境

[复制链接]

尚未签到

发表于 2015-11-16 12:03:30 | 显示全部楼层 |阅读模式
1、配置环境
  (1)Ubuntu14.04 x86_64 [Kernel Version: 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
     # mysql_secure_installation
     之后按照自己的需求选择安装,包括是否允许root用户远程连接。

    (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、配置

配置主要的目的是隐藏Yii框架url中的index.php;对于Nginx与PHP的配置,网上资料繁多。

(1)Nginx

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

server {
listen 80 default_server;
#listen [::]:80 default_server ipv6only=on;  ## 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
Started - Apache and Nginx configurations
-
Nginx
  
  Nginx能正常启动
  

   (2)PHP

# vim /etc/php5/fpm/php.ini  找到cgi.fix_pathinfo选项,取消注释,并将cgi.fix_pathinfo的值改为0。
  重启php5-fpm服务:service php5-fpm restart
  
  在/var/www/目录下新建testphp.php,
  内容为
  

<?php
phpinfo();
?>
  php工作正常。
  


  
  

4、测试

   (1)网站是否能工作

DSC0000.jpg
网站首页显示没有问题,但是所有的菜单点击后都有404错误
DSC0001.jpg
下面是Yii工程url的配置(protected/config/main.php)
DSC0002.jpg
下面是菜单栏的路径配置
DSC0003.jpg
(2)隐藏Yii url中的index.php

之前nginx的配置是按照yii官方文档配置的,然而并没有什么卵用。Google搜索了许多资料,不外乎修改&quot;location /&quot;中的配置。
1)解决方案1
  location /{
try_files $uri $uri/ /index.php?$request_uri;
  }
DSC0004.jpg
提示$yii_bootstrap变量内容就是inde.php
但是还是404错误
DSC0005.jpg

2)解决方案2
DSC0006.jpg
我的nginx版本是1.4.6的,所以应该参照下面一个的配置修改。修改后重启nginx服务
DSC0007.jpg
DSC0008.jpg
也是然并卵

经过艰难排错,结果发现自己脑残。
我未完全按照官方建议配置,而是在&quot;location ~ \.php&quot;后面多了个$
DSC0009.jpg
改了这个之后我以为行了,但是我又错了
DSC00010.jpg
DSC00011.jpg
不过总归错误变了,继续查资料解决。
终于找到错误了:
将之前修改过的/etc/php5/fpm/php.ini文件中的cgi.fix_pathinfo参数改回去,改为1
DSC00012.jpg
重启php5-fpm:service php5-fpm restart
DSC00013.jpg
搞定











课外话:修改fastcgi_pass参数样例
(1)修改/etc/php5/fpm/pool.d/www.conf文件
注释listen = /var/run/php5-fpm.sock,
新添listen = 127.0.0.1:9000
DSC00014.jpg
重启php5-fpm服务:service php5-fpm restart



(2)修改/etc/nginx/sites-available/default中的&quot;location ~ \.php&quot;块,
注释“fastcgi_pass unix:/var/run/php5-fpm.sock;”,
取消“fastcgi_pass 127.0.0.1:9000;”的注释
DSC00015.jpg

  
  重启nginx服务


  

版权声明:本文为博主原创文章,未经博主允许不得转载。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-139893-1-1.html 上篇帖子: CentOS 5.6(X64)下编译安装LNMP平台(Nginx1.0.4+PHP5.3.6+Mysql5.5.12) 下篇帖子: LNMP搭建笔记③之编译安装nginx
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表