Apache on Orange Pi Zero

Installing the Apache 2 web server

Apache2 is one of the world’s most widely used, robust and reliable web server applications. It runs perfectly on SBCs (Single-Board Computer) like the Orange Pi Zero.
To get started with an Orange Pi like the Orange Pi-Zero, see the following article: https://f1atb.fr/index.php/2020/08/06/getting-started-orange-pi-zero/

Once you get started, make sure you have an up-to-date configuration with:

apt-get update
apt-get upgrade

If you are not “root” add sudo in front of the commands.
Install Apache2:

apt install apache2 -y

Test the functioning of Apache by opening the web page at the IP address of your Orange PI

Default home page.
http://<adresse IP>
ex: http://192.168.0.100

By default, the website is located in the / var / www / html / folder and Apache returns the file / var / www / html / index.htm

You can now install your website pages in another folder like for example / home / xxxx / Html and configure the server accordingly in the default configuration file.

nano /etc/apache2/sites-available/000-default.conf
        ServerAdmin webmaster@localhost
        DocumentRoot /home/xxxx/Html
        ScriptAlias "/cgi-bin/" "/home/xxxx/Html/cgi-bin/"
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /home/xxxx/Html/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Require all granted
        </Directory>
        <Directory "/home/xxxx/Html/cgi-bin/">
                AllowOverride None
                Options +ExecCGI
                AddHandler cgi-script .cgi .pl .py
                Require all granted
        </Directory>

In the Html folder we have a cgi-bin sub-folder which will allow you to run scripts in python or perl. You have to tell Apache where this particular folder is located, which can be elsewhere so as not to simply return the script files but to start their execution locally.

SERVER TEST

In the Html folder, put a simple web page: index.html.

<!DOCTYPE html>
<html>
  <body>
  <h1>Test de mon site</h1>
  </body>
</html>

Restart the Apache2 server:

service apache2 restart

Call up the page from a browser

http://<adresse IP>

DYNAMIC SCRIPTS TEST

CGI (Common Gateway Interface) defines a method of interaction between a web server and external content-generating programs, more often referred to as CGI programs or CGI scripts. This is an easy way to add dynamic content to your website using your favorite programming language like perl or python. Here only in the cgi-bin folder, the programs will be executable as defined by the ScriptAlias directive of the Apache configuration file.

In the cgi-bin folder, put a small python ‘test.py’ file to test its execution.

#!/usr/bin/python3

print("Content-type:text/html\n\n")
print("hello")

Call up the page from a browser

http://<adresse IP>/cgi-bin/test.py

If the program runs, it’s good. If you get the code listing back, the cgid.load module may not be loaded by Apache. Check the / etc / apache2 / mods-enabled folder to see if the cgid.load file is present. If not, it’s available in mods-available. Then enable it with the command:

 a2enmod cgid

Leave a Reply

Your email address will not be published. Required fields are marked *