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.59 (Unix) Server built: Apr 10 2024 00:40:47 |
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: disabled) Active: active (running) since Wed 2024-05-08 08:58:45 JST; 13s ago Main PID: 1782 (httpd) Tasks: 82 (limit: 4630) Memory: 6.6M (peak: 7.4M) CPU: 27ms CGroup: /system.slice/httpd.service tq1782 /usr/bin/httpd -k start -DFOREGROUND tq1784 /usr/bin/httpd -k start -DFOREGROUND tq1785 /usr/bin/httpd -k start -DFOREGROUND mq1786 /usr/bin/httpd -k start -DFOREGROUND May 08 08:58:45 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://[server IP] 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.3.6 (cli) (built: Apr 12 2024 12:24:08) (NTS) Copyright (c) The PHP Group Zend Engine v4.3.6, 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 713 : change post_max_size = 300M Line 865 : change upload_max_filesize = 200M Line 975 : 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 17 18 19 20 |
# 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 Wed 2024-05-08 09:25:59 JST; 2min 30s ago Main PID: 2255 (php-fpm) Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec" Tasks: 3 (limit: 4630) Memory: 21.8M (peak: 22.0M) CPU: 53ms CGroup: /system.slice/php-fpm.service tq2255 "php-fpm: master process (/etc/php/php-fpm.conf)" tq2256 "php-fpm: pool www" mq2257 "php-fpm: pool www" May 08 09:25:59 Lepard systemd[1]: Starting The PHP FastCGI Process Manager... May 08 09:25:59 Lepard php-fpm[2255]: [NOTICE] fpm is running, pid 2255 May 08 09:25:59 Lepard php-fpm[2255]: [NOTICE] ready to handle connections May 08 09:25:59 Lepard php-fpm[2255]: [NOTICE] systemd monitor interval set to 10000ms May 08 09:25:59 Lepard systemd[1]: Started 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