Skip to content

apache2

Apache2 (Apache HTTP Server) is a free, open-source, and widely-used web server software that delivers web content over HTTP, serving as a platform for approximately a third of all websites, known for its stability, flexibility via modules, and cross-platform compatibility (Linux, Windows, macOS)

Installation

Install Apache2

emerge --ask apache2

OpenRC

Start apache2

/etc/init.d/apache2 start

Stop apache2

/etc/init.d/apache2 stop

Restart

/etc/init.d/apache2

Reload Apache2

/etc/init.d/apache2 reload

Check Status

/etc/init.d/apache2 status

Enable php

To enable PHP in apache, you will need to add "-D PHP" to your apache2 command. OpenRC users can append that string to APACHE2_OPTS in /etc/conf.d/apache2".

eselect php set cli 3

File: /etc/apache2/modules.d/70_mod_php.conf

<IfDefine PHP>
    # The mod_php.so symlink is controlled by
    # eselect-php. However, the module name changed from
    # php5_module to php7_module so we can't blindly load whatever
    # is there. Instead we let eselect-php manage a small
    # configuration file that loads the appropriate module.
    Include "/var/lib/eselect-php/mod_php.conf"

    # Tell apache that mod_php should handle PHP files.
    #
    # NOTE: Avoiding AddHandler/AddType for security (bug
    # #538822). Please read the related news item!
    <FilesMatch "\.(php|php[57]|phtml)$">
       SetHandler application/x-httpd-php
    </FilesMatch>

    # PHP source files which are meant to be displayed as
    # syntax-highlighted source code.
    <FilesMatch "\.phps$">
       SetHandler application/x-httpd-php-source
    </FilesMatch>

    DirectoryIndex index.php index.phtml
</IfDefine>

Verify that PHP module

To verify the PHP module works, create a test page in /var/www/htdocs/localhost

<html>
  <body>
    <?php phpinfo(); ?>
 </body>
</html>

Configure Proxy

Configure Proxy

etc/init.d/apache2 restart 
 * Caching service dependencies ...
 * You are binding an interface in you virtual hosts.
 * You must add rc_need="net.FOO" to your /etc/conf.d/apache2
 * where FOO is the interface(s) providing the following address(es):
 *znc.nr1.se (/etc/apache2/vhosts.d/znc.nr1.nu.conf:1)                                                                                                                                   [ ok ]
 * Stopping apache2 ...                                                   [ ok ]
 * Starting apache2 ... 
Bind interface with rc_need

Set interface that will be used for hosting apache2

printf '\n\n%s\n\n' 'rc_need="net.eno1' >> /etc/conf.d/apache2
/etc/init.d/apache2 restart

Setup letsencrypt signed certs

certbot -d www.hostname.com -d hostname.com --apache

When certbot will verify the cert we will see similiar in access.log for apache2

3.22.61.96 - - [14/May/2023:10:30:19 +0200] "GET /.well-known/acme-challenge/CMWy_f-AKz7uG9c89xwWKig70uHSX0n7tKpgHVm_oY4 HTTP/1.1" 200 87
23.178.112.209 - - [14/May/2023:10:30:19 +0200] "GET /.well-known/acme-challenge/CMWy_f-AKz7uG9c89xwWKig70uHSX0n7tKpgHVm_oY4 HTTP/1.1" 200 87
35.91.12.158 - - [14/May/2023:10:30:19 +0200] "GET /.well-known/acme-challenge/CMWy_f-AKz7uG9c89xwWKig70uHSX0n7tKpgHVm_oY4 HTTP/1.1" 200 87
3.17.145.168 - - [14/May/2023:10:30:19 +0200] "GET /.well-known/acme-challenge/P0q5SwIQxt_zS1uKeCg100HGp_jA53-kn_sFJpymxoA HTTP/1.1" 200 87
23.178.112.208 - - [14/May/2023:10:30:19 +0200] "GET /.well-known/acme-challenge/P0q5SwIQxt_zS1uKeCg100HGp_jA53-kn_sFJpymxoA HTTP/1.1" 200 87
35.91.12.158 - - [14/May/2023:10:30:19 +0200] "GET /.well-known/acme-challenge/P0q5SwIQxt_zS1uKeCg100HGp_jA53-kn_sFJpymxoA HTTP/1.1" 200 87