在Linux环境下配置ThinkPHP环境是一个相对直接的过程,但需要确保所有必要的组件都已正确安装和配置。以下是一个详细的部署指南:
安装基础软件包:
对于Ubuntu/Debian系统:
sudo apt update && sudo apt upgrade -y sudo apt install php php-fpm php-mysql php-mbstring php-xml php-curl -y sudo apt install nginx -y 对于CentOS/RHEL系统:
sudo yum update -y sudo yum install php php-fpm php-mysqlnd php-mbstring php-xml php-curl -y sudo yum install epel-release -y sudo yum install nginx -y 安装Composer:
curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer Nginx配置:
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/thinkphp sudo ln -s /etc/nginx/sites-available/thinkphp /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl restart nginx Apache配置:
确保已启用 mod_rewrite 模块:
sudo a2enmod rewrites sudo service apache2 restart 下载并解压项目:
wget https://example.com/thinkphp6.x.zip unzip thinkphp6.x.zip -d /var/www/html/thinkphp 配置数据库连接:
编辑 application/database.php 文件,确保数据库连接信息正确。
设置目录权限:
sudo chown -R www-data:www-data /var/www/html/thinkphp sudo chmod -R 755 /var/www/html/thinkphp 配置虚拟主机(可选):
如果你使用了Apache,确保在 httpd.conf 或 sites-available 目录下的配置文件中指向了正确的项目目录。
启动Web服务器:
sudo service nginx restart # 或者 sudo service apache2 restart 访问项目:
在浏览器中输入你的服务器IP地址或域名,加上项目的路径,例如 http://yourdomain.com/thinkphp 。
fastcgi_pass 路径正确。try_files $uri $uri/ /index.php?$query_string; 。composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ 。app_debug 以提高安全性。.env 文件访问:防止敏感信息泄露。