1. 安装 PHP The Yii2.0 (PHP >= 5.4.0),
sudo add-apt-repository ppa:ondrej/php5
sudo apt-get update
2. 安装PHP extensions
sudo apt-get install php5-cgi
sudo apt-get install php5-fpm
sudo apt-get install php5-curl
sudo apt-get install php5-mcrypt
sudo apt-get install php5-gd
sudo apt-get install php5-dev
或者
sudo apt-get install php5-cgi php5-fpm php5-curl php5-mcrypt php5-gd php5-dev php5-mysql
如果源不存在了
sudo add-apt-repository ppa:ondrej/php
sudo apt-get install php7.1-fpm php7.1-curl php7.1-mysql php7.1-common php7.1-cgi php7.1-mcrypt php7.1-gd php7.1-dev
3. 配置环境
打开: vi /etc/nginx/sites-available/default(vi安装sudo apt-get install vim)
修改以下内容:两个位置,为以下内容
index index.html index.htm index.php;
......
location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php5-fpm.sock;#fastcgi_pass unix:/var/run/php7.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
4.重启
/etc/init.d/php5-fpm {start|stop|quit|restart|reload|logrotate} 或者php7.1-fpm
或者
service php5-fpm {start|stop|quit|restart|reload|logrotate} 或者php7.1-fpm
5. 安装Redis
sudo apt-get install redis-server
安装 PHP Redis extension
sudo apt-get install php5-redis
6. 安装 nginx
sudo apt-get install nginx
7. 配置 nginx
在/etc/nginx/conf.d下建一个conf文件,例如test.conf
假设自己的项目是/var/www/下的test,确认自己的项目$fcgi_server的与/etc/nginx/sites-available/default匹配
server {
set $project_root /var/www/test/src;
set $docs_root /var/www/test/docs;
set $fcgi_server unix:/var/run/php5-fpm.sock; ## listen for socket
#set $fcgi_server 127.0.0.1:9000; ## listen for portcharset utf-8;
listen 80; ## listen for ipv4
#listen [::]:80 default_server ipv6only=on;
## listen for ipv6server_name test.com *.test.com;
root $project_root;access_log /var/log/nginx/test.com-access.log;
error_log /var/log/nginx/test.com-error.log;location ^~ /docs/frontend {
alias $docs_root/frontend/site/;
index index.html;
}location ^~ /docs/backend {
alias $docs_root/backend/api/;
index index.html;
}location / {
root $project_root/frontend/build;
rewrite ^/?(.*) /index.html break;
}location ~ /(scripts|styles|images|i18n)/{
root $project_root/frontend/build;
}location ^~ /partials {
root $project_root/frontend/build;
try_files $uri $uri/ /partials/empty.html;
}location ^~ /bower/ {
alias $project_root/frontend/bower/;
}location /api {
alias $project_root/backend/web/;rewrite ^(/api)/$ $1 permanent;
try_files $uri /backend/web/index.php?$args;
}location ^~ /api/(.+.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar))$ {
access_log off;
expires 360d;rewrite ^/api/(.+)$ /backend/web/$1 break;
rewrite ^/api/(.+)/(.+)$ /backend/web/$1/$2 break;
try_files $uri =404;
}location ~ .php$ {
fastcgi_pass $fcgi_server;
fastcgi_keep_conn on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}location ~ .(ht|svn|git) {
deny all;
}
}
8. 配置hosts
vi /etc/hosts
添加一条
127.0.0.1 test.com
9. 安装 composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
处理步骤(http://pkg.phpcomposer.com/)
安装composer
composer global require "fxp/composer-asset-plugin:1.0.0-beta4"
用composer安装php后台需要的扩展
cd /<DIR>/src/backend
composer install
10. SASS
安装 ruby (version > 1.9.1)
sudo apt-get install ruby
执行 mirror for ruby(Ensure only ruby.taobao.org exists)
gem sources --remove http://rubygems.org/
gem sources -a https://ruby.taobao.org/
gem sources -l
*** CURRENT SOURCES ***
https://ruby.taobao.org
安装 sass
gem install sass
11. 安装指定版本nodejs
curl -o ~/node.tar.gz https://nodejs.org/dist/v0.12.7/node-v0.12.7.tar.gz
cd
tar -zxvf node.tar.gz
cd node-v0.12.7
./configure
make
sudo make install
12. 指向源
npm config set registry=http://registry.npm.taobao.org
安装 gulp
sudo npm install -g gulp
安装 bower
sudo npm install -g bower
13. 安装前台需要的包
cd /<DIR>/src/frontend
(sudo)npm install
bower install
14. 安装 Mysql
sudo apt-get install mysql-server mysql-client
sudo apt-get install php5-mysql
创建 database user: root password: root
create database hopeland CHARACTER SET utf8;
15.
配置backend
cd /<DIR>/src/backend/
chmod 777 runtime
chmod 777 temps
创建默认 table
./yii migrate/up配置frontend
cd /<DIR>/src/frontend/
gulp
16. Init Rbac
./yii migrate --migrationPath=@yii/rbac/migrations/
Init rbac mechanism
./yii rbac/init
Change user's auth role
./yii rbac/set-auth
17. Config Resque with Supervisor
安装 supervisor
pip install supervisor
或者
easy_install supervisor
添加test.conf in /etc/supervisor/conf.d folder
[program:test_scheduler]
process_name=%(program_name)s_%(process_num)02d
directory=/var/www/test
command=php /var/www/test/src/backend/yii resque/scheduler
numprocs=1
redirect_stderr=True
autostart=True
autorestart= True
stdout_logfile=/var/log/supervisor/%(program_name)s-stdout.log
stderr_logfile=/var/log/supervisor/%(program_name)s-stderr.log
重启 supervisor
```sh
sudo supervisorctl reload
sudo supervisorctl restart all
18. Init jobs
./yii job/init
Start job
./yii job/start
19. 访问test.com