Laravel部署环境搭建
PHP
sudo apt install php
PHP >= 8.3
Laravel also requires the following PHP extensions:
Ctype PHP Extension
cURL PHP Extension
DOM PHP Extension
Fileinfo PHP Extension
Filter PHP Extension
Hash PHP Extension
Mbstring PHP Extension
OpenSSL PHP Extension
PCRE PHP Extension
PDO PHP Extension
Session PHP Extension
Tokenizer PHP Extension
XML PHP Extension
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
composer config --list --global
清理缓存
composer clear
更新
composer update
nodejs
windows
# 下载并安装 fnm:
winget install Schniz.fnm
# 下载并安装 Node.js:
fnm install 26
# 验证 Node.js 版本:
node -v # Should print "v26.13.1".
# 验证 npm 版本:
npm -v # Should print "11.20.0".
linux
# 下载并安装 fnm:
curl -o- https://fnm.vercel.app/install | bash
# 下载并安装 Node.js:
fnm install 26
# 验证 Node.js 版本:
node -v # Should print "v26.13.1".
# 验证 npm 版本:
npm -v # Should print "11.20.0".
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
