在CentOS上部署PHP项目的流程大致如下:
更新系统:
sudo yum update -y
安装Web服务器:
sudo yum install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd
sudo yum install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
安装PHP及其常用扩展:
sudo yum install php php-mysqlnd php-fpm php-mbstring php-xml -y
配置Web服务器:
配置Apache:
sudo a2enmod php7.x
sudo systemctl restart apache2
info.php
:echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
在浏览器中访问http://your_server_ip/info.php
。如果看到PHP信息页面,说明PHP工作正常。配置Nginx:
sudo systemctl start php7.x-fpm
sudo systemctl enable php7.x-fpm
/etc/nginx/sites-available/default
或对应的站点配置文件中,添加以下配置:server {
listen 80;
server_name your_server_ip;
root /var/www/html; # 指向您的网站路径
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.x-fpm.sock; # 替换为您的PHP-FPM版本
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
sudo nginx -t
sudo systemctl restart nginx
配置防火墙:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
部署应用程序:
将您的PHP应用程序文件上传到/var/www/html
目录(或您所选择的其他目录)。确保文件权限设置正确。
测试部署: 在浏览器中访问您配置的服务器IP或域名,检查您的PHP应用程序是否正确运行。
以上步骤涵盖了在CentOS上部署PHP项目的基本流程。根据具体项目的需求,可能还需要进行进一步的配置和调整。