• Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
logo logo
  • Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
ENEN
  • 简体简体
  • 繁體繁體
Client Area

Apache for Newbie: Set up Apache for multiple PHP versions

December 17, 2023

Apache for Newbie: Set up Apache for multiple PHP versions

Apache is one of the most popular web servers in the world, and it’s no surprise that many VPS hosting companies, including Server.HK, offer Apache as part of their hosting packages. However, setting up Apache to work with multiple PHP versions can be a daunting task for beginners. In this article, we’ll walk you through the process step by step, with relevant examples and code samples to help you along the way.

Why Use Multiple PHP Versions?

Before we dive into the setup process, let’s first discuss why you might want to use multiple PHP versions on your Hong Kong VPS. Different web applications may require different PHP versions to function correctly. For example, an older application may only be compatible with PHP 5.6, while a newer application may require PHP 7.4. By setting up Apache to work with multiple PHP versions, you can host multiple applications on the same server without any compatibility issues.

Step 1: Install Apache

The first step is to install Apache on your VPS. You can do this using the following command:

sudo apt-get install apache2

Once Apache is installed, you can start the server using the following command:

sudo service apache2 start

Step 2: Install Multiple PHP Versions

Next, you’ll need to install the PHP versions you want to use. You can do this using the following commands:

sudo apt-get install php5.6
sudo apt-get install php7.4

Once the PHP versions are installed, you can switch between them using the following commands:

sudo a2dismod php5.6
sudo a2enmod php7.4
sudo service apache2 restart

Step 3: Configure Apache for Multiple PHP Versions

Now that you have multiple PHP versions installed, you’ll need to configure Apache to use them. You can do this by creating separate virtual hosts for each PHP version. Here’s an example of a virtual host configuration for PHP 5.6:

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /var/www/html/example.com
    <FilesMatch .php$>
        SetHandler "proxy:unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost"
    </FilesMatch>
</VirtualHost>

And here’s an example of a virtual host configuration for PHP 7.4:

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /var/www/html/example.com
    <FilesMatch .php$>
        SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost"
    </FilesMatch>
</VirtualHost>

Once you have created the virtual host configurations, you can enable them using the following commands:

sudo a2ensite example.com-php5.6.conf
sudo a2ensite example.com-php7.4.conf
sudo service apache2 restart

Conclusion

Setting up Apache to work with multiple PHP versions can seem intimidating at first, but with the right guidance, it’s a straightforward process. By following the steps outlined in this article, you can easily configure your Hong Kong VPS Hosting to host multiple web applications with different PHP version requirements. Remember to always test your configurations before deploying them to a live environment, and don’t hesitate to reach out to the Server.HK support team if you need any assistance.

Recent Posts

  • Hong Kong VPS vs Singapore VPS: Which Is Better for Your Asia Business in 2026?
  • How to Migrate from CentOS 8 to AlmaLinux or Rocky Linux Safely
  • CentOS Server Performance Tuning: Optimization Techniques for 2026
  • How to Configure SELinux in CentOS Without Breaking Your System (CentOS Stream 9/10 – 2026)
  • Managing Users and Permissions in CentOS Stream: Best Practices (CentOS Stream 9/10 – 2026)

Recent Comments

No comments to show.

Knowledge Base

Access detailed guides, tutorials, and resources.

Live Chat

Get instant help 24/7 from our support team.

Send Ticket

Our team typically responds within 10 minutes.

logo
Alipay Cc-paypal Cc-stripe Cc-visa Cc-mastercard Bitcoin
Cloud VPS
  • Hong Kong VPS
  • US VPS
Dedicated Servers
  • Hong Kong Servers
  • US Servers
  • Singapore Servers
  • Japan Servers
More
  • Contact Us
  • Blog
  • Legal
© 2026 Server.HK | Hosting Limited, Hong Kong | Company Registration No. 77008912
Telegram
Telegram @ServerHKBot