業務用エアコン関連の技術情報、エラーコード、環境問題対策に関する別サイト「エアコンの安全な修理・適切なフロン回収」

CentOS7.9 : WEB Server Apache

1.Apache2 installation and virtual host setup

1.1 Apache2 Install

①Install httpd

# yum -y install httpd

Version Check
# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: May 10 2022 18:05:14

1.2 Apache Configuration

①Edit httpd.conf file
# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf_bak
# vi /etc/httpd/conf/httpd.conf
●Line 86 : Administrator address
ServerAdmin [Email Address]
●Per Line 95: Change ServerName
#ServerName www.example.com:80
ServerName domain name
●Line 144 : Change (Indexes removed)
Options FollowSymLinks
●Line 151 : Change
AllowOverride All
●Line 164 : File names accessible by directory name only
Add "index.php index.cgi index.htm"
●Add to last line
ServerTokens Prod
②If Firewalld is enabled, HTTP service permission is required; use [80/TCP] for HTTP and [443/TCP] for HTTPS
# firewall-cmd --add-service=http --permanent
# firewall-cmd --add-service=https --permanent
# firewall-cmd --reload
③Apache Auto-Start Configuration
# systemctl start httpd
# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
# 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 Fri 2023-02-17 12:21:28 JST; 33s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 2234 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           tq2234 /usr/sbin/httpd -DFOREGROUND
           tq2235 /usr/sbin/httpd -DFOREGROUND
           tq2236 /usr/sbin/httpd -DFOREGROUND
           tq2237 /usr/sbin/httpd -DFOREGROUND
           tq2238 /usr/sbin/httpd -DFOREGROUND
           tq2239 /usr/sbin/httpd -DFOREGROUND
           mq2240 /usr/sbin/httpd -DFOREGROUND

Feb 17 12:21:28 Lepard systemd[1]: Starting The Apache HTTP Se....
Feb 17 12:21:28 Lepard systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.

④operation check
If you access http://[server IP address] and the 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 the operation of apache.

Rename the welcome page

# mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.org
If you access http://[server IP address] and the Test Page is displayed as shown below, it is OK.

1.3 Virtual Host Settings

Assign and configure the domain name [cent.korodes.com] to the document root [/var/www/html/cent.korodes.com] directory for virtual host operation
Create a new /etc/httpd/conf.d/vhost.conf

# vi /etc/httpd/conf.d/vhost.conf
Description

<VirtualHost *:80>
DocumentRoot /var/www/html/cent.korodes.com
ServerName cent.korodes.com
ServerAdmin<Email Address>  ←Administrator Email Address
ErrorLog logs/cent.korodes.com-error_log
CustomLog logs/cent.korodes.com-access_log combined
</VirtualHost>
<Directory "/var/www/html/cent.korodes.com">
Options FollowSymLinks
AllowOverride All
</Directory>

Creating a Document Directory

# mkdir /var/www/html/cent.korodes.com

Restart Apache

# systemctl restart httpd

2. Confirmation of CGI Script Usage

①CGI availability check

②Create test scripts and check operation

# vi /var/www/cgi-bin/index.cgi

#!/usr/bin/python2
print("Content-type: text/html\n")
print("CGI Script Test Page")
# 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 Installation

①Install PHP7.4 (Remi repository)
# yum -y install --enablerepo=remi,remi-php74 php php-mbstring php-xml php-xmlrpc php-gd php-pdo php-pecl-mcrypt php-mysqlnd php-pecl-mysql

②Version Check

# php -v
PHP 7.4.33 (cli) (built: Feb 14 2023 09:31:03) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

③Restart Apache

# systemctl restart httpd

④Confirmation of PHP operation
Create the following file

If you access http://[domain name]/test.php in your browser and see the following screen, it is OK

4. 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.

4.1 Create password file for Digest authentication

Specify an authenticated area called realm. This realm is used to allow access to the same directory as authenticated.
In this example, the realm is "DigestAuth" and a user and password file named "secretuser" (".digestauth") is created. Execute the following command and enter the password for "secretuser" when prompted.

# /usr/bin/htdigest -c /etc/httpd/.digestauth "DigestAuth" secretuser
New password:
Re-type new password:

Confirmation

# cat /etc/httpd/.digestauth
secretuser:DigestAuth:64939177c7b7c6eac3687925b27e771d

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.)

# 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

# mkdir  /var/www/html/[FQDN]/secret

Enable Digest authentication and reboot

# systemctl restart httpd.service

When accessing http://[FQDN]/secret with a browser, a screen appears asking for "user name" and "password".
画像に alt 属性が指定されていません。ファイル名: 66216a549073fbbc5c6ff8d87bb8e569.jpg

Copied title and URL