回到/home/www/imooc目录下输入命令sudo wget https://github.com/yiisoft/yii2/releases/download/2.0.10/yii-basic-app-2.0.10.tgz
下载yii2的basic安装包
我这里下载不下来,只好下载到本地电脑,然后,使用SCP命令SSH传到vagrant虚拟主机里,scp /c/办公/box/imooc/yii-basic-app-2.0.10.tgz [email protected]:/tmp
,tmp目录有不用改权限,然后再拷贝到/home/www/imooc目录下
这里的laravel是zip的,服务器上没法解压,所以我下载下来,重新打包上传。scp [email protected]:/home/www/imooc/laravel-v5.1.11.zip /c/办公/box/imooc
本地解压后,在git bash里使用tar.gz的压缩命令tar zcvf laravel.tar.gz laravel
然后上传到虚拟机
解压yii和laravel
sudo tar -xvf yii-basic-app-2.0.10.tgz
sudo tar -xvf laravel.tar.gz
进入/etc/nginx/conf.d,新建yii2.conf
在yii2.conf配置下面代码,记得将basic目录改为yii2
server{
server_name yii.imooc.test;
root /home/www/imooc/yii2/web;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
try_files $uri=404;
}
}
配置hosts文件
保存,重启nginx,打开浏览器,访问http://yii.imooc.test
有个错误,需要配置,打开/home/www/imooc/yii2/config.php文件,将'cookieValidationKey' => '',
的值补上
然后就正常了
然后再配置apache2,在/etc/apache2/sites-enabled下面新建yii2.conf
ServerName yii.imooc.test
DocumentRoot /home/www/imooc/yii2/web
重启apache,访问yii.imooc.test
进入这个目录/home/www/imooc/yii2/controllers
打开SiteController.php,新建一个函数
打开/home/www/imooc/yii2/config/web.php,
将urlManger的注释去掉,保存
但是apache下面打不开
在/home/www/imooc/yii2/web下新建 .htaccess文件,复制下面的代码
RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php
保存,刷新浏览器
开始配置laravel目录,进入/etc/nginx/conf.d,将yii2.conf复制成laravel.conf
sudo cp yii2.conf laravel.conf
vim打开laravel.conf,只需要改一下第二第三行的域名和index文件的路径。
server{
server_name laravel.imooc.test;
root /home/www/imooc/laravel/public;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
try_files $uri = 404;
}
}
重启nginxsudo /etc/init.d/nginx restart
,然后配置本地hosts文件
进入/etc/apache2/sites-enabled目录,将yii2.conf复制成laravel.conf
配置下面代码,然后重启apache
ServerName laravel.imooc.test
DocumentRoot /home/www/imooc/laravel/public
配置完apache和nginx都无法访问,报500的错误。查看nginx日志文件,
然后我搜索了一下,stackoverflow上的大神们解释说是,无法往硬盘写入日志导致
http://stackoverflow.com/questions/32319106/laravel-white-page-500-internal-server-error
我偷懒,直接把整个laravel文件夹赋予读写权限sudo chmod -R 777 laravel
然后访问nginx的80端口
apache的8888端口都正常了