vagrant的学习 之 ThinkPHP3.2

mac2022-06-30  22

vagrant的学习 之 ThinkPHP3.2


 

(1)在web目录下新建tp32目录:

cd /home/www/ mkdir tp32

(2)下载框架

我从ThinkPHP官网下载了ThinkPHP_3.2.3_full.zip,然后上传到虚拟机的里,解压到新建的tp32目录里。


(3)添加虚拟主机域名:

在nginx的配置文件里新建配置文件:

cd /etc/nginx/conf.d/ touch tp32.conf

编辑:sudo vim tp32.conf

server{ server_name study.tp32.com; root /home/www/tp32; index index.php index.html; location / { if ( -f $request_filename){ break; } if ( !-e $request_filename){ rewrite ^/(.*)$ /index.php/$1 last; break; } } location ~ \.php{ set $script $uri; set $path_info ""; if ($uri ~ "^(.+\.php)(/.+)"){ set $script $1; set $path_info $2; } include fastcgi_params; 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; } }

重写规则可以参照ThinkPHP3.2完全开发手册【部署】-->【URL重写】:

http://document.thinkphp.cn/manual_3_2.html#url_rewrite。

修改HOSTS文件:

sudo vim /etc/hosts

增加一行:

IP地址 study.tp32.com

重启nginx后,然后在本地机器上,访问 study.tp32.com,可以看到 欢迎使用 ThinkPHP 的界面。

重写配置好之后就可以以常见的url模式访问了:http://study.tp32.com/Home/Index/index。 


 如果web服务器时apache:

//创建tp32的apache的配置文件 cd /etc/apache2/sites-enabled sudo touch tp32.conf //编辑文件 <VirtualHost *:8888> ServerName study.tp32.com DocumentRoot /home/www/tp32/ ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> //开启apache的重写模块 sudo a2enmod rewrite //修改apache的允许重写访问 cd /etc/apache2 sudo vim apache2.conf <Directory /> Options FollowSymLinks AllowOverride None #修改成AllowOverride ALL 打开rewrite #Require all denied #把这行屏蔽掉,拒绝一切链接 </Directory>

重启apache:sudo service apache2 restart 或者 sudo /etc/init.d/apache2 restart

访问:study.tp32.com:8888就可以了。


 

总结:

  编写nginx重写规则后,修改ThinkPHP的配置项 URL_MODEL 后好像就没区别了;

  对重写的规则一知半解,需要深入学习。


 

欢迎大家指点哦~


 

转载于:https://www.cnblogs.com/gyfluck/p/9560051.html

最新回复(0)