laravel php artisan serve怎么启动nginx运行
时间: 2023-11-28 20:24:03 浏览: 44
`php artisan serve` 是启动 PHP 内置的开发服务器,而不是 Nginx。
如果您想使用 Nginx 运行 Laravel 应用程序,需要进行以下步骤:
1. 安装 Nginx 和 PHP-FPM:
```
sudo apt update
sudo apt install nginx php-fpm
```
2. 配置 Nginx 以处理 Laravel 应用程序的请求。例如,您可以在 `/etc/nginx/sites-available` 目录下创建一个名为 `laravel` 的文件,并按以下示例进行配置:
```
server {
listen 80;
server_name example.com;
root /var/www/laravel/public;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
```
这个配置文件假定您的 Laravel 应用程序位于 `/var/www/laravel` 目录下。如果应用程序位于不同的位置,则需要相应地更改 `root` 指令。
3. 使 Nginx 加载配置文件:
```
sudo ln -s /etc/nginx/sites-available/laravel /etc/nginx/sites-enabled/
sudo systemctl restart nginx
```
4. 确保您的应用程序配置文件中的 `APP_URL` 值与 `server_name` 指令的值匹配。
```
APP_URL=http://example.com
```
完成上述步骤后,您可以使用以下命令启动 PHP-FPM:
```
sudo systemctl start php7.4-fpm
```
现在,您的 Laravel 应用程序应该可以通过 Nginx 访问了。