在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項目。