Contents
1. Install Web server Apache
1.1Install apache2
| 1 | # zypper -n install apache2 | 
1.2 Apache2 : Basic Configuration
| 1 2 3 4 5 6 7 8 | # vi /etc/sysconfig/apache2 # Line 152: Change to administrator address. APACHE_SERVERADMIN=<administrator E-mail> # Line 169: Change to own domain name APACHE_SERVERNAME="<domain name>" # Line 248: Change APACHE_SERVERTOKENS="Prod" | 
| 1 2 3 4 | # vi /etc/apache2/httpd.conf # Line 197: Set file names that can be accessed only by directory name DirectoryIndex index.html index.htm index.php | 
| 1 2 3 4 5 | # systemctl start apache2 # systemctl enable apache2 Created symlink /etc/systemd/system/httpd.service → /usr/lib/systemd/system/apache2.service. Created symlink /etc/systemd/system/apache.service → /usr/lib/systemd/system/apache2.service. Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service → /usr/lib/systemd/system/apache2.service. | 
1.3 Enable Firewalld
The HTTP service must be allowed. Note that HTTP uses 80/TCP; HTTPS uses 443.
| 1 2 3 4 5 6 | # firewall-cmd --add-service=http --permanent Success # firewall-cmd --add-service=https --permanent Success # firewall-cmd --reload success | 
1.4 Apache2 : operation check
Create an HTML test page to verify that it works.
Start a web browser on the client PC and access the test page you created as follows
| 1 2 3 4 5 6 7 8 9 | # vi /srv/www/htdocs/index.html <html> <body> <div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;"> Test Page </div> </body> </html> | 
Access http://<IP address> with a browser and confirm that the following message is displayed.

2. Apache2 : Use Perl scripts.
Configure Perl scripts to be used as CGI
2.1 Install Perl
①Install
| 1 | # zypper -n install perl | 
②Enable the CGI module.
| 1 | # a2enmod cgid | 
CGI execution is allowed under [/srv/www/cgi-bin/] by default.
よって、For example, by creating and deploying the script [/srv/www/cgi-bin/index.cgi], you can access [http://(httpd server)/cgi-bin/index.cgi]
Because this setting treats all files under [/srv/www/cgi-bin/] as CGI, non-CGI files cannot be displayed.
#The following configuration will allow CGI execution under /srv/www/cgi-bin/.
| 1 2 | # grep -n "^ *ScriptAlias" /etc/apache2/default-server.conf 72:ScriptAlias /cgi-bin/ "/srv/www/cgi-bin/" | 
| 1 | # systemctl restart apache2 | 
③Create a test script and check it works.
| 1 2 3 4 5 | # cat > /srv/www/cgi-bin/test_script <<'EOF' #!/usr/bin/perl print "Content-type: text/html\n\n"; print "Hello CGI\n"; EOF | 
Grant permissions to script files.
| 1 | # chmod 705 /srv/www/cgi-bin/test_script | 
operation check
| 1 2 | # curl http://localhost/cgi-bin/test_script Hello CGI | 
If you see the message "Hello CGI", it is normal.
3. Apache2 : Virtual Host Configuration
Configure both domains sample1.korodes.com sample2.korodes.com to be displayed on a single server
| 1 | # cd /srv/www/htdocs/ | 
Create a directory named sample1.korodes.com under /srv/www/htdocs/.
| 1 | # mkdir sample1.korodes.com | 
Create an idex.html file in the sample1.korodes.com directory
| 1 2 3 | # vi sample1.korodes.com/index.html +++++++++Virtual Host Site1 sample1.korodes.com ++++++++++ | 
Create a new virtual_host.conf file under /etc/apache2/vhosts.d
| 1 2 3 4 5 6 7 8 9 10 | # vi /etc/apache2/vhosts.d/virtual_host.conf <VirtualHost *:80> ServerName sample1.korodes.com ServerAdmin <Administrator email address> DocumentRoot /srv/www/htdocs/sample1.korodes.com ErrorLog /var/log/apache2/sample1.korodes.com.error.log CustomLog /var/log/apache2/sample1.korodes.com.access.log combined LogLevel warn </VirtualHost> | 
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #vi /etc/hosts # hosts         This file describes a number of hostname-to-address #               mappings for the TCP/IP subsystem.  It is mostly #               used at boot time, when no name servers are running. #               On small systems, this file can be used instead of a #               "named" name server. # Syntax: # # IP-Address  Full-Qualified-Hostname  Short-Hostname # 127.0.0.1       localhost # special IPv6 addresses ::1             localhost ipv6-localhost ipv6-loopback fe00::0         ipv6-localnet ff00::0         ipv6-mcastprefix ff02::1         ipv6-allnodes ff02::2         ipv6-allrouters ff02::3         ipv6-allhosts 192.168.11.83   sample1.korodes.com  ← Add | 
| 1 | # systemctl restart apache2 | 
| 1 2 | # cd /srv/www/htdocs # mkdir sample2.korodes.com | 
| 1 2 3 | # vi sample2.korodes.com/index.html *************Virtual Host Site2 sample2.korodes.com ********* | 
Add to virtual_host.conf file
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | # vi /etc/apache2/vhosts.d/virtual_host.conf <VirtualHost *:80> ServerName sample1.korodes.com ServerAdmin <Administrator email address> DocumentRoot /srv/www/htdocs/sample1.korodes.com ErrorLog /var/log/apache2/sample1.korodes.com.error.log CustomLog /var/log/apache2/sample1.korodes.com.access.log combined LogLevel warn </VirtualHost> # Add the following <VirtualHost *:80> ServerName sample2.korodes.com ServerAdmin <Administrator email address> DocumentRoot /srv/www/htdocs/sample2.korodes.com ErrorLog /var/log/apache2/sample2.korodes.com.error.log CustomLog /var/log/apache2/sample2.korodes.com.access.log combined LogLevel warn </VirtualHost> | 
Add to the hosts file
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #vi /etc/hosts # hosts         This file describes a number of hostname-to-address #               mappings for the TCP/IP subsystem.  It is mostly #               used at boot time, when no name servers are running. #               On small systems, this file can be used instead of a #               "named" name server. # Syntax: # # IP-Address  Full-Qualified-Hostname  Short-Hostname # 127.0.0.1       localhost # special IPv6 addresses ::1             localhost ipv6-localhost ipv6-loopback fe00::0         ipv6-localnet ff00::0         ipv6-mcastprefix ff02::1         ipv6-allnodes ff02::2         ipv6-allrouters ff02::3         ipv6-allhosts 192.168.11.83   sample1.korodes.com 192.168.11.83   sample2.korodes.com  ←Add | 
| 1 | # systemctl restart apache2 | 
It is OK if "http://sample1.korodes.com" and "http://sample2.korodes.com" appear in your web browser as shown below.

4. Apache2 : Use PHP scripts
Install PHP and configure it so that PHP scripts can be used
4.1 Install PHP
| 1 2 | # zypper -n install php7 php7-pear php7-mbstring apache2-mod_php7 # a2enmod php7 | 
| 1 2 3 4 | # vi /etc/php7/apache2/php.ini # Line 962: Time zone setting date.timezone = 'Asia/Tokyo' | 
| 1 | # systemctl restart apache2 | 
4.2 Create a PHP test page and check it works.
Create a test page
| 1 2 3 | # vi /srv/www/htdocs/sample1.korodes.com/test.php <?php phpinfo(); ?> | 
| 1 | # systemctl restart httpd.service | 
Start a Web browser on the client PC and access "http://sample1.korodes.com/test.php". If the test page you created is displayed as shown below, you are good to go.


 
  
  
  
  