You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CentOS7/Apache下已有PHP7时安装PHP5.6并配置特定虚拟主机

Hey there! I’ve helped a bunch of folks set up multiple PHP versions on CentOS 7 with Apache, so let’s walk through this step by step to get your PHP 5.6-only code running on a specific virtual host while keeping PHP 7 intact.

1. Install PHP 5.6 alongside your existing PHP 7

CentOS 7’s default repos don’t include PHP 5.6, so we’ll use the Remi repository (a trusted source for updated PHP packages). Here’s how to get it set up:

  • First, install the required repository files:
    sudo yum install -y epel-release
    sudo yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm
    
  • Enable the Remi repo specifically for PHP 5.6:
    sudo yum-config-manager --enable remi-php56
    
  • Install PHP 5.6 and common modules (note the php56- prefix to avoid conflicts with your existing PHP 7):
    sudo yum install -y php56 php56-php-cli php56-php-fpm php56-php-mysqlnd php56-php-gd php56-php-xml php56-php-mbstring
    
  • Start the PHP 5.6 FPM service and set it to run automatically on system boot:
    sudo systemctl start php56-php-fpm
    sudo systemctl enable php56-php-fpm
    
  • Verify the service is running (look for "active (running)" in the output):
    sudo systemctl status php56-php-fpm
    
2. Configure your specific virtual host to use PHP 5.6

We’ll use Apache’s mod_proxy_fcgi to route PHP requests for your target virtual host to the PHP 5.6 FPM process. Here’s the detailed setup:

  • First, make sure mod_proxy_fcgi is installed and enabled:
    sudo yum install -y mod_proxy_fcgi
    sudo systemctl restart httpd
    
  • Locate your Apache virtual host configuration directory (usually /etc/httpd/conf.d/ or /etc/httpd/sites-available/). Create or edit the config file for your target domain (e.g., legacy-app.conf):
    <VirtualHost *:80>
        ServerName your-legacy-app-domain.com
        ServerAlias www.your-legacy-app-domain.com
        DocumentRoot /var/www/legacy-app/public_html
    
        # Disable mod_php to prevent PHP 7 from handling requests for this domain
        php_admin_flag engine off
    
        # Route PHP requests to PHP 5.6 FPM
        <FilesMatch \.php$>
            # Check your PHP 5.6 FPM listen path first (see note below)
            SetHandler "proxy:unix:/run/php56-php-fpm/www.sock|fcgi://localhost"
        </FilesMatch>
    
        # Logging configuration (adjust paths to your preference)
        ErrorLog /var/log/httpd/legacy-app_error.log
        CustomLog /var/log/httpd/legacy-app_access.log combined
    </VirtualHost>
    
    Important note: To confirm the correct listen path for PHP 5.6 FPM, run this command:
    grep 'listen =' /etc/opt/remi/php56/php-fpm.d/www.conf
    
    If it returns a port like 127.0.0.1:9000 instead of a socket path, update the SetHandler line to:
    SetHandler "proxy:fcgi://127.0.0.1:9000"
    
  • Create your app’s document root and set proper permissions for Apache:
    sudo mkdir -p /var/www/legacy-app/public_html
    sudo chown -R apache:apache /var/www/legacy-app/public_html
    sudo chmod -R 755 /var/www/legacy-app/public_html
    
  • Test your Apache configuration for syntax errors:
    sudo apachectl configtest
    
    If you see Syntax OK, restart Apache to apply the changes:
    sudo systemctl restart httpd
    
  • Verify the setup works: Create a info.php file in your app’s document root with this content:
    <?php phpinfo(); ?>
    
    Visit http://your-legacy-app-domain.com/info.php in your browser—you should see PHP 5.6 listed as the active version.

内容的提问来源于stack exchange,提问作者user3181303

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 06:48:05