• 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 with mod_cgi

December 17, 2023

Apache for Newbie: Set up Apache with mod_cgi

Apache is one of the most popular web servers in the world, known for its flexibility and robustness. If you are new to web hosting and want to set up Apache with mod_cgi, this article will guide you through the process step by step.

What is Apache?

Apache is an open-source web server software that powers millions of websites worldwide. It is known for its stability, security, and performance. Apache supports various modules that extend its functionality, and one such module is mod_cgi.

What is mod_cgi?

Mod_cgi is an Apache module that allows the server to execute CGI (Common Gateway Interface) scripts. CGI scripts are programs written in languages like Perl, Python, or Ruby, which generate dynamic content for web pages. With mod_cgi, Apache can process these scripts and deliver the output to the client’s browser.

Setting up Apache with mod_cgi

Before setting up Apache with mod_cgi, make sure you have a VPS hosting plan from Server.HK. They offer reliable and affordable Hong Kong VPS hosting services, perfect for hosting your website.

Here are the steps to set up Apache with mod_cgi:

Step 1: Install Apache

If you haven’t installed Apache yet, you can do so by following these commands:

$ sudo apt update
$ sudo apt install apache2

This will install Apache on your VPS.

Step 2: Enable mod_cgi

To enable mod_cgi, run the following command:

$ sudo a2enmod cgi

This command enables the mod_cgi module in Apache.

Step 3: Configure Apache

Next, you need to configure Apache to allow CGI scripts. Open the Apache configuration file using a text editor:

$ sudo nano /etc/apache2/sites-available/000-default.conf

Add the following lines inside the “ section:

ScriptAlias /cgi-bin/ /var/www/html/cgi-bin/
<Directory "/var/www/html/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Require all granted
</Directory>

Save the file and exit the text editor.

Step 4: Create a CGI script

Now, let’s create a simple CGI script to test if everything is working fine. Create a file named `hello.cgi` inside the `/var/www/html/cgi-bin/` directory:

$ sudo nano /var/www/html/cgi-bin/hello.cgi

Add the following code to the file:

#!/usr/bin/perl

print "Content-type: text/htmlnn";
print "Hello, CGI!";

Save the file and exit the text editor.

Step 5: Restart Apache

Finally, restart Apache to apply the changes:

$ sudo service apache2 restart

Now, if you visit `http://your-domain.com/cgi-bin/hello.cgi`, you should see the message “Hello, CGI!” displayed on the page.

Summary

In this article, we learned how to set up Apache with mod_cgi. We installed Apache, enabled mod_cgi, configured Apache to allow CGI scripts, created a simple CGI script, and tested it. Apache with mod_cgi allows you to run dynamic CGI scripts on your website, enhancing its functionality. If you are looking for reliable VPS hosting services, consider Server.HK, a leading provider of Hong Kong VPS hosting.

For more information about Hong Kong VPS hosting, visit https://server.hk.

Recent Posts

  • How to Run a SaaS Product on Hong Kong VPS: Architecture and Deployment Guide 2026
  • Hong Kong VPS Uptime and SLA: What 99.9% Uptime Really Means for Your Business (2026)
  • Cryptocurrency and USDT Payment for VPS Hosting: Why It Matters for Global Businesses (2026)
  • How to Speed Up Your Website for China: A Technical Optimization Guide 2026
  • Hong Kong VPS Windows Server: How to Set Up and Use a Windows VPS in Asia (2026)

Recent Comments

  1. Hong Kong VPS Uptime and SLA: What 99.9% Uptime Really Means for Your Business (2026) - Server.HK on How to Monitor Your Hong Kong VPS: Uptime, Performance, and Alert Setup Guide (2026)
  2. Best Hong Kong VPS Providers in 2026: Compared by Speed, Routing, and Value - Server.HK on How to Migrate Your Website to a Hong Kong VPS: Zero-Downtime Transfer Guide (2026)
  3. vibramycin injection on How to Choose the Right Hong Kong VPS Plan: A Buyer’s Guide for 2026
  4. allopurinol for gout on CN2 GIA vs BGP vs CN2 GT: What’s the Real Difference for China Connectivity?
  5. antibiotics online purchase on How to Set Up a WordPress Site on a Hong Kong VPS with aaPanel (Step-by-Step 2026)

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