分類
网站

nginx和yii2

记录下Ubuntu12.04安装nginx遇到的问题。

nginx安装好后打开php遇到File not found

修改/etc/nginx/conf.d/default.conf文件。首先在server下添加root,然后修改fastcgi_param为SCRIPT_FILENAME $document_root$fastcgi_script_name;

server {
    listen       80;
    server_name  localhost;
    root         /usr/share/nginx/html;

    #charset koi8-r;
    ...
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
    ...

php升级到5.5

新版Yii要求php5.4或更高,但Ubuntu12.04库中的默认版本是5.3.所以我就直接添加PPA升级了。

sudo apt-get update && sudo apt-get install python-software-properties  
sudo add-apt-repository ppa:ondrej/php5
sudo apt-get update && sudo apt-get dist-upgrade

升级后打开php页面出现502 Bad Gateway,把/etc/php5/fpm/pool.d/www.conf中listen = /var/run/php5-fpm.sock替换成listen = 127.0.0.1:9000就好了。可能是升级后/var/run/php5-fpm.sock被删除了。更多升级到5.5导致502 Bad Gateway,请参考Fix “502 Bad Gateway” error on NGINX server after upgrading PHP

安装phpmyadmin

sudo apt-get install phpmyadmin  
sudo ln -s /usr/share/phpmyadmin/ /usr/share/nginx/html/phpmyadmin

如果nginx配置文件没有加index.php会出现403错误。应该把/etc/nginx/conf.d/default.conf中字段配置为这样:

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm index.php;
    }

安装Composer

curl -sS https://getcomposer.org/installer | php  
sudo mv composer.phar /usr/local/bin/composer

通过Composer安装yii

首先切换到网站目录下,如/opt/lampp/htdocs。安装basic版:

sudo php composer.phar create-project yiisoft/yii2-app-basic basic 2.0.1

安装advanced版

sudo php composer.phar create-project yiisoft/yii2-app-advanced advanced 2.0.1

相关文档

安装yii2的时候照着里面的readme做就好了。advanced版中有用户数据库。https://github.com/yiisoft/yii2/tree/master/docs/guideThe Definitive Guide to Yii 2.0

卸載nginx

sudo apt-get remove nginx nginx-common
sudo apt-get purge nginx
sudo apt-get autoremove

本文更新於 2015/04/04。

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *