Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Server \ Ubuntu 15.10 under Python + Apache + CGI fully configured     - Get and Post requests Comments (Linux)

- CentOS 6.7 install Nagios Tutorials (Server)

- RedHat Linux 6.4 install Oracle 10g error (Database)

- Python implementation Bursa transition model (Programming)

- Oracle 11g maintenance partitions (eight) - Renaming Partitions (Database)

- Java semaphores (Programming)

- C ++ implementation of the list of basic operations and test cases (Programming)

- Hadoop connection failed or stuck processing (Server)

- Cool Android realization SVG animation (Programming)

- Close Pycharm spell check (Programming)

- Zabbix monitoring platform to extract a single server graphical Python implementation of concurrent (Server)

- Installation of Theano + CUDA under Ubuntu (Linux)

- Comparison of sorting algorithms (Programming)

- Apache Linux firewall reverse proxy configuration (Linux)

- MySQL / MariaDB database master-slave replication (Database)

- Ubuntu 14.04 Solution login interface infinite loop (Linux)

- Linux system commands to view hardware information (Linux)

- MySQL primary and secondary replicate data inconsistencies (Database)

- Transfer MySQL database to MariaDB (Database)

- Linux file system structure Introduction (Linux)

  Ubuntu 15.10 under Python + Apache + CGI fully configured
  Add Date : 2018-11-21      
  Operating system environments: Ubuntu 15.10

0. demand reasons

    I want to set up a Linux Apache to run CGI programs, to facilitate future deployment of Python Web applications with Apache, but encountered a variety of problems, the Internet to find answers or are too old (4/5 years ago with now It has been a lot worse), or it does not complete, so summarize here, as the latest version of it.

1.Apache installation

    The source code is compiled and installed using the form. First to note is that to successfully install Apache, in turn requires installing the following software (libraries) are considered successful installation of Apache:

(1) apr installation

Download: http: //apr.apache.org/

Note that on this site there are two respective software download, one apr, the other is to be installed below the apr-util, because the English name looks too confusing, so be sure to look at what is downloaded. I downloaded here: apr-1.5.2.tar.gz

Step one: Unpack

xpleaf @ leaf: ~ / Downloads $ tar xvf apr-1.5.2.tar.gz
apr-1.5.2 / mmap / win32 /
apr-1.5.2 / mmap / win32 / mmap.c
apr-1.5.2 / apr-config.in
Step 2: Run configure to detect and set the compiler options

xpleaf @ leaf: ~ / Downloads /apr-1.5.2$ ./configure
config.status: creating include / arch / unix / apr_private.h
config.status: executing libtool commands
rm: can not remove 'libtoolT': No such file or directory
config.status: executing default commands
    Under normal circumstances, there is no problem, if there is a problem, you can find yourself, this a good solution.

The third step: to compile and install

xpleaf @ leaf: ~ / Downloads /apr-1.5.2$ make
xpleaf @ leaf: ~ / Downloads /apr-1.5.2$ sudo make install
    OK, so, apr installation is complete.

(2) apr-util Installation

    Download is the same as with the above, here I downloaded version is: apr-util-1.5.4.tar.gz

    apr-util step of the installation with the above almost, but there is a step to note is that when executing ./configure command apr need to specify the installation directory:

xpleaf @ leaf: ~ / Downloads /apr-util-1.5.4$ ./configure
checking whether gcc accepts -g ... yes
checking for gcc option to accept ISO C89 ... none needed
Applying apr-util hints file rules for x86_64-unknown-linux-gnu
checking for APR ... no
configure: error:. APR could not be located Please use the --with-apr option.
# Note the above given tips
    First find apr installation directory:

xpleaf @ leaf: ~ / Downloads /apr-util-1.5.4$ whereis apr
apr: / usr / local / apr
    Then add the appropriate parameters to perform the apr-util ./configure command:

xpleaf @ leaf: ~ / Downloads /apr-util-1.5.4$ ./configure --with-apr = / usr / local / apr
config.status: creating test / Makefile
config.status: creating include / private / apu_config.h
config.status: executing default commands
    In this case precompiled even completed, then perform the following make and sudo make install:

xpleaf @ leaf: ~ / Downloads /apr-util-1.5.4$ make
xpleaf @ leaf: ~ / Downloads /apr-util-1.5.4$ sudo make install
    OK, so, apr-util installation is done.

(3) pcre installed

    This is not necessary, provided that you have the original system installed in its library, if it is not already installed, when you compile Apache will appear the following error message:

configure: error:. pcre-config for libpcre not found PCRE is required and from available http://pcre.org/

    So if you have such a situation occurs, please download and install pcre.

    Download: http: //sourceforge.net/projects/pcre/files/pcre/

    I downloaded version is here: pcre-8.38.tar.gz

    With the installation steps as above, but there will not be any problems, given directly to Step Well:

xpleaf @ leaf: ~ / Downloads $ tar zxvf pcre-8.38.tar.gz
xpleaf @ leaf: ~ / Downloads /pcre-8.38$ ./configure
xpleaf @ leaf: ~ / Downloads /pcre-8.38$ make
xpleaf @ leaf: ~ / Downloads /pcre-8.38$ sudo make install

    pcre also after installation, the following can actually install the Apache.

(4) Apache installation

    After the above three software installation is complete, which began following the installation Apache.

    Download: http: //httpd.apache.org/download.cgi

    I downloaded version is: httpd-2.4.18.tar.gz

a. Installation

    Just completed the above steps, it is easier to install apache, in turn execute the following command on it.

xpleaf @ leaf: ~ / Downloads $ tar zxvf httpd-2.4.18.tar.gz
xpleaf @ leaf: ~ / Downloads /httpd-2.4.18$ ./configure --enable-module = shared
xpleaf @ leaf: ~ / Downloads /httpd-2.4.18$ make
xpleaf @ leaf: ~ / Downloads /httpd-2.4.18$ sudo make install

b. Parameter Description

     Note that if you do not specify apache installation directory when executing ./configure, default is installed in / usr / local / apache2, you can view its installation directory in the following way:

xpleaf @ leaf: ~ $ whereis apache2
apache2: / usr / local / apache2
    In addition, in the implementation of the above adds ./configure -enable-module = shared parameters, namely through the module is compiled into a dynamic shared object, allows the dynamic loading when Apache starts, so that later need to load a new module, just in the configuration file settings. Of course, for such convenience and performance is worth the loss of certain individual measure. So you do not add this parameter is no problem.

c. can not start solution

    After installation is complete, you can start, because the compiler is used in the installation, it is necessary to start with the following way:

xpleaf @ leaf: ~ $ sudo / usr / local / apache2 / bin / apachectl start
/ Usr / local / apache2 / bin / httpd: error while loading shared libraries: libpcre.so.1: can not open shared object file: No such file or directory
    But you will find another error, and it is reported error: Unable to Canadian dollars libpcre.so.1 library functions.

    libpcre.so.1, very familiar names, front not already installed? Indeed installed, but Apache does not find it just, look:

xpleaf @ leaf: ~ $ ldd / usr / local / apache2 / bin / httpd
    linux-vdso.so.1 => (0x00007ffdf9fe6000)
    libpcre.so.1 => not found
    libaprutil-1.so.0 => /usr/local/apr/lib/libaprutil-1.so.0 (0x00007f8192a47000)
    libapr-1.so.0 => /usr/local/apr/lib/libapr-1.so.0 (0x00007f8192813000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f81925f5000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f819222b000)
    libexpat.so.0 => /usr/local/apr/lib/libexpat.so.0 (0x00007f8192002000)
    libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007f8191dca000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f8191bc6000)
    /lib64/ld-linux-x86-64.so.2 (0x00005637a587b000)
    Then we pcre library functions corresponding to the software linked to the / lib directory on it:

xpleaf @ leaf: ~ $ sudo ln -s /usr/local/lib/libpcre.so.1 / lib
    Here then start to try:

xpleaf @ leaf: ~ $ sudo / usr / local / apache2 / bin / apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using Set the 'ServerName' directive globally to suppress this message.
    OK, next time you open the browser, the classic "It works" show out:


    In this case, Apache installation can be considered complete, Here to talk about CGI configuration.

2.CGI Configuration

    Apache supports CGI configuration, the following described in detail the configuration process.

    Find the Apache installation directory / usr / local / apache2 / conf, httpd.conf configuration file and make changes, such as the following description:

(1) loading cgi module
    Probably in httpd.conf 137 line:

#LoadModule Cgid_module modules / mod_cgid.so

LoadModule cgid_module modules / mod_cgid.so

(2) set the cgi script file path
    Probably in httpd.conf 329 line:

ScriptAlias ​​/ cgi-bin / "/ usr / local / apache2 / cgi-bin /"
    Apache can see the "/ usr / local / apache2 / cgi-bin /" is mapped to / cgi-bin /, that is, when you access / cgi-bin / directory via the browser, in fact, is to visit the "/ usr / local / apache2 / cgi-bin / "directory, for convenience, I set it as follows:

ScriptAlias ​​/ cgi-bin / / home / xpleaf / Source_Code / cgi_for_py /
    Note that this path must be added at the end of / apache is otherwise unable to hit the file path under.

Access (3) set the path cgi
    Probably httpd.conf195 line:

    AllowOverride none
    Require all denied

    The entire contents of the above modifications to the following:

   AllowOverride None
   Options + ExecCGI
   Order allow, deny
   Allow from all

    Note that the directory is changed to the front of our reform: / home / xpleaf / Source_Code / cgi_for_py /

    Such modifications are for a reason, if not set permissions here, when you visit your cgi script files in your browser, you may get a prompt like this:

You do not have permission to access /cgi-bin/hello.py on this server.

(4) set apache explain the python cgi script files
    Probably in httpd.conf 386 line:

#AddHandler Cgi-script .cgi
    Remove comment, change it to:

AddHandler cgi-script .cgi .py
    Plus .py, you can explain python script file, if you need to explain shell script file, you can add .pl, other similar.

    OK, after you complete step 4 above, CGI configuration is complete. However, after the configuration is complete, we need to restart the Apache service:

xpleaf @ leaf: / usr / local / apache2 / conf $ sudo / usr / local / apache2 / bin / apachectl restart
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using Set the 'ServerName' directive globally to suppress this message.
3. Add the CGI script file

(1) Create a cgi script file

    Add the following to a file in / home / xpleaf / Source_Code / cgi_for_py / directory and named hello.py: