在Linux系统中部署ThinkPHP应用,可以按照以下步骤进行:
sudo apt update
sudo apt install apache2
sudo apt update
sudo apt install nginx
sudo apt update
sudo apt install php php-cli php-fpm php-mysql php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath
编辑/etc/apache2/sites-available/000-default.conf文件,添加以下内容:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
启用站点:
sudo a2ensite 000-default.conf
sudo systemctl restart apache2
编辑/etc/nginx/sites-available/default文件,添加以下内容:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # 根据PHP版本调整
}
location ~ /\.ht {
deny all;
}
}
重启Nginx:
sudo systemctl restart nginx
下载ThinkPHP应用:
cd /var/www/html
git clone https://github.com/top-think/thinkphp.git myapp
cd myapp
配置数据库:
编辑application/database.php文件,配置数据库连接信息。
安装Composer依赖:
composer install
运行应用:
php run start
确保防火墙允许HTTP和HTTPS流量:
sudo ufw allow 'Nginx Full'
如果你需要HTTPS,可以使用Let’s Encrypt免费获取SSL证书:
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com
通过以上步骤,你应该能够在Linux系统中成功部署ThinkPHP应用。