• 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 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)
  • How to Set Up Nginx on CentOS Stream for High-Performance Web Hosting

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