[LINUX] Install Apache 2.4 on Ubuntu 19.10 Eoan Ermine and run CGI


--Install apache2 package on Ubuntu --Enable mod_cgid with the a2enmod command --Install CGI script --Enable the setting with the a2ensite command

Apache 2 installation

Install the apache2 package.

$ sudo apt install apache2

Check the version.

$ /usr/sbin/apachectl -V
Server version: Apache/2.4.41 (Ubuntu)
Server built:   2019-08-14T14:36:32
Server's Module Magic Number: 20120211:88
Server loaded:  APR 1.6.5, APR-UTIL 1.6.1
Compiled using: APR 1.6.5, APR-UTIL 1.6.1
Architecture:   64-bit
Server MPM:     event
  threaded:     yes (fixed thread count)
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D HTTPD_ROOT="/etc/apache2"
 -D SUEXEC_BIN="/usr/lib/apache2/suexec"
 -D DEFAULT_PIDLOG="/var/run/apache2.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="mime.types"
 -D SERVER_CONFIG_FILE="apache2.conf"

Check that it is running by accessing it with curl etc.

$ curl -I http://localhost/
HTTP/1.1 200 OK
Date: Tue, 21 Jan 2020 10:47:37 GMT
Server: Apache/2.4.41 (Ubuntu)
Last-Modified: Tue, 21 Jan 2020 10:28:46 GMT
ETag: "2aa6-59ca3df7ac2c0"
Accept-Ranges: bytes
Content-Length: 10918
Vary: Accept-Encoding
Content-Type: text/html

Enable mod_cgid

Enable the cgid module with a2enmod cgi or a2enmod cgid.

$ sudo a2enmod cgi
Your MPM seems to be threaded. Selecting cgid instead of cgi.
Enabling module cgid.
To activate the new configuration, you need to run:
  systemctl restart apache2

mod \ _cgid -Apache HTTP Server Version 2 \ .4

On some Unix operating systems, forking a process from a multithreaded server can be a very costly operation. The reason is that the new process replicates all the threads of the parent process. To avoid this cost at each CGI startup, mod_cgid forks the child process to run an external daemon to run the CGI script. The primary server uses unix domain sockets to communicate with this daemon.

This module is used instead of mod_cgi whenever multithreaded MPM is chosen at compile time. At the user level, the settings and behavior of this module is exactly the same as mod_cgi. The only exception is the addition of the ScriptSock directive, which specifies the name of the socket for communicating with the CGI daemon.

Install CGI script

Create a / var / www / hello directory.

$ sudo mkdir /var/www/hello

Grant permissions to users who edit CGI script files.

$ sudo chown hoge:hoge /var/www/hello

Place the index.cgi file.

$ vim /var/www/hello/index.cgi

The contents of index.cgi. This time, it is CGI by shell script.

echo 'Status: 200 OK'
echo 'Content-Type: text/html;charset=utf-8'
echo ''
echo '<html><body>Hello, world.</body></html>'

Grant execute permission to index.cgi.

$ chmod 755 /var/www/hello/index.cgi

Install configuration file

Copy the 000-default.conf file located in the / etc / apache2 / sites-available directory to create a file called hello.conf.

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

Modify the contents of the hello.conf file.

$ sudo vim /etc/apache2/sites-available/hello.conf

Replace the hello.conf file with the following:


<VirtualHost *:80>

  # /etc/apache2/sites-available/000-default.Contents copied from conf
  ServerAdmin [email protected]
  DocumentRoot /var/www/html
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

  #Settings to run CGI
  ScriptAlias /hello/ /var/www/hello/
  <Directory "/var/www/hello/">
    Options ExecCGI
    AddHandler cgi-script .cgi
    DirectoryIndex index.cgi
    AllowOverride None
    Require all granted


Enable hello.conf and disable 000-default.conf

Currently 000-default is enabled.

$ ls -l /etc/apache2/sites-enabled/ | grep conf
lrwxrwxrwx 1 root root 35 January 21 19:28 000-default.conf -> ../sites-available/000-default.conf

Enable hello.conf with the a2ensite command.

$ sudo a2ensite hello
Enabling site hello.
To activate the new configuration, you need to run:
  systemctl reload apache2

Disable 000-default.conf with the a2dissite command.

$ sudo a2dissite 000-default
Site 000-default disabled.
To activate the new configuration, you need to run:
  systemctl reload apache2

You can see that hello.conf is enabled.

$ ls -l /etc/apache2/sites-enabled/ | grep conf
lrwxrwxrwx 1 root root 29 January 21 20:03 hello.conf -> ../sites-available/hello.conf

Restart Apache for the settings to take effect

$ sudo systemctl restart apache2

You can check that CGI is working with curl command etc.

$ curl -i http://localhost/hello/
HTTP/1.1 200 OK
Date: Tue, 21 Jan 2020 11:09:41 GMT
Server: Apache/2.4.41 (Ubuntu)
Content-Length: 40
Content-Type: text/html;charset=utf-8

<html><body>Hello, world.</body></html>

Reference material

Recommended Posts

Install Apache 2.4 on Ubuntu 19.10 Eoan Ermine and run CGI
Install Apache Tomcat 9 on Ubuntu 19.10 Eoan Ermine Hello World
Install and run dropbox on Ubuntu 20.04
Reverse proxy with Apache 2.4 on Ubuntu 19.10 Eoan Ermine
Install Mecab and mecab-python3 on Ubuntu 14.04
Install OpenCV and Chainer on Ubuntu
Install CUDA 8.0 and Chainer on Ubuntu 16.04
Install fabric on Ubuntu and try
Install Puppet Master and Client on Ubuntu 16.04
Install pyenv and Python 3.6.8 on Ubuntu 18.04 LTS
Install and run Python3.5 + NumPy + SciPy on Windows 10
How to update security on Ubuntu 19.10 Eoan Ermine
Install MongoDB on Ubuntu 16.04 and operate via python
Install TensorFlow on Ubuntu
Install PySide2 on Ubuntu
Install JModelica on Ubuntu
Install Python 3.3 on Ubuntu 12.04
Install Theano on Ubuntu 12.04
Install angr on Ubuntu 18.04
Install pip / pip3 on Ubuntu
Run the flask app on Cloud9 and Apache Httpd
Install Docker on Arch Linux and run it remotely
Run Jupyter on Ubuntu on Windows
Install GoLand IDE on Ubuntu
Install OpenCV on Ubuntu + python
wsl Install PostgreSQL on Ubuntu 18.04
[ROS] Install ROS (melodic) on Ubuntu (18.04)
Install Caffe on Ubuntu 14.04 (GPU)
Install Docker on WSL Ubuntu 18.04
Ubuntu 19.10 Eoan Ermine Japanese / Japanese locale environment and time zone settings
Install python3 and scientific calculation library on Ubuntu (virtualenv + pip)
Install CUDA10.1 + cuDNN7.6.5 + tensorflow-2.3.0 on Ubuntu 18.04
Install Caffe on Ubuntu 14.04 (CPU mode)
How to install OpenCV on Cloud9 and run it in Python
Install Python 3.8 on Ubuntu 20.04 (OS standard)
Install Ubuntu 18.04 on MacBook Pro Touchbar model and connect to WIFI
Build and install OpenCV on Windows
Run XGBoost on Bash on Ubuntu on Windows
Install Python 3.9 on Ubuntu 20.04 (OS standard?)
Install confluent-kafka for Python on Ubuntu
Install Python 2.7 on Ubuntu 20.04 (OS standard?)
How to install Go on Ubuntu
Run Yocto on Ubuntu using QEMU.
ROS study # 1 Install ros-noetic on ubuntu 20.04
Install easy_install and pip on windows
Until you install and run matplotlib
Until you install Apache and Tomcat on Linux (CentOS) and deploy Java apps
Steps to run Google Chrome headless on EC2 Ubuntu and take screenshots
Install ROS and ROS module for Roomba on RaspberryPi3 and try to run it
Install Python3 and Django on Amazon Linux (EC2) and run your web server
Build Python3 and OpenCV environment on Ubuntu 18.04
Python virtual environment and packages on Ubuntu
Steps to install Python environment on Ubuntu
Install and launch k3s on Manjaro Linux
Install and Configure TigerVNC server on Linux
Mount and format Disk on Ubuntu on GCP.
Run bootgen on Debian GNU / Linux, Ubuntu
Install Pleasant on Ubuntu 20.04 (.NetCore3.1 / PostgreSQL version)
Install ubuntu on 32bit UEFI Ultra Notebook
Install Caffe running 3D-CNN on clean Ubuntu 14.04