之前写过一篇win7下安装Yii2的文章 win7系统下安装yii2步奏 ,其实在mac和liunx下安装都大同小异的,很多人会问怎么又写了一遍呢,这不因为换mac了嘛,哈哈(其实是从新整理和总结一下)。
建议大家学习Yii2时用composer(若是不会的可以单独去学习), php5.4以上,低了自己升级吧
安装
1、composer安装完后执行下面语句,之后就耐心等待,会很长时间
composer create-project --prefer-dist yiisoft/yii2-app-advanced yii-application
注:yii-application 是你网站的目录你可以自定义,这个目录会自动创建的。
2、打开终端执行init命令,并选择dev环境
/path/to/php-bin/php /path/to/yii-application/init
3、创建一个数据库,并修改common/config/main-config.php 的 common[‘db’]配置
4、打开控制台,执行命令,创建数据库。
/path/to/php-bin/php /path/to/yii-application/yii migrate
5、配置nginx的web文件的访问路径
前台:/path/to/yii-application/frontend/web/ 后台:/path/to/yii-application/backend/web/
6、nginx配置文件
server { charset utf-8; client_max_body_size 128M; listen 80; ## listen for ipv4 #listen [::]:80 default_server ipv6only=on; ## listen for ipv6 server_name frontend.viphper.com; root /path/to/yii-application/frontend/web/; index index.php; access_log /path/to/yii-application/log/frontend-access.log; error_log /path/to/yii-application/log/frontend-error.log; location / { # Redirect everything that isn't a real file to index.php try_files $uri $uri/ /index.php$is_args$args; } # uncomment to avoid processing of calls to non-existing static files by Yii #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ { # try_files $uri =404; #} #error_page 404 /404.html; # deny accessing php files for the /assets directory location ~ ^/assets/.*\.php$ { deny all; } location ~ \.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; #fastcgi_pass unix:/var/run/php5-fpm.sock; try_files $uri =404; } location ~* /\. { deny all; } } server { charset utf-8; client_max_body_size 128M; listen 80; ## listen for ipv4 #listen [::]:80 default_server ipv6only=on; ## listen for ipv6 server_name backend.viphper.com; root /path/to/yii-application/backend/web/; index index.php; access_log /path/to/yii-application/log/backend-access.log; error_log /path/to/yii-application/log/backend-error.log; location / { # Redirect everything that isn't a real file to index.php try_files $uri $uri/ /index.php$is_args$args; } # uncomment to avoid processing of calls to non-existing static files by Yii #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ { # try_files $uri =404; #} #error_page 404 /404.html; # deny accessing php files for the /assets directory location ~ ^/assets/.*\.php$ { deny all; } location ~ \.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; #fastcgi_pass unix:/var/run/php5-fpm.sock; try_files $uri =404; } location ~* /\. { deny all; } }
7、配置相应的hosts,然后浏览器直接访问 http://frontend.viphper.com,直接可以访问。