Contents
Apache2 installation and virtual host configuration
1.Apache2 Install
①httpd Install
1 |
# dnf -y install httpd |
Version Check
1 2 3 |
# httpd -v Server version: Apache/2.4.57 (Fedora Linux) Server built: Apr 11 2023 00:00:00 |
2.Apache Configuration
①Edit httpd.conf file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf_bak # vi /etc/httpd/conf/httpd.conf #Line 91 : Specify administrator address ServerAdmin [Email Address] #Per line 100: Change ServerName #ServerName www.example.com:80 ServerName [Domain name] #Line 149 : Change (Indexes are deleted) Options FollowSymLinks #Line 156 : Change AllowOverride All #Line 169 : File names accessible by directory name only Add "index.php index.cgi index.htm" #Add to the last line ServerTokens Prod |
②If Firewalld is enabled, HTTP service permission is required; use [80/TCP] for HTTP
1 2 |
# firewall-cmd --add-service=http --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 22 23 24 25 |
# systemctl start httpd # systemctl enable httpd # systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; preset: disabled) Drop-In: /usr/lib/systemd/system/service.d mq10-timeout-abort.conf Active: active (running) since Tue 2023-04-25 08:49:28 JST; 25s ago Docs: man:httpd.service(8) Main PID: 1198 (httpd) Status: "Total requests: 0; Idle/Busy workers 100/0;Requests/sec: 0; Bytes served/sec: 0 B/sec" Tasks: 177 (limit: 2253) Memory: 14.2M CPU: 77ms CGroup: /system.slice/httpd.service tq1198 /usr/sbin/httpd -DFOREGROUND tq1199 /usr/sbin/httpd -DFOREGROUND tq1200 /usr/sbin/httpd -DFOREGROUND tq1232 /usr/sbin/httpd -DFOREGROUND mq1245 /usr/sbin/httpd -DFOREGROUND Apr 25 08:49:28 Lepard systemd[1]: Starting httpd.service - The Apache HTTP Server... Apr 25 08:49:28 Lepard httpd[1198]: Server configured, listening on: port 80 Apr 25 08:49:28 Lepard systemd[1]: Started httpd.service - The Apache HTTP Server. |
④operation check
If you access http://[server IP address] and the Fedora Webserver Test Page is displayed as shown below, it is OK.
⑤Hide the Welcome page, create a new index.html file as a Test Page, and check apache operation
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 9 |
# 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://[server IP address]" and the Test Page is displayed as shown below, it is OK.
3.Virtual Host Settings
Assign and configure the [FQDN] to be operated on the virtual host in the document root [/var/www/html/FQDN] directory
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# vi /etc/httpd/conf.d/vhost.conf <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> |
Apache restart
1 |
# systemctl restart httpd |
Ensure CGI Script Usage
①Confirmation of CGI availability
1 2 3 |
# grep -n "^ *ScriptAlias" /etc/httpd/conf/httpd.conf 252: ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" The above is displayed and available under "/var/www/cgi-bin/". |
②Create test scripts and check operation
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") |
1 |
# chmod 755 /var/www/cgi-bin/index.cgi |
1 2 |
# curl localhost/cgi-bin/index.cgi CGI Script Test Page |
PHP installation and configuration
1.PHP Install
①Install
1 |
# dnf -y install php php-mbstring php-pear |
②Apache restatrt
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 20 21 22 23 |
# systemctl restart httpd # systemctl status php-fpm ● php-fpm.service - The PHP FastCGI Process Manager Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; preset: disabled) Drop-In: /usr/lib/systemd/system/service.d mq10-timeout-abort.conf Active: active (running) since Tue 2023-04-25 08:57:15 JST; 10s ago Main PID: 1968 (php-fpm) Status: "Ready to handle connections" Tasks: 6 (limit: 2253) Memory: 10.8M CPU: 43ms CGroup: /system.slice/php-fpm.service tq1968 "php-fpm: master process (/etc/php-fpm.conf)" tq1969 "php-fpm: pool www" tq1970 "php-fpm: pool www" tq1971 "php-fpm: pool www" tq1972 "php-fpm: pool www" mq1973 "php-fpm: pool www" Apr 25 08:57:15 Lepard systemd[1]: Starting php-fpm.service - The PHP FastCGI Process Manager... Apr 25 08:57:15 Lepard systemd[1]: Started php-fpm.service - The PHP FastCGI Process Manager. |
③Confirmation of PHP operation
Create the following file
1 2 |
# vi /var/www/html/<FQDN>/test.php <?php phpinfo(); ?> |
Access http://[FQDN]/test.php and if the following screen appears, OK
Digest authentication in Apache2
Since Basic Authentication, a well-known authentication authentication method for http, transmits 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 the authentication information and sends it in encrypted form, so there is almost no risk of information leakage.
1. Create password file for Digest authentication
Specify an authenticated area called realm. This realm allows the same directory to be accessed as authenticated.
As an example, we will create a user named "secretuser" and a password file ".digestauth" with "DigestAuth" as the realm. Execute the following command and enter the password for "secretuser" when prompted.
1 2 3 4 |
# /usr/bin/htdigest -c /etc/httpd/.digestauth "DigestAuth" secretuser Adding password for secretuser in realm DigestAuth. New password: Re-type new password: |
Confirmation
1 2 |
# cat /etc/httpd/.digestauth secretuser:DigestAuth:a1c671xxxxxxx306092bbd0fa2156268 |
As above, secretuser and encrypted password are created
2. Edit Apache configuration file
Specify the directory to which Digest authentication will be applied. (In this case, specify the secret directory.)
1 |
# vi /etc/httpd/conf/httpd.conf |
Add the following at the end
1 2 3 4 5 6 7 |
<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".