Skip to content

apache2 | Cheatsheet

The Apache HTTP Server is a free and open-source cross-platform web server software, released under the terms of Apache License 2.0. Apache is developed and maintained by an open community of developers under the auspices of the Apache Software Foundation


emerge --ask apache2


/etc/init.d/apache2 start
/etc/init.d/apache2 stop
/etc/init.d/apache2 restart
/etc/init.d/apache2 reload
/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 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

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

    DirectoryIndex index.php index.phtml

Verify that PHP module

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

    <?php phpinfo(); ?>

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):
 * (/etc/apache2/vhosts.d/                                                                                                                                   [ 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 -d --apache

When certbot will verify the cert we will see similiar in access.log for apache2 - - [14/May/2023:10:30:19 +0200] "GET /.well-known/acme-challenge/CMWy_f-AKz7uG9c89xwWKig70uHSX0n7tKpgHVm_oY4 HTTP/1.1" 200 87 - - [14/May/2023:10:30:19 +0200] "GET /.well-known/acme-challenge/CMWy_f-AKz7uG9c89xwWKig70uHSX0n7tKpgHVm_oY4 HTTP/1.1" 200 87 - - [14/May/2023:10:30:19 +0200] "GET /.well-known/acme-challenge/CMWy_f-AKz7uG9c89xwWKig70uHSX0n7tKpgHVm_oY4 HTTP/1.1" 200 87 - - [14/May/2023:10:30:19 +0200] "GET /.well-known/acme-challenge/P0q5SwIQxt_zS1uKeCg100HGp_jA53-kn_sFJpymxoA HTTP/1.1" 200 87 - - [14/May/2023:10:30:19 +0200] "GET /.well-known/acme-challenge/P0q5SwIQxt_zS1uKeCg100HGp_jA53-kn_sFJpymxoA HTTP/1.1" 200 87 - - [14/May/2023:10:30:19 +0200] "GET /.well-known/acme-challenge/P0q5SwIQxt_zS1uKeCg100HGp_jA53-kn_sFJpymxoA HTTP/1.1" 200 87