App service
Services/Apache HTTP server (PHP)

Apache HTTP server (PHP) service

Apache HTTP Server service for serving PHP applications through a linked PHP-FPM backend.

You add this service to a stack, where you choose its version and resources. Each app environment can override them.

On Wodby

How Apache HTTP server (PHP) runs on Wodby

What Wodby sets up for this web server. Apache here is configured by environment variables, by the config files the service declares and by the application's own .htaccess files.

How it is configured

On every start the container renders its configuration from templates and environment variables: conf/httpd.conf, conf/conf.d/vhost.conf (one virtual host) and conf/preset.conf under /usr/local/apache2. They are rewritten on each start; never edit them in a running container.

To change the configuration:

  • Set APACHE_* environment variables on the service.
  • Change the docroot setting.
  • Override the main configuration template or the virtual host template, both declared as config files of this service.
  • Add .htaccess files to the codebase: overrides are allowed in the document root (APACHE_ALLOW_OVERRIDE_ENABLED), and mod_rewrite, mod_headers, mod_expires and mod_deflate are loaded.

Preset

APACHE_VHOST_PRESET selects the rules included in the virtual host. This service uses the image default, html: files are served from the document root with index.html as the directory index (APACHE_DIRECTORY_INDEX). There is no fallback for paths that match no file; a single-page application needs its own rewrite rule in .htaccess. The image also ships a php preset, used by the PHP service built on this one.

Document root

The codebase is at /var/www/html. The docroot setting (variable DOCROOT_SUBDIR) names a subdirectory of the repository, and APACHE_DOCUMENT_ROOT is set to /var/www/html/ followed by it. Leave the setting empty to serve the repository root.

Always present

  • /.healthz returns 204 and is not logged. Use it for health checks.
  • Files and directories whose names start with a dot are denied, as are files ending in .sh, .sql, .mysql, .po, .tpl, .make or .test, wodby.yml and Makefile.
  • Directory listings are off unless APACHE_INDEXES_ENABLED is set.

Variables that matter most

VariableEffect
APACHE_DIRECTORY_INDEXdirectory index file
APACHE_ALLOW_OVERRIDE_ENABLEDwhat .htaccess files may override
APACHE_TIMEOUT, APACHE_REQUEST_READ_TIMEOUTrequest time limits
APACHE_LIMITED_ACCESSremoves the rule that grants access to everyone, so that access is defined elsewhere
APACHE_HTTP2accepts cleartext HTTP/2
APACHE_INCLUDE_CONFthe files included in place of the generated virtual host
APACHE_LOG_LEVELerror log level

Access and error logs go to the container's standard output and error.

Build and reaching the service

  • The image is built from the connected repository: the codebase is copied into the image at /var/www/html. Files are served from the built image, so a change needs a new build and deployment.
  • Other services reach it over HTTP on port 80 at the app service's name inside the environment.

Check the result

  • httpd -S prints the virtual host in effect; httpd -t checks the syntax.
  • curl -sI localhost/.healthz returns 204 from inside the container.

Apache for PHP on Wodby

What this service adds to the Apache service it is based on: it serves a PHP application's static files and passes PHP requests to the linked PHP service.

How requests are handled

The service sets APACHE_VHOST_PRESET to php:

  • The directory index is index.php (APACHE_DIRECTORY_INDEX).
  • A request for a .php file that exists under the document root is passed to the PHP service over FastCGI. A .php path with no file is not passed on.
  • Everything else is served by Apache as a file. The preset has no front controller rule: routing every path to index.php comes from the application's own .htaccess, which Apache reads.

Backend link

The link to a PHP-FPM service sets APACHE_BACKEND_HOST and APACHE_BACKEND_PORT, the FastCGI target. Apache passes the script as a path on its own disk, so the PHP service must have the code at the same path. Both images are built from the same source for that reason: this service has no repository of its own and is built from the source of the linked PHP service, copied to /var/www/html.

Document root

The docroot setting (variable DOCROOT_SUBDIR) has no default here: the repository root is served until it is set, for example to public or web. APACHE_DOCUMENT_ROOT is /var/www/html/ followed by it.

Variables that matter most

In addition to those of the Apache service: APACHE_FCGI_PROXY_TIMEOUT (how long Apache waits for PHP) and APACHE_FCGI_PROXY_CONN_TIMEOUT.

Static files

Static files are served from the built image: a changed asset needs a new build and deployment of this service.

Check the result

  • httpd -S prints the virtual host in effect.
  • curl -sI localhost/ from inside the container returns the application's response when the PHP service is reachable.

Overview

Technical profile of Apache HTTP server (PHP)

The versions are the ones you can select for Apache HTTP server (PHP) in a stack or an app environment. The service itself is published in revisions, and a stack references a specific revision.

Service type

App service

Versions

2.4

Stacks

Stacks that include Apache HTTP server (PHP)

This public stack includes Apache HTTP server (PHP). You can create an app from a public stack as it is, or add the service to a stack of your own.

Configuration

Apache HTTP server (PHP) service configuration

The Apache HTTP server (PHP) service declares the following. Where a value can be changed, a stack sets it and each app environment can override it.

Technical domains

Wodby gives each public HTTP port a technical domain with a TLS certificate and renews the certificate. A port that the service marks private gets no domain. You can add custom domains.

Configs

2 config files that a stack or an app environment can override.

Settings

1 setting that a stack or an app environment can change.

Service links

Each link is a connection from Apache HTTP server (PHP) to another service. A stack sets which service a link points to. The cards list the public services that can satisfy each link.