ThinkPHP在Ubuntu上的部署流程如下:
安装基础环境
sudo apt update && sudo apt install php php-cli php-fpm php-mysql php-mbstring php-xml php-curlcurl -sS https://getcomposer.org/installer | php && sudo mv composer.phar /usr/local/bin/composer配置Web服务器(以Nginx为例)
sudo apt install nginx/etc/nginx/sites-available/default):server {
listen 80;
server_name your_domain_or_ip;
root /path/to/your/project/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:/var/run/php/php7.x-fpm.sock;
}
}
(需将php7.x-fpm.sock替换为实际版本,如php8.2-fpm.sock)sudo systemctl restart nginx部署ThinkPHP项目
composer create-project topthink/think tp6 /path/to/your/project配置数据库
.env文件:DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_NAME=your_db_name
DB_USER=your_db_user
DB_PASSWORD=your_db_password
php think migrate:run设置权限并启动
sudo chown -R www-data:www-data /path/to/your/project && sudo chmod -R 755 /path/to/your/projectcd /path/to/your/project && php think run(仅限开发测试)访问项目
http://your_domain_or_ip,查看项目是否正常运行。注意事项:
.env中app_debug=false)。fastcgi_pass路径是否正确。