在CentOS上安装Laravel并优化其性能,可以通过以下步骤实现:
sudo yum update -y
sudo yum install nginx php php-fpm php-mysql php-json php-gd php-mbstring php-xml php-pear php-zip -y
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer
composer create-project --prefer-dist laravel/laravel my_laravel_project
sudo chown -R nginx:nginx /path/to/my_laravel_project
sudo chmod -R 755 /path/to/my_laravel_project/storage
sudo chmod -R 755 /path/to/my_laravel_project/bootstrap/cache
server {
listen 80;
server_name your_domain_or_IP;
root /path/to/my_laravel_project/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
sudo systemctl restart nginx
.env
文件中的APP_DEBUG
设置为false
。APP_ENV=production
APP_DEBUG=false
php artisan route:cache
php artisan config:cache
通过上述步骤,你不仅能够在CentOS上成功安装Laravel,还能优化其性能,确保你的Web应用程序运行高效。