温馨提示×

phpstorm在centos上如何实现自动化部署

小樊
65
2025-06-14 08:30:50
栏目: 编程语言

在CentOS上实现PhpStorm的自动化部署通常涉及以下几个步骤:

  1. 安装必要的软件包:确保你的CentOS系统已经安装了所有必要的软件包,如MySQL、Nginx和PHP。可以使用以下命令来完成:
# 安装MySQL
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
yum install mysql57-community-release-el7-11.noarch.rpm
yum install mysql-community-server
systemctl start mysqld
systemctl enable mysqld

# 安装Nginx
yum install gcc-c++ zlib openssl openssl-devel
mkdir /usr/local/nginx
cd /usr/local/nginx
wget http://nginx.org/download/nginx-1.21.4.tar.gz
tar -zxvf nginx-1.21.4.tar.gz
cd nginx-1.21.4
./configure
make && make install

# 安装PHP
yum install epel-release
yum install gcc automake autoconf libtool make gcc-c++ glibc libmcrypt
  1. 配置Web服务器:配置Nginx以使用PHP,并设置虚拟主机。编辑Nginx配置文件 /usr/local/nginx/conf/nginx.conf,在配置文件中添加以下内容:
server {
    listen 80;
    server_name your_domain_or_ip;
    root /path/to/your/php/project;
    index index.php index.html index.htm;
    location / {
        try_files $uri $uri/ = 404;
    }
    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

重启Nginx以应用更改:

systemctl restart nginx
  1. 配置PhpStorm
  • 打开PhpStorm,创建一个新项目或打开现有项目。
  • 在“Deployment”选项卡中,配置远程解释器,指向你的PHP安装路径。
  • 设置部署选项,如映射本地项目目录到远程服务器目录。
  1. 使用Git实现自动化部署
  • 创建Git用户并添加权限:
# 创建一个名叫jouzeyu的用户
adduser jouzeyu

# 给git用户添加权限
mkdir /home/git
cd /home/git
mkdir .ssh
touch authorized_keys
cd .ssh
cat ~/.ssh/id_rsa.pub  # 复制公钥到authorized_keys文件
  • 初始化仓库并配置权限:
mkdir /www/wwwroot/git
cd /www/wwwroot/git
git init --bare website.git
chown -R git:git website.git
  • 克隆项目到服务器:
mkdir /www/wwwroot/test
cd /www/wwwroot/test
git clone /www/wwwroot/git/website.git
chown -R git website
  • 在PhpStorm中配置Deployment:

  • 打开PhpStorm,转到 File > Settings

  • 选择 Build, Execution, Deployment > Deployment,点击 Configuration... 按钮。

  • 点击 + 图标以添加一个新的服务器配置,选择 SFTP 作为连接类型。

  • 填写服务器的地址、端口、用户名和密码等信息。

  • Mappings 选项卡中,指定本地项目文件夹与服务器上项目文件夹之间的映射关系。

  • 点击 OK 保存配置。

通过以上步骤,你就可以在CentOS上使用PhpStorm进行自动化部署了。如果在配置过程中遇到问题,可以参考PhpStorm的官方文档或相关社区论坛寻求帮助。

0