在CentOS上部署ThinkPHP项目,可以按照以下步骤进行:
首先,确保你的CentOS系统已经安装了以下软件:
sudo yum install epel-release sudo yum install nginx sudo systemctl start nginx sudo systemctl enable nginx
sudo yum install php-fpm php-mysqlnd php-gd php-mbstring php-xml php-pear php-bcmath sudo systemctl start php-fpm sudo systemctl enable php-fpm
sudo yum install mysql-server sudo systemctl start mysqld sudo systemctl enable mysqld
编辑Nginx配置文件,通常位于 /etc/nginx/nginx.conf
或 /etc/nginx/conf.d/default.conf
。
server { listen 80; server_name your_domain.com; # 替换为你的域名或IP地址 root /path/to/your/thinkphp/project; # 替换为你的ThinkPHP项目路径 index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; include fastcgi.conf; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; } location ~ /\.ht { deny all; } }
保存并退出编辑器,然后重启Nginx:
sudo systemctl restart nginx
确保PHP-FPM配置正确,通常位于 /etc/php-fpm.d/www.conf
。
listen = /var/run/php-fpm/php-fpm.sock listen.owner = nginx listen.group = nginx user = nginx group = nginx
重启PHP-FPM:
sudo systemctl restart php-fpm
将你的ThinkPHP项目文件上传到 /path/to/your/thinkphp/project
目录下。
如果你的项目使用数据库,确保在MySQL中创建相应的数据库和用户,并授权访问。
CREATE DATABASE your_database_name; CREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password'; GRANT ALL PRIVILEGES ON your_database_name.* TO 'your_username'@'localhost'; FLUSH PRIVILEGES;
在ThinkPHP项目的 .env
文件中配置数据库连接信息:
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=your_database_name DB_USERNAME=your_username DB_PASSWORD=your_password
进入项目目录并运行以下命令来安装依赖:
cd /path/to/your/thinkphp/project composer install
然后启动项目:
cd /path/to/your/thinkphp/project php run start
打开浏览器,访问 http://your_domain.com
,你应该能够看到你的ThinkPHP项目运行起来了。
以上步骤涵盖了在CentOS上部署ThinkPHP项目的基本流程。根据你的具体需求,可能还需要进行一些额外的配置和优化。