Ubuntu 上搭建 ThinkPHP 开发环境
一 环境准备与安装
二 创建项目与目录权限
三 Web 服务器配置
server {
listen 80;
server_name your_domain_or_ip;
root /var/www/html/tp6/public;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock; # 按实际 PHP 版本调整
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.env { deny all; }
}
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/tp6/public
<Directory /var/www/html/tp6/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
四 框架配置与本地开发启动
DB_TYPE=mysql
DB_HOST=127.0.0.1
DB_NAME=tp6
DB_USER=tp6
DB_PASSWORD=StrongPass!
DB_PORT=3306
DB_PREFIX=
五 生产环境建议