在Debian系统中配置Laravel路由,你需要遵循以下步骤:
sudo apt-get update sudo apt-get install laravel laravel new project_name 这将在当前目录下创建一个名为project_name的新文件夹,其中包含Laravel项目的所有文件。
首先,安装Nginx:
sudo apt-get install nginx 然后,创建一个新的Nginx配置文件:
sudo nano /etc/nginx/sites-available/project_name 将以下内容粘贴到配置文件中,替换project_name为你的实际项目名称,并将/var/www/project_name/public替换为你的项目公共目录的实际路径:
server { listen 80; server_name example.com; # 替换为你的域名或公网IP地址 root /var/www/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; # 根据你的PHP版本进行修改 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 保存并关闭文件。接下来,创建一个符号链接以启用此配置:
sudo ln -s /etc/nginx/sites-available/project_name /etc/nginx/sites-enabled/ 检查Nginx配置文件是否有语法错误:
sudo nginx -t 如果没有错误,重启Nginx服务:
sudo systemctl restart nginx routes/web.php文件,添加你需要的路由。例如:Route::get('/', function () { return 'Hello, World!'; }); Route::get('/about', function () { return 'About page'; }); http://example.com(或你的域名/IP地址)来测试你的Laravel应用程序。你应该看到"Hello, World!“页面。点击”/about"链接,你应该看到"About page"页面。这就是在Debian系统上配置Laravel路由的过程。如果你遇到任何问题,请随时提问。