Contents
1. Apache2 installation and virtual host configuration
1.1 Apache2 Installation
①Install httpd
1 2 3 4 5 6 |
# pacman -S apache Version Check # httpd -v Server version: Apache/2.4.58 (Unix) Server built: Oct 25 2023 18:28:29 |
1.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 # vim /etc/httpd/conf/httpd.conf ●Line 223 : Administrator address specification ServerAdmin [Email Address] ●Per Line 234 : Add ServerName #ServerName www.example.com:80 ServerName [domain name] ●Line 271 : Change (Indexes removed) Options FollowSymLinks ●Line 278 : change AllowOverride All ●Line 291 : Add file names accessible only by directory name DirectoryIndex index.html index.php index.cgi ●Add to the last line ServerTokens Prod |
②If firewall is enabled, HTTP service must be allowed; HTTP uses [80/TCP].
1 2 |
# ufw allow http # ufw reload |
③Apache Autostart Configuration
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# systemctl start httpd # systemctl enable httpd # systemctl status httpd ● httpd.service - Apache Web Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; preset: di> Active: active (running) since Thu 2023-12-21 14:24:42 JST; 12s ago Main PID: 2993 (httpd) Tasks: 82 (limit: 4631) Memory: 18.3M (peak: 18.7M) CPU: 27ms CGroup: /system.slice/httpd.service 2993 /usr/bin/httpd -k start -DFOREGROUND 2994 /usr/bin/httpd -k start -DFOREGROUND 2995 /usr/bin/httpd -k start -DFOREGROUND 2996 /usr/bin/httpd -k start -DFOREGROUND Dec 21 14:24:42 Lepard systemd[1]: Started Apache Web Server. |
④operation check
Create a new index.html file as a Test Page and check apache operation
1 2 3 4 5 6 7 8 |
# vim /srv/http/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 be operated on the virtual host in the document root [/srv/[FQDN]] directory
1 2 |
# mkdir /srv/[FQDN] # mkdir /etc/httpd/conf/vhosts |
Virtual Host Configuration File Creation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# vim /etc/httpd/conf/vhosts/[FQDN] #Virtual Host Domain Settings <VirtualHost *:80> ServerAdmin <Email Address> ←Administrator's email address DocumentRoot "/srv/[FQDN]" ServerName [FQDN] ErrorLog "/var/log/httpd/[FQDN]-error_log" CustomLog "/var/log/httpd/[FQDN]-access_log" common <Directory "/srv/[FQDN]"> Options FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost> |
Setting permissions for document directories
1 |
# chmod o+x /srv/[FQDN] |
Include the following virtual host configuration file at the end of httpd.conf
1 2 3 4 |
# vim /etc/httpd/conf/httpd.conf Add to last line Include conf/vhosts/[FQDN] |
Restart Apache
1 |
# systemctl restart httpd |
2. Confirmation of CGI Script Usage
①CGI availability check
1 2 3 |
# grep -n "^ *ScriptAlias" /etc/httpd/conf/httpd.conf 373: ScriptAlias /cgi-bin/ "/srv/http/cgi-bin/" The above is displayed and available under "/srv/http/cgi-bin/". |
➁Edit /etc/httpd/conf/httpd.conf file
1 2 3 4 5 6 7 8 9 10 |
# vim /etc/httpd/conf/httpd.conf Line 175 : Uncomment LoadModule cgid_module modules/mod_cgid.so Line 178 : Uncomment LoadModule cgi_module modules/mod_cgi.so Line 391 : change Options None → Options ExecCGI |
1 |
# systemctl restart httpd |
➂Create test scripts and check operation
1 2 3 4 5 6 7 |
# mkdir /srv/http/cgi-bin/ # vim /srv/http/cgi-bin/index.cgi #!/usr/bin/python3 print("Content-type: text/html\n") print("CGI Script Test Page") |
1 2 3 |
# chmod 755 /srv/http/cgi-bin/index.cgi # curl localhost/cgi-bin/index.cgi CGI Script Test Page |
3. PHP installation and configuration
3.1 PHP8 installation
①Install
1 |
# pacman -S php php-apache php-fpm |
②Version Check
1 2 3 4 |
# php -v PHP 8.2.14 (cli) (built: Dec 21 2023 14:02:51) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.14, Copyright (c) Zend Technologies |
Configuration of PHP main unit
1 2 3 4 5 6 7 8 9 10 |
# vim /etc/php/php.ini Line 703 : change post_max_size = 300M Line 855 : change upload_max_filesize = 200M Line 965 : Uncommented and added date.timezone = Asia/Tokyo |
Configure php-fpm
1 2 |
# systemctl enable php-fpm Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service. |
1 |
# systemctl start php-fpm |
➂Edit Apache configuration file and set up to use PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# vim /etc/httpd/conf/httpd.conf Line 66 : comment-out #LoadModule mpm_event_module modules/mod_mpm_event.so Line 67 : Uncomment LoadModule mpm_prefork_module modules/mod_mpm_prefork.so Line 185-186 : add LoadModule php_module modules/libphp.so AddHandler php-script php Add to last line Include conf/extra/php_module.conf |
③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 |
# 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; preset: disabled) Active: active (running) since Sat 2023-12-16 16:32:38 JST; 1min 19s ago Main PID: 5877 (php-fpm) Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec" Tasks: 3 (limit: 4631) Memory: 11.6M (peak: 11.8M) CPU: 257ms CGroup: /system.slice/php-fpm.service tq5877 "php-fpm: master process (/etc/php/php-fpm.conf)" tq5878 "php-fpm: pool www" mq5879 "php-fpm: pool www" Dec 16 16:32:38 Lepard systemd[1]: Starting The PHP FastCGI Process Manager... |
④Confirmation of PHP operation
Create the following file
1 2 |
# vim /srv/[FQDN]/test.php <?php phpinfo(); ?> |
Access "http://[FQDN]/test.php" in your browser and if you see the following screen, it is OK