在CentOS上部署ThinkPHP项目,可以按照以下步骤进行:
首先,确保你的CentOS系统已经安装了以下软件:
sudo yum install httpd
sudo systemctl start httpd
sudo systemctl enable httpd
sudo yum install php php-mysqlnd php-gd php-mbstring php-xml php-pear php-bcmath
sudo systemctl restart httpd
sudo yum install mysql-server
sudo systemctl start mysqld
sudo systemctl enable mysqld
sudo mysql_secure_installation
编辑Apache配置文件 /etc/httpd/conf/httpd.conf
或创建一个新的虚拟主机配置文件 /etc/httpd/conf.d/your_project.conf
:
<VirtualHost *:80>
ServerName your_project_domain.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/your_project_error.log
CustomLog /var/log/httpd/your_project_access.log combined
</VirtualHost>
重启Apache:
sudo systemctl restart httpd
编辑Nginx配置文件 /etc/nginx/nginx.conf
或创建一个新的服务器块配置文件 /etc/nginx/conf.d/your_project.conf
:
server {
listen 80;
server_name your_project_domain.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/your_project_error.log;
access_log /var/log/nginx/your_project_access.log;
}
重启Nginx:
sudo systemctl restart nginx
cd /path/to/deploy
git clone https://github.com/your/thinkphp-project.git
cd thinkphp-project
composer install --no-dev --optimize-autoloader
编辑 .env
文件,配置数据库连接信息:
DB_TYPE=mysql
DB_HOST=127.0.0.1
DB_NAME=your_database_name
DB_USER=your_database_user
DB_PASSWORD=your_database_password
DB_PORT=3306
DB_PREFIX=
php think migrate
确保项目目录和文件权限正确:
sudo chown -R apache:apache /path/to/your/thinkphp/project
sudo chmod -R 755 /path/to/your/thinkphp/project
如果你使用的是Apache:
sudo systemctl start httpd
sudo systemctl enable httpd
如果你使用的是Nginx:
sudo systemctl start nginx
sudo systemctl enable nginx
打开浏览器,访问 http://your_project_domain.com
,你应该能够看到你的ThinkPHP项目。
通过以上步骤,你就可以在CentOS上成功部署ThinkPHP项目了。