Contents
1.Apache2 Install , Virtual Host Configuration
1.1 Apache2 Install
①httpd Install
1 2 3 4 5 6 |
# dnf -y install httpd Version Check # httpd -v Server version: Apache/2.4.37 (MIRACLE LINUX) Server built: Sep 21 2023 02:25:30 |
1.2 Apache Configuration
①Edit httpd.conf file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf_bak # vi /etc/httpd/conf/httpd.conf Line 89 : Administrator address specification ServerAdmin [Email Address] Per Line 99 : Change ServerName Add "ServerName <domain name>" under "#ServerName www.example.com:80" Line 147 : Change (Delete Indexes) Options FollowSymLinks Line 154 : Change AllowOverride All Line 167 : 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/HTTPS service permission is required; HTTP uses [80/TCP][443/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 Sat 2023-10-14 10:27:21 JST; 47s ago Docs: man:httpd.service(8) Main PID: 7793 (httpd) Status: "Running, listening on: port 80" Tasks: 213 (limit: 10869) Memory: 53.4M CGroup: /system.slice/httpd.service tq7793 /usr/sbin/httpd -DFOREGROUND tq7794 /usr/sbin/httpd -DFOREGROUND tq7795 /usr/sbin/httpd -DFOREGROUND tq7796 /usr/sbin/httpd -DFOREGROUND mq7797 /usr/sbin/httpd -DFOREGROUND Oct 14 10:27:21 localhost.localdomain systemd[1]: Starting The Apache HTTP Server... Oct 14 10:27:21 localhost.localdomain systemd[1]: Started The Apache HTTP Server. Oct 14 10:27:21 localhost.localdomain httpd[7793]: Server configured, listening on: port 80 |
④operation check
If you access http://[server IP address] and see the MiracleLinux Test Page 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 |
1 2 3 4 5 6 7 8 9 |
Create HTML test page # 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.
1.3 Virtual Host Settings
Assign and configure the domain name [miracle.korodes.com] to the document root [/var/www/html/miracle.korodes.com] directory for virtual host operation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# vi /etc/httpd/conf.d/vhost.conf #Virtual Host Domain Settings <VirtualHost *:80> DocumentRoot /var/www/html/miracle.korodes.com ServerName miracle.korodes.com ServerAdmin [Email Address] ←Administrator's email address ErrorLog logs/miracle.korodes.com-error_log CustomLog logs/miracle.korodes.com-access_log combined </VirtualHost> <Directory "/var/www/html/miracle.korodes.com"> Options FollowSymLinks AllowOverride All </Directory> |
Creating a Document Directory
1 |
# mkdir /var/www/html/miracle.korodes.com |
Apache Restart
1 |
# systemctl restart httpd |
Create test pages and check operation
1 2 3 4 5 6 7 8 |
# vi /var/www/html/miracle.korodes.com/index.html <html> <body> <div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;"> Virtual Host Test Page </div> </body> </html> |
Access."http://miracle.korodes.com/index.html"
If the following screen appears, it is normal.
2. Use of CGI Scripts
①CGI availability check
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
1 2 3 4 5 |
# vi /var/www/cgi-bin/index.cgi #!/usr/libexec/platform-python print("Content-type: text/html\n") print("CGI Script Test Page") |
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
3.1.PHP Install
①Install
1 |
# dnf -y install php |
②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 |
If you are on Php 7.2, upgrade to Php 8.2.
If you are installing Php8.2, you will need the Remi repository, so install it if you have not already done so.
1 |
# dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm |
Stop PHP once
1 |
# dnf module disable php |
PHP 8.2 Install
1 |
# dnf module install php:remi-8.2 |
php-fpm configuration
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 2 3 4 5 6 |
# systemctl start php-fpm # php -v PHP 8.2.11 (cli) (built: Sep 26 2023 11:11:58) (NTS gcc x86_64) Copyright (c) The PHP Group Zend Engine v4.2.11, Copyright (c) Zend Technologies with Zend OPcache v8.2.11, Copyright (c), by Zend Technologies |
If the version is updated to 8.2, it is OK.
③Apache Restart
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 Sat 2023-10-14 11:15:34 JST; 1min 54s ago Main PID: 11017 (php-fpm) Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec" Tasks: 6 (limit: 10869) Memory: 22.1M CGroup: /system.slice/php-fpm.service tq11017 php-fpm: master process (/etc/php-fpm.conf) tq11018 php-fpm: pool www tq11019 php-fpm: pool www tq11020 php-fpm: pool www tq11021 php-fpm: pool www mq11022 php-fpm: pool www Oct 14 11:15:34 localhost.localdomain systemd[1]: Starting The PHP FastCGI Process Manager... Oct 14 11:15:34 localhost.localdomain systemd[1]: Started The PHP FastCGI Process Manager. |
④Confirmation of PHP operation
Create the following files
1 2 |
# vi /var/www/html/[FQDN]/test.php <?php phpinfo(); ?> |
f you access http://[FQDN]/test.php in your browser and see the following screen, it is OK