Ubuntu Apache Docker

I used Ubuntu, a Debian-based Linux, so you can find the commands to install and configure Docker in this article. Once Docker is installed, download the latest Nifi image version from DockerHub. Webdevops/php-apache ¶. These image extends webdevops/php with a apache daemon which is running on port 80 and 443. This image is using supervisor and runs the daemon under user application (UID 1000; GID 1000) as default. If the container is started under a different user the daemon will be run under the specified uid.

Despite the surge of NGINX, Apache is still one of the most used open source server software. But this article is not about Apache vs NGINX discussion. This is just a quick tips where I’ll show you various ways to restart Apache server in Ubuntu or other Linux distributions.

Restart Apache in Ubuntu Linux

Like many other services, there are multiple ways to restart Apache. Since Ubuntu 16.04, 18.04 and above versions use systemd, you can use the systemd commands to manage any service, including Apache. In fact, systemd is my recommend method.

But wait! Do you really need to restart Apache?

Why do you want to restart Apache server? Probably you made some configuration changes and you want those changes to take into effect. If that’s the case, you don’t need to restart Apache.

Restarting Apache means the Apache server will shutdown and then start again. If you are on a production server, it will result in downtime for all the services that utilize the Apache server. You don’t want to do that, do you?

Apache supports reload which means you can reload the configuration without shutting down the server. This way, your live server won’t suffer a downtime.

If you don’t want to use systemd command, there is an alternate command to reload apache server:

Okay! You really want to restart Apache

I can understand that you may have your reason where you reloading Apache won’t do the job and you must restart the Apache server. If that’s the case, you can use the systemd command:

Alternatively, you can this command as well:

Ubuntu Apache Docker

Bonus Tip: Check status of Apache server

Since you are dealing with restarting and reloading a service, it would be a good idea to check its status. You can check the status of Apache server using systemd:

The non-systemd command for checking Apache server status is:

I hope you liked this quick to tip on restarting Apache server in Ubuntu and other Linux distributions. If you have questions or suggestions, do let me know in the comment section.

Ubuntu apache php

These image extends webdevops/php with a apache daemon which is running on port 80 and 443

Uses Supervisord


This image is using supervisor and runs the daemon under user application (UID 1000; GID 1000) as default. If the container isstarted under a different user the daemon will be run under the specified uid.

Docker image tags¶

TagDistribution namePHP Version
5.6customized official php imagePHP 5.6
7.0customized official php imagePHP 7.0
7.1customized official php imagePHP 7.1
7.2customized official php imagePHP 7.2
7.3customized official php imagePHP 7.3
7.4customized official php imagePHP 7.4
8.0customized official php imagePHP 8.0
7.1-alpinecustomized official php imagePHP 7.1
7.2-alpinecustomized official php imagePHP 7.2
7.3-alpinecustomized official php imagePHP 7.3
7.4-alpinecustomized official php imagePHP 7.4
8.0-alpinecustomized official php imagePHP 8.0
alpinedeprecatedPHP 7.x
alpine-php7deprecatedPHP 7.x
alpine-php5deprecatedPHP 5.6
alpine-3deprecatedPHP 5.6
alpine-3-php7deprecatedPHP 7.x
ubuntu-12.04deprecatedPHP 5.3
ubuntu-14.04deprecatedPHP 5.5
ubuntu-15.04deprecatedPHP 5.6
ubuntu-15.10deprecatedPHP 5.6
ubuntu-16.04deprecatedPHP 7.0
debian-7deprecatedPHP 5.4
debian-8deprecatedPHP 5.6
debian-8-php7deprecatedPHP 7.x (via sury)
debian-9deprecatedPHP 7.0
centos-7PHP 5.4
centos-7-php56PHP 5.6
centos-7-php7PHP 7.0

Environment variables¶

Base environment variables¶

Ubuntu Apache Docker
Environment variableDescriptionDefault
LOG_STDOUTDestination of daemon outputempty (stdout)
LOG_STDERRDestination of daemon errorsempty (stdout)
SERVICE_CRON_OPTScron daemon argumentsempty (when syslog is used)
SERVICE_DNSMASQ_OPTSdnsmasq daemon argumentsempty (when syslog is used)
SERVICE_DNSMASQ_USERdnsmasq effective userroot
SERVICE_POSTFIX_OPTSpostfix daemon argumentsempty (when syslog is used)
SERVICE_SSH_OPTSssh daemon argumentsempty (when syslog is used)
SERVICE_SUPERVISOR_OPTSsupervisor daemon argumentsempty (when syslog is used)
SERVICE_SUPERVISOR_USERsupervisor effective userroot
SERVICE_SYSLOG_OPTSsyslog daemon argumentsempty (when syslog is used)

Base environment variables¶

Environment variableDescriptionDefault
POSTFIX_MYNETWORKSPostfix mynetworks addressempty
POSTFIX_RELAYHOSTPostfix upstream relay serverempty

Web environment variables¶

Environment variableDescriptionDefault
WEB_DOCUMENT_ROOTDocument root for webserver/app
WEB_DOCUMENT_INDEXIndex documentindex.php
WEB_ALIAS_DOMAINDomain aliases*.vm
WEB_PHP_SOCKETPHP-FPM socket address127.0.0.1:9000 (for php-* images)
SERVICE_PHPFPM_OPTSPHP-FPM command argumentsempty (when php fpm is used)
SERVICE_APACHE_OPTSApache command argumentsempty (when apache is used)
SERVICE_NGINX_OPTSNginx command argumentsempty (when nginx is used)
SERVICE_NGINX_CLIENT_MAX_BODY_SIZENginx client_max_body_size50m (when nginx is used)

PHP modules¶

As we build our images containing almost every PHP module and having it activated by default, you might want to deactivate some.

You can specify a comma-separated list of unwanted modules as dynamic env variable PHP_DISMOD, e.g. PHP_DISMOD=ioncube,redis.

PHP.ini variables¶

You can specify eg. php.memory_limit=256M as dynamic env variable which will set memory_limit=256M as php setting.

Environment variableDescriptionDefault
php.{setting-key}Sets the {setting-key} as php setting

PHP FPM variables¶

You can specify eg. fpm.pool.pm.max_requests=1000 as dyanmic env variable which will sets pm.max_requests=1000 as fpm pool setting.The prefix fpm.pool is for pool settings and fpm.global for global master process settings.

Environment variableDescriptionDefault
fpm.global.{setting-key}Sets the {setting-key} as fpm globalsetting for the master process
fpm.pool.{setting-key}Sets the {setting-key} as fpm poolsetting


Due to the incompatibilities between composer v1 and v2 we introduce a simple mechanism to switch between composer versions.

Environment variableDescriptionDefault
COMPOSER_VERSIONSpecify the composer version to use2

Be aware that this switch is only executed during container start (entrypoint).If you want to build your software with a specific composer version, you can do this:

Or composer respectively.


PHP customization¶

For customization a placeholder /opt/docker/etc/php/php.ini is available which will be loaded as lastconfiguration file. All settings can be overwritten in this ini file.

Either use COPY inside your Dockerfile to overwrite this file or useRUNechomemory_limit=128M>>/opt/docker/etc/php/php.ini to set specific php.ini values.

Apache customization¶

This image has two directories for configuration files which will be automatic loaded.

For global configuration options the directory /opt/docker/etc/httpd/conf.d can be used.For vhost configuration options the directory /opt/docker/etc/httpd/vhost.common.d can be used.

Ubuntu Apache Docker Free

Any *.conf files inside these direcories will be included either global or the vhost section.

Docker image layout¶

Run Apache Ubuntu Docker

Apache layout¶


Main global configuration directory

(automatically included files)

/opt/docker/etc/httpd/conf.d/10-php.confPHP cgi configuration
/opt/docker/etc/httpd/conf.d/10-error-document.confError document configuration
/opt/docker/etc/httpd/conf.d/10-log.confLog configuration
/opt/docker/etc/httpd/conf.d/10-server.confBasic server configuration

SSL configuration directory for

certifications and keys

/opt/docker/etc/httpd/ssl/server.crtExample SSL certification (*.vm)
/opt/docker/etc/httpd/ssl/server.csrExample SSL certification request (*.vm)
/opt/docker/etc/httpd/ssl/server.keyExample SSL key (*.vm)

Vhost configuration directory

(automatically included files)


Placeholder configuration file

(prevent include errors for Apache 2.2)

/opt/docker/etc/httpd/global.confGlobal httpd configuration
/opt/docker/etc/httpd/main.confMain httpd configuration
/opt/docker/etc/httpd/php.confDeprecated PHP configuration
/opt/docker/etc/httpd/vhost.common.confDeprecated vhost common include
/opt/docker/etc/httpd/vhost.confVhost configuration
/opt/docker/etc/httpd/vhost.ssl.confVhost SSL configuration
/opt/docker/etc/supervisor.d/httpd.confSupervisord configuration file for Apache HTTPD

PHP layout¶

Ubuntu Apache Install

/opt/docker/etc/php/php.webdevops.iniPHP settings from WebDevOps image
/opt/docker/etc/php/php.iniphp.ini for custom settings
/opt/docker/etc/php/fpm/php-fpm.confPHP-FPM main configuration file
/opt/docker/etc/php/fpm/pool.d/application.confApplication PHP-FPM pool configuration file
/opt/docker/etc/supervisor.d/php-fpm.confSupervisord configuration file for PHP-FPM

Most Viewed Posts