在 CentOS 上安装 Laravel 时,可能会遇到权限不足的问题
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
www-data
或 nginx
):sudo chown -R www-data:www-data /path/to/your/laravel-project
sudo find /path/to/your/laravel-project -type d -exec chmod 755 {} \;
sudo find /path/to/your/laravel-project -type f -exec chmod 644 {} \;
public
)设置为文档根目录。例如,对于 Apache,你需要在虚拟主机配置中添加以下内容:<VirtualHost *:80>
ServerName yourdomain.com
DocumentRoot /path/to/your/laravel-project/public
<Directory /path/to/your/laravel-project/public>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
对于 Nginx,你需要在虚拟主机配置中添加以下内容:
server {
listen 80;
server_name yourdomain.com;
root /path/to/your/laravel-project/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
完成以上步骤后,你应该可以在 CentOS 上成功安装 Laravel 并运行它。如果仍然遇到权限问题,请检查 Web 服务器的错误日志以获取更多详细信息。