在Debian上配置ThinkPHP的路由,你需要遵循以下步骤:
composer create-project topthink/think your_project_name
将your_project_name替换为你的项目名称。
sudo apt update
sudo apt install nginx
/etc/nginx/sites-available目录下创建一个新的配置文件,例如your_project_name:sudo nano /etc/nginx/sites-available/your_project_name
server {
listen 80;
server_name your_domain_or_ip;
root /path/to/your_project_name/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
将your_domain_or_ip替换为你的域名或IP地址,将/path/to/your_project_name替换为你的项目路径。
sites-enabled目录:sudo ln -s /etc/nginx/sites-available/your_project_name /etc/nginx/sites-enabled/
sudo nginx -t
如果没有错误,重启Nginx服务:
sudo systemctl restart nginx
application目录下,找到route.php文件。如果没有这个文件,你可以创建一个。在route.php文件中,你可以定义路由规则。例如:<?php
use think\Route;
Route::get('/', 'index/Index/index');
Route::get('/hello/:name', 'index/Index/hello');
这将配置两个路由规则:一个用于主页,另一个用于显示带有参数name的问候消息。
现在,你已经在Debian上配置了ThinkPHP的路由。访问你的域名或IP地址,你应该能看到相应的页面。