在CentOS上处理Laravel请求,你需要遵循以下步骤:
composer global require laravel/installer
laravel new your_project_name
这将在your_project_name目录中创建一个新的Laravel项目。
/etc/nginx/conf.d/your_project_name.conf文件中添加以下配置:server {
listen 80;
server_name your_domain.com;
root /path/to/your_project_name/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
对于Apache,你需要在/etc/httpd/conf.d/your_project_name.conf文件中添加以下配置:
<VirtualHost *:80>
ServerName your_domain.com
DocumentRoot /path/to/your_project_name/public
<Directory /path/to/your_project_name/public>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/your_project_name_error.log
CustomLog ${APACHE_LOG_DIR}/your_project_name_access.log combined
</VirtualHost>
storage和bootstrap/cache目录具有可写权限:sudo chmod -R 775 /path/to/your_project_name/storage
sudo chmod -R 775 /path/to/your_project_name/bootstrap/cache
对于Nginx:
sudo systemctl restart nginx
对于Apache:
sudo systemctl restart httpd
http://your_domain.com来访问你的Laravel项目。如果你在本地开发环境中遇到问题,请确保你的防火墙允许HTTP和HTTPS流量。以上步骤应该可以帮助你在CentOS上处理Laravel请求。如果你遇到任何问题,请查看Laravel文档以获取更多详细信息和故障排除指南。