thinkphp6的安装与部署
环境要求
PHP >= 7.1.0
安装Composer
6.0版本开始,必须通过Composer方式安装和更新,所以你无法通过Git下载安装。
curl -sS https://getcomposer.org/installer | phpmv composer.phar /usr/local/bin/composer
我们建议使用国内镜像(阿里云)
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
安装稳定版
composer create-project topthink/think tp
这里的tp目录名你可以任意更改,这个目录就是我们后面会经常提到的应用根目录。
如果你之前已经安装过,那么切换到你的应用根目录下面,然后执行下面的命令进行更新:
composer update topthink/framework
更新操作会删除thinkphp目录重新下载安装新版本,但不会影响app目录,因此不要在核心框架目录添加任何应用代码和类库。
安装和更新命令所在的目录是不同的,更新必须在你的应用根目录下面执行
安装开发版
一般情况下,composer 安装的是最新的稳定版本,不一定是最新版本,如果你需要安装实时更新的版本(适合学习过程),可以安装6.0.x-dev版本。
composer create-project topthink/think=6.0.x-dev tp
开启调试模式
应用默认是部署模式,在开发阶段,可以修改环境变量APP_DEBUG开启调试模式,上线部署后切换到部署模式。
本地开发的时候可以在应用根目录下面定义.env文件。
通过create-project安装后在根目录会自带一个.example.env文件(环境变量示例),你可以直接更名为.env文件并根据你的要求进行修改,该示例文件已经开启调试模式
修改nginx配置文件
vim tp6.conf
server {listen 80;server_nameapp.tp6.com;#charset koi8-r;#access_loglogs/host.access.logmain;root /data/web/tp6/public; location / {indexindex.html index.htm index.php;if ( -f $request_filename) { break;}if (!-e $request_filename) {rewrite^/(.*)$/index.php/$1last; break;}}#error_page404/404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504/50x.html;location = /50x.html {root html;}location ~ .+\.php($|/) {set $script$uri;set $path_info"/";if ($uri ~ "^(.+\.php)(/.+)") {set $script $1;set $path_info$2; } fastcgi_pass 127.0.0.1:9000;fastcgi_indexindex.php?IF_REWRITE=1;include fastcgi_params;fastcgi_param PATH_INFO $path_info;fastcgi_param SCRIPT_FILENAME$document_root/$script;fastcgi_param SCRIPT_NAME $script;fastcgi_paramMDZ_ENV"local";}}
重启nginx或者重新加载配置文件
systemctl reload nginx.service
或
systemctl restart nginx.service
修改本地windows系统环境的hosts文件,在C:\Windows\System32\drivers\etc 下hosts
加入
20.20.24.134 app.tp6.com
浏览器中访问 app.tp6.com