在CentOS服务器上部署ThinkPHP项目,可以按照以下步骤进行:
sudo yum install httpd
sudo systemctl start httpd
sudo systemctl enable httpd
sudo yum install nginx
sudo systemctl start nginx
sudo systemctl enable nginx
sudo yum install php php-mysqlnd php-gd php-mbstring php-xml php-zip
sudo systemctl restart httpd # 如果使用Apache
# 或者
sudo systemctl restart nginx # 如果使用Nginx
编辑/etc/httpd/conf/httpd.conf
或创建一个新的虚拟主机文件(如/etc/httpd/conf.d/yourapp.conf
):
<VirtualHost *:80>
ServerName yourdomain.com
DocumentRoot /path/to/your/thinkphp/project
<Directory /path/to/your/thinkphp/project>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/httpd/yourapp-error.log
CustomLog /var/log/httpd/yourapp-access.log combined
</VirtualHost>
编辑/etc/nginx/nginx.conf
或创建一个新的服务器块文件(如/etc/nginx/conf.d/yourapp.conf
):
server {
listen 80;
server_name yourdomain.com;
root /path/to/your/thinkphp/project;
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;
}
error_log /var/log/nginx/yourapp-error.log;
access_log /var/log/nginx/yourapp-access.log;
}
将你的ThinkPHP项目文件上传到服务器上的指定目录(如/path/to/your/thinkphp/project
)。
确保你的ThinkPHP项目配置文件(通常是application/database.php
)中的数据库连接信息正确。
cd /path/to/your/thinkphp/project
sudo chown -R apache:apache .
sudo chmod -R 755 .
cd /path/to/your/thinkphp/project
sudo chown -R nginx:nginx .
sudo chmod -R 755 .
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
打开浏览器,访问你的服务器域名或IP地址,查看ThinkPHP项目是否正常运行。
确保防火墙允许HTTP和HTTPS流量:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
通过以上步骤,你应该能够在CentOS服务器上成功部署ThinkPHP项目。