How to restart apache2 without terminating docker container? - php

I am using as a base the php docker container with the tag:
php:5.6-apache
When I try to restart the apache2 inside the container, the container stops:
root#phalconapp:/var/www/html# service apache2 restart
Restarting web server: apache2Terminated
root#phaclonapp:/var/www/html#
me#myLocalComputer:
How to restart apache2 without stopping the container?
I want to play around with the container and customize it, before I put my changes into the dockerfile. I want to install some extension and for them to work I need to restart apache for the changes to take effect.
This is the log file via:
Attaching to dltasklight_phlaconapp_1
phlaconapp_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
phlaconapp_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
phlaconapp_1 | [Mon May 30 10:19:24.556154 2016] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) PHP/5.6.22 configured -- resuming normal operations
phlaconapp_1 | [Mon May 30 10:19:24.556181 2016] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
phlaconapp_1 | [Mon May 30 10:21:11.754993 2016] [mpm_prefork:notice] [pid 1] AH00169: caught SIGTERM, shutting down
dltasklight_phlaconapp_1 exited with code 0

If you use apache as the primary service to keep your running container, you can NOT reboot it. Simply because you built the image and sets the CMD with it.
The main purpose of a CMD is to provide defaults for an executing container. These defaults can include an executable, or they can omit the executable, in which case you must specify an ENTRYPOINT instruction as well.
Try to reload without restart a service:
/etc/init.d/apache2 reload

My solution to this was to exit my bash shell into the container, and just restart the container outside of Docker. Because Apache is set as the primary service, this also restarts Apache, and doesn't crash the container.
docker restart <container>

sudo docker kill --signal="USR1" your_appache_container
Other signals that you can use to achieve the following :
Stop Now Signal: TERM
Graceful Restart Signal: USR1
Restart Now Signal: HUP
Graceful Stop Signal: WINCH
From: this website

I want to customize the container, I need to install some extension
and for them to work I need to restart apache for the changes to take
effect.
This is against the Docker's immutable infrastructure principle. IMHO, you are using the docker container similar to a full blown VM. Instead, I would suggest you to treat the docker image as the final artifact and version it.
Note: This is just my humble opinion, you may have a valid usecase which I am not aware of, which I am curious to find out.

Inside docker, I use a command like this:
exec /usr/sbin/httpd -D FOREGROUND

But before going, does your apache fails while doing the restart? Thats how it exits? In that case, please do make it run by setting right configurations and having a look at those logs.
One method you can try is login to the container (to bash) and you could always have a docker commit at a point where it works. You can then change your base container image to that.
I had workarounds for similar situations by building new images from these committed ones using different ENTRYPOINT's in my Dockefile.

Related

docker image for php is not working on browser for windows 10

I just started to learn docker and tried to create a php image with apache using docker file. As per my understanding I am able to create image using the docker file and after building image I tried to run that image in the form of container and it looks fine to me but when I tried to run that on the browser using "172.17.0.2" IP address its showing The connection was reset issue and i tried a lot but not able to resolve this issue. I am attaching few images for to clearly mention my issue.
Dockerfile:
FROM php:7.2-apache
COPY src/ /var/www/html/
and the screen of windows pwershell showing
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message [Sat Oct 13 17:42:22.816118 2018] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.25 (Debian) PHP/7.2.10 configured -- resuming normal operations [Sat Oct 13 17:42:22.817371 2018] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
Any help would be appreciated, thanks.
I am able to resolve the issue now, there were two problems:
(1) I was trying to reach an incorrect IP the correct was 127.0.0.1
(2) I wasn't running windows power shell as admin to run docker commands.
One more thing if anyone still faces the same issue than make sure you configured to access shared drive for docker containers through docker interface.
I also worked through the https://hub.docker.com/_/php apache example. I solved the issue by clarifying ownership of the php sources by adding a third line to the Dockerfile:
FROM php:7.2-apache
COPY src/ /var/www/html/
RUN chown -R www-data:www-data /var/www/html

How to pass Docker Compose variables to Apache and PHP?

Let's say I have a variable TEST: test passed in docker-compose.yml to a container. From the shell inside the container I can see by echoing that the variable really is passed. However, Apache (2.2) does not seem to receive it. For example, PassEnv TEST fails:
Starting httpd: [Thu Nov 30 18:22:28 2017] [warn] PassEnv variable TEST was undefined
Also $_ENV["TEST"] stays empty.
mod_env is loaded properly.
How do I get Apache to read the variables passed via docker-compose.yml, and how do I pass those to PHP?
What are the settings in Apache and PHP that block the passing of system environment variables?
I'm running CentOS 6.9, Apache 2.2, and PHP 5.3.3.

Apache 2.4 Error: FCGI: attempt to connect to Unix domain socket /run/php/php7.0-fpm.sock (*) failed

I have updated my working Froxlor installation to PHP 7.
All my customer-sites work perfectly fine (with PHP 7 via FPM).
The only problem is, that if I want to access the Froxlor Backend, I get an Erorr 503.
The apache Error-Log says:
`[Tue Oct 11 10:01:04.067069 2016] [proxy:error] [pid 23949] (2)No such file or directory: AH02454: FCGI: attempt to connect to Unix domain socket /run/php/php7.0-fpm.sock (*) failed`
`[Tue Oct 11 10:01:04.089648 2016] [proxy_fcgi:error] [pid 23949] [client xx.xx.xx.xx:1819] AH01079: failed to make connection to backend: httpd-UDS`
The Error-Log of PHP-FPM says nothing.
The same thing happens, if I try to access the server directly via IP.
System-Details:
Debian 8
Apache 2.4
PHP7
PHP7-FPM
Where I have to serach for the Problem? If needed, config-files can be provided.
If you are using PHP-FPM, the problem may also be that you need to start the PHP service.
Apache does not automatically stop the process, so you will either manually start it up or automatically on startup
For PHP 7.x (remember to include your version):
service php7.x-fpm start
For PHP 7:
service php7-fpm start
For PHP 5:
service php-fpm start
This will begin the FPM process for you.
Additionally, you may also want the process to startup on boot. To do that simply enter the following, of course considering your respective version.
systemctl enable php7.x-fpm
I had same issue, on New server having php7.4 and these virtual host configuration files(located in /etc/apache2/sites-available/ directory) i migrated from server having php7.2.
When checked in detail i found
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php/php7.2-fpm.sock|fcgi://localhost/"
</FilesMatch>
Which then i replaced with
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost/"
</FilesMatch>
Basically updating php version and it worked fine after restarting apache2
Steps I made in order to make it work on my host:
in /etc/apt/sources.list - added non-free to debian repository
apt update
apt install libapache2-mod-fastcgi
a2enmod fastcgi
(That made the "Invalid command 'FastCgiExternalServer' error, I encountered on a new installation", go away).
In Froxlor - "Settings" - "Froxlor VirtualHost settings":
[X] Enable PHP-FPM for the Froxlor vHost If enabled, Froxlor will also be running under a local user.
I also removed all "Listen" entries from apache2's ports.conf

Apache Webserver stopped working on windows7

I have an Apache 2.4.9 web-server running php5 on windows7. It had been working fine, but now it isn't running. I see nothing about php in the application logs, nor in the Apache logs.
I do not know how to troubleshoot php5 in windows. I cannot run any phpinfo(); scripts, but I can see where php is started in the Apache logs
[Mon May 12 17:26:49.832429 2014] [mpm_winnt:notice] [pid 1388:tid 528] AH00455: Apache/2.4.9 (Win32) PHP/5.5.11 configured -- resuming normal operations
I see no notice of PHP crashing though.
The page is http://rm362c.umecheme.maine.edu/
and you can see the php in the source now.
what steps can I take to troubleshoot and debug php5 as it pertains to Apache2.4 and Windows7?
Add below lines to php.ini to view any php error in your browser --
error_reporting = -1
display_errors = On
Remove above lines in your production environment (Source: http://php.net/manual/en/errorfunc.configuration.php#89648 ).
For more check http://php.net/manual/en/errorfunc.configuration.php .
If port 80 is blocked by Skype or some other applications you will not be able to run apache since http requires port 80 and https require port 443 open. or if you have IIS web server running it also could be reason.
Please go through below article for further details if its xampp on windows7
http://www.nextofwindows.com/how-to-troubleshoot-xampp-apache-not-running-on-windows-7/

PHP Redis Error: Uncaught exception ‘RedisException’

I use Redis to build a IOS SNS App (for restful api). As more user use it, errors happened.
It throws out :
Uncaught exception 'RedisException' with message 'read error on connection'
in /data1/www/htdocs/11/iossns/Model/Core/Redis.php
I don't know how to solve the problem.
Can you help?
Thank you!
What PHP-to-Redis library are you using? Here’s the official list from Redis. What is your webserver? (Apache, nginx, etc) How is PHP running? (CGI, FPM, mod_php, etc)
Here’s a thread for the same exception message in phpredis. It turns out phpredis does not currently support persistent connections with php-fpm. Version 2.2.3 of phpredis has some connection handling changes that might decrease the frequency of your issues.
I recommend checking your Redis connector configuration to…
disable persistent connections
enable connection retries
increase log verbosity
You might also consider adjustments to (generally increasing) default_socket_timeout in php.ini.
It's a redis 6 bug.
You can do this:
sudo nano /etc/systemd/system/redis.service
# ADD THIS TO [Service] SECTION
ExecStartPost=/bin/sh -c "echo $MAINPID > /var/run/redis/redis.pid"
sudo systemctl daemon-reload && sudo systemctl restart redis-server
In my case in Ubuntu 20.04 I discovered systemctl was trying to restart service because it couldn't find the /run/redis/redis-server.pid
redis-server.service: Failed with result 'timeout'.
Feb 25 17:51:09 artamredis systemd[1]: Failed to start Advanced key-value store.
Feb 25 17:51:09 artamredis systemd[1]: redis-server.service: Scheduled restart job, restart counter is at 18.
Feb 25 17:51:09 artamredis systemd[1]: Stopped Advanced key-value store.
Feb 25 17:51:09 artamredis systemd[1]: Starting Advanced key-value store...
Feb 25 17:51:09 artamredis systemd[1]: redis-server.service: Can't open PID file /run/redis/redis-server.pid (yet?) after start: Operation not permitted
In order to solve it in /etc/redis/redis.conf file find
pidfile /var/run/redis_6379.pid
and change to
pidfile /run/redis/redis-server.pid

Categories