Ubuntu PHP应用部署实操指南
一 环境准备与版本选择
二 部署两种常见方案
<VirtualHost *:80>
ServerName yourdomain.com
DocumentRoot /var/www/html/myproj/public
<Directory /var/www/html/myproj/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/myproj_error.log
CustomLog ${APACHE_LOG_DIR}/myproj_access.log combined
</VirtualHost>
server {
listen 80;
server_name yourdomain.com;
root /var/www/html/myproj/public;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
三 发布代码与数据库初始化
CREATE DATABASE myproj CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'myproj'@'localhost' IDENTIFIED BY 'StrongPass!';
GRANT ALL PRIVILEGES ON myproj.* TO 'myproj'@'localhost';
FLUSH PRIVILEGES;
四 安全与运维要点