在 Ubuntu 上使用 ThinkPHP 创建项目,通常有两种主流方式:Composer(推荐) 和 手动下载。下面以 ThinkPHP 6 / 8 为例说明。
sudo apt update
sudo apt install php php-cli php-common php-mbstring php-xml php-curl php-mysql unzip
查看版本:
php -v
sudo apt install composer
或官方方式:
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
验证:
composer -V
composer create-project topthink/think tp_project
tp_project是项目目录名,可自定义
cd tp_project
php think run
默认访问地址:
http://127.0.0.1:8000
server {
listen 80;
server_name tp.test;
root /var/www/tp_project/public;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
}
}
tp_project
├── app # 应用目录
├── public # 入口文件(web根目录)
├── config # 配置
├── route # 路由
└── think # 命令行入口
sudo chown -R www-data:www-data storage
chmod -R 755 storage
修改 .env:
APP_DEBUG = true
public/index.php如果你告诉我:
我可以给你更精确的配置步骤。