Laravel部署环境搭建
PHP
sudo apt install php
Nginx
sudo apt install nginx
cd /etc/nginx/conf.d/
vi laravel..conf
server {
listen 80;
listen [::]:80;
server_name example.com;
root /var/www/example/public;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
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 ~ ^/index\.php(/|$) {
fastcgi_pass unix:/run/php/php8.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_buffer_size 32k;
fastcgi_buffers 8 32k;
fastcgi_busy_buffers_size 64k;
fastcgi_hide_header X-Powered-By;
}
location ~ \.php$ {
return 404;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
SQL
mysql -u root -p
CREATE DATABASE laravel;
CREATE USER admin IDENTIFIED BY "********";
GRANT ALL PRIVILEGES ON laravel.* TO admin;
FLUSH PRIVILEGES;
EXIT;
Composer
https://getcomposer.org/download/
win 执行 Composer-Setup.exe
linux 执行 sudo apt install -y composer
验证版本号
composer --version
composer config --list --global
composer config --list --global
取消配置
composer config -g --unset repos.packagist
阿里云
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
华为
composer config -g repos.packagist composer https://repo.huaweicloud.com/repository/php/
腾讯
composer config -g repos.packagist composer https://mirrors.tencent.com/composer/
全量
composer config -g repo.packagist composer https://packagist.phpcomposer.com
若项目之前已通过其他源安装,则需要更新 composer.lock 文件
composer update --lock
诊断
composer diagnose
#安装
composer install
清理缓存
composer clear
更新
composer update
nodejs
apt remove -y nodejs npm
apt autoremove -y
curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
apt install -y nodejs
node -v # 期望 v22.x
npm -v # 期望 10.x+
which -a node npm