在/home目录下新建www目录,进入www目录,新建imooc目录
安装git
<code>sudo apt-get install git</code>
下面命令的意思是克隆thinkPHP5从GitHub上,放到/home/www/imooc/tp5的目录下
<code>git clone https://github.com/top-think/think tp5</code>
然后进入tp5目录<code>cd tp5</code>
克隆再克隆核心框架仓库:<code>git clone https://github.com/top-think/framework</code>

进入/etc/nginx目录

放到如图所示的两个目录里面就可以默认加载

打开nginx下的conf.d的目录,新建tp5.conf,etc下面的目录都是管理员才能操作的,所以需要sudo,touch是新建文件的意思,用vim打开刚刚新建的tp5.conf

server{
server_name tp5.imooc.test;
root /home/www/imooc/tp5/public;
index index.php index.html;
location / {
//下面的if和括号之间必须有空格,查错查了几百遍才查出来
//用sudo nginx -t可以查看哪里写错了
if ( -f $request_filename ){
break;
}
if ( !-e $request_filename ){
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location ~ \.php{
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
try_files $uri = 404;
}
}
按Esc <code>:wq!</code>退出重启nginx
<code>sudo service nginx restart</code>
下面这个命令可以查看nginx是否在运行
<code> ps -A |grep nginx</code>

然后访问http://tp5.imooc.test ,这时候会爆出502的错误

这时候我们需要查看两个文件,一个是访问文件<code>tail -f /var/log/nginx/error.log</code>
一个是错误日志文件 <code>tail -f /var/log/nginx/error.log</code>
如果不让访问,用<code>sudo chmod 777 error.log</code>授权
连接被拒绝

打开下面的/etc/php5/fpm/pool.d文件夹下的www.conf

把域模式的监听方式注释掉,然后使用端口的方式监听,据说更稳定

保存退出,重启php服务<code>sudo service php5-fpm restart</code> 或者<code>sudo /etc/init.d/php5-fpm restart</code>都可以
然后就配置完了,刷新,应该可以访问了。

然后是apache,打开/etc/apache2/apache2.conf文件

可以看到apache2的配置文件在sites-enabled文件夹下
进入这个文件夹,新建tp5.conf文件

在tp5.conf文件中写入
<VirtualHost *:8888>
ServerName tp5.imooc.test
DocumentRoot /home/www/mooc/vagrant/phpmvc/tp5/public/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
保存,退出,<code>sudo service apache2 restart</code>

不让访问,看看错误日志,打开/var/log/apache2/error.log

看到访问被拒绝,打开/etc/apache2/apache2.conf文件

把这一行前面加个#注释掉

然后保存,重启apache2

然后再访问浏览器就可以了

打开tp5/application/index/controller/Index.php,在index方法后面加一个test方法。

访问路径

增加配置
location ~ \.php{
set $script $uri;
set $path_info "";
if ( $uri ~ "^(.+\.php)(/.+)"){
set $script $1;
set $path_info $2;
}
include fastcgi_params;
fastcgi_index index.php?IF_REWRITE=1;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $script;
try_files $uri = 404;
}
重启nginx,然后再刷新访问,至少没有拒绝。


开启apache的rewrite规则<code> sudo a2enmod rewrite</code>
将apache的这一行配置的None改为All

然后去掉index.php的索引文件也能访问

网友评论