Contents
1.Apache2 installation and virtual host configuration
1.1 Apache2
①httpd Install
1 |
# dnf -y install httpd |
Version Check
1 2 3 |
# httpd -v Server version: Apache/2.4.37 (Oracle Linux Server) Server built: Aug 13 2024 05:06:02 |
1.2 Apache Configuration
①Edit httpd.conf file
1 |
# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf_bak |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# vi /etc/httpd/conf/httpd.conf Line 89 : Specify administrator address ServerAdmin <mail address> Per Line 98 : add 「#ServerName www.example.com:80」 ServerName <domain name> Line 147 : Change (Indexes is deleted) Options FollowSymLinks Line 154 : Change AllowOverride All Line 167 : file name accessible only by directory name Add "index.php index.cgi " Add to the last line ServerTokens Prod |
②If Firewalld is enabled, HTTP service permission is required; HTTP uses [80/TCP],HTTPS uses[143/TCP]
1 2 3 |
# firewall-cmd --add-service=http --permanent # firewall-cmd --add-service=https --permanent # firewall-cmd --reload |
③Apache Auto-Start Configuration
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# systemctl start httpd # systemctl enable httpd # systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2024-10-14 09:50:42 JST; 18s ago Docs: man:httpd.service(8) Main PID: 7495 (httpd) Status: "Running, listening on: port 80" Tasks: 213 (limit: 16915) Memory: 26.5M CGroup: /system.slice/httpd.service ├─7495 /usr/sbin/httpd -DFOREGROUND ├─7496 /usr/sbin/httpd -DFOREGROUND ├─7497 /usr/sbin/httpd -DFOREGROUND ├─7498 /usr/sbin/httpd -DFOREGROUND └─7499 /usr/sbin/httpd -DFOREGROUND Oct 14 09:50:42 Lepard systemd[1]: Starting The Apache HTTP Server... Oct 14 09:50:42 Lepard systemd[1]: Started The Apache HTTP Server. Oct 14 09:50:42 Lepard httpd[7495]: Server configured, listening on: port 80 |
④operation check
If you access http://[server IP address] and you see the Oracle Apache2 Test Page as shown below, it is OK.
⑤Hide the Oracle Welcome page, create a new index.html file as a Test Page, and check the operation of apache.
Rename the welcome page
1 |
# mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.org |
Create HTML test page
1 2 3 4 5 6 7 8 |
# vi /var/www/html/index.html <html> <body> <div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;"> Apache Test Page </div> </body> </html> |
If you access http:// and the Test Page is displayed as shown below, it is OK.
1.3 Virtual Host Settings
Assign and configure the domain name [FQDN] to the document root [/var/www/html/FQDN] directory for virtual host operation
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# vi /etc/httpd/conf.d/vhost.conf Virtual Host Domain Settings <VirtualHost *:80> DocumentRoot /var/www/html/[FQDN] ServerName [FQDN] ServerAdmin <Email Address> ErrorLog logs/[FQDN].error_log CustomLog logs/[FQDN].access_log combined </VirtualHost> <Directory "/var/www/html/[FQDN]"> Options FollowSymLinks AllowOverride All </Directory> |
Creating a Document Directory
1 |
# mkdir /var/www/html/[FQDN] |
Restart Apache
1 |
# systemctl restart httpd |
2. Confirmation of CGI Script Usage
①Confirmation of CGI availability
1 2 3 |
# grep -n "^ *ScriptAlias" /etc/httpd/conf/httpd.conf 250:ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" The above is displayed and available under "/var/www/cgi-bin/". |
②Create test scripts and check operation
test scripts
1 2 3 4 5 |
# vi /var/www/cgi-bin/index.cgi #!/usr/bin/python3 print("Content-type: text/html\n") print("CGI Script Test Page") |
If "CGI Script Test Page" is displayed, it is OK.
1 2 3 |
# chmod 755 /var/www/cgi-bin/index.cgi # curl localhost/cgi-bin/index.cgi CGI Script Test Page |
3. PHP installation and configuration
1.PHP
①Install
1 |
# dnf -y install php php-mbstring php-pear |
②Version Check
1 2 3 4 |
# php -v PHP 7.2.24 (cli) (built: Oct 22 2019 08:28:36) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies |
Upgrade to Php 8.3
EPEL and Remi repositories are required, so install them if you have not already done so.
1 2 |
# dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm # dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm |
Stop PHP once
1 |
# dnf module disable php |
Installing PHP 8.3
1 |
# dnf module install php:remi-8.3 |
php-fpm configuration
1 |
# systemctl enable php-fpm |
③Restart Apache
After PHP installation, restarting Apache will invoke PHP-FPM (FPM : FastCGI Process Manager) by default, and php-fpm service will be started in conjunction with httpd startup.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# systemctl restart httpd # systemctl status php-fpm ● php-fpm.service - The PHP FastCGI Process Manager Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2024-10-14 10:02:45 JST; 7s ago Main PID: 10024 (php-fpm) Status: "Ready to handle connections" Tasks: 6 (limit: 16915) Memory: 15.5M CGroup: /system.slice/php-fpm.service ├─10024 php-fpm: master process (/etc/php-fpm.conf) ├─10025 php-fpm: pool www ├─10026 php-fpm: pool www ├─10027 php-fpm: pool www ├─10028 php-fpm: pool www └─10029 php-fpm: pool www Oct 14 10:02:45 Lepard systemd[1]: Starting The PHP FastCGI Process Manager... Oct 14 10:02:45 Lepard systemd[1]: Started The PHP FastCGI Process Manager. |
④Confirmation of PHP operation
Create the following file
1 2 3 4 5 |
# vi /var/www/html/[FQDN]/test.php <?php phpinfo(); ?> |
Access http://[FQDN]/test.php in your browser and if you see the following screen, it is OK
4. Digest authentication with Apache2
Since Basic Authentication, a well-known authentication authorization method for http, sends authentication information in plain text, there is a risk of ID and password leakage if the packet is intercepted.
On the other hand, Digest Authentication encrypts and transmits authentication information, so there is almost no risk of information leakage.
4.1 Create password file for Digest authentication
Specify an authenticated area called realm. This realm allows the same directory to be accessed as authenticated.
For this example, the realm is "DigestAuth" and a user and password file named "secretuser" ".digestauth" is created.
1 |
# /usr/bin/htdigest -c /etc/httpd/.digestauth "DigestAuth" secretuser |
Confirmation
1 2 |
# cat /etc/httpd/.digestauth secretuser:DigestAuth:xxxxxx77c7b7c6eacxxxxxxxxxxxxxxx |
As above, secretuser and encrypted password are created
4.2 Edit Apache configuration file
Specify the directory to which Digest authentication will be applied. (In this case, specify the "secret" directory.)
1 2 3 4 5 6 7 8 9 10 |
# vi /etc/httpd/conf/httpd.conf Add the following at the end <Directory "/var/www/html/[FQDN]/secret"> AuthType Digest AuthName "DigestAuth" AuthDigestDomain /secret/ AuthUserFile "/etc/httpd/.digestauth" Require valid-user </Directory> |
Create a directory for Digest authentication
1 |
# mkdir /var/www/html/[FQDN]/secret |
Enable Digest authentication and reboot
1 |
# systemctl restart httpd.service |
When accessing http://[FQDN]/secret with a browser, a screen appears asking for "user name" and "password".