Say I have a script to populate the PHP APC cache when PHP is restarted, the cache is empty.
Is it possible to create a mechanism to autorun some kind of script when the master php-fpm process is started?
Open php-fpm
vim /etc/init.d/php-fpm
In the file, find the start function, add your commands at the end.
start () {
...
# Your commands here
}
Save and restart php-fpm
I have one article for you please once read it, It might be helpful to you Link
Open php-frm through CMD
Ubantu sudo gedit /etc/init.d/php-fpm
You put the code under following function.
function start {
/*
Your code here
*/
}
Related
I'm currently trying to update the "session.save_handler = files" and "session.save_path = null" to my own values but they always default to files.
In my case I have setup the php redis extensions and I would like to setup to "session.save_handler = redis" and "session.save_path = https://rediserver:6375", however, after updating the config files either updating directly on /usr/local/etc/php-fpm.d/www.conf or adding an extra .conf file to /usr/local/etc/php-fpm.d/session.conf and restarting php-fpm with "kill -USR2 1" the values are not updated when I check using php-info(); function.
Any idea what might be happing ? I'm using docker image php:7.2-fpm .
Thanks
I found the issue, I was using supervisorD to load my php-fpm therefore the command kill -USR2 1 wasn't making any effect to reload the php changes. The solution was to kill manually my php-fpm process and make supervisord start again with '"supervisorctl restart [task name]"'
I use nginx and php7.1-fpm. I want to run a background process using PHP and exec().
My short code:
<?php
exec('/usr/local/bin/program > /dev/null 2>&1');
Unfortunately after the systemd restart php7.1-fpm the program is killed.
I have tried to run with a different user than the one running the pool:
<?php
exec('sudo -u another_user /usr/local/bin/program > /dev/null 2>&1');
However, this does not solve the problem - still kills.
I can not use ssh2_connect(). How can I solve this problem?
It seems this is due to the php-fpm service being managed by the systemd.
All processes launched from php-fpm belong to its control-group and when you restart the service systemd sends the SIGTERM to all the processes in the control-group even if they are daemonized, detached and/or belong to another session.
You can check your control-groups with this command:
systemd-cgls
What I've done is to change the KillMode of the php-fpm service to process.
Just edit it's .service file:
vi /etc/systemd/system/multi-user.target.wants/php7.0-fpm.service
and change or add the line to the [Service] block:
KillMode=process
Then reload the configuration by executing:
systemctl daemon-reload
That worked for me.
References:
Can't detach child process when main process is started from systemd
http://man7.org/linux/man-pages/man5/systemd.kill.5.html
What would be wonderful would be a command (similar to setsid) that allowed to launch a process and detach from control-group but I haven't been able to find it.
I have a page thats called form a browser which at the end needs to run one command as root. I am very well aware of the security implications of running shell_exec commands from the browser, so I have locked down my sudoers file for "apache all no password" to the one command:
apache ALL = (ALL) NOPASSWD: /usr/sbin/rndc
I have made my PHP page hard-coded so no part of the command is run from user-accessible inputs.
This process just refreshes the config for Bind9 (named) by issuing
shell_exec("/usr/sbin/sudo /usr/sbin/rndc reload");
However, it seems this does not run, but when I have make /bin/bash the default shell for apache and as apache, this process runs when I try it in apache shell:
[root#localhost zones]# su - apache
-bash-4.2$ /usr/bin/sudo /usr/sbin/rndc reload
server reload successful
My whole PHP code:
<?php
error_reporting(E_ALL);
$result = shell_exec("/usr/bin/sudo /usr/sbin/rndc reload");
print_r($result);
?>
I get no responses. Any ideas? SELinux is now set to permissive.
turned out to be the require_ttl parameter in my sudo files. Apache was erring in /var/log/httpd/error_log.
Thats to those who viewed :)
I have an issue with apache and php.
I call this script in php:
exec("nohup sudo QUIET=y sh foo.sh > /home/tmp/log.txt 2>&1 & echo $!", $res);
Shortly after, the script foo.sh need to restart apache to include new configuration files:
/etc/init.d/apachectl restart
In command line, it works fine but in my php script the process is killed at the same time apache is restarted. Why? I thought nohup detach the processus of its parent.
(I point out that i can't change the sh script)
Any help would be greatly appreciated.
You should use /etc/init.d/apachectl reload if the only thing you want is to reread configuration files.
/etc/init.d/apachectl reload
This will not stop the service, but keep it running and refreshes the processes configuration.
Use /etc/init.d/apachectl reload instead if you dont want to kill the process.
Since apache restart sends SIGTERM, not SIGHUP,
you should handle SIGTERM from foo.sh
I have XAMPP installed on Windows 7. I need to stop and start Apache many times every day.
Currently, I do this by opening up the Xampp control panel, clicking 'Stop' (next to 'Apache'), waiting for it to stop, then clicking 'Start'.
Ideally I would like to be able to do this more quickly - something like right click the Xampp icon, and choosing 'Restart Apache'. Or, even better, just a shortcut key that restarts Apache.
I know that there are two bat files with Xampp - apache_stop.bat and apache_start.bat. I've tried utilising these to get want I want. However, when you run apache_start.bat, you get a cmd window that you can't get rid of. I couldn't find a way to start Apache silently in this way.
So, basically I want to be able to quickly restart Apache (one click/shortcut key), completely silently.
Thanks in advance.
Copy apache_start.bat and rename it to apache_restart.bat.
Change the line apache\bin\httpd.exe to apache\bin\httpd.exe -k restart
Voila, there you go with your restart script.
and you can also give it a shortcut.
If you have the Apache service monitor in your system tray, you can just open that (right click, I think?) and click "restart Apache".
If it's not in your system tray, you can find it in the /bin folder of the Apache installation (called ApacheMonitor.exe). I'd recommend making a shortcut to it in the "Startup" folder.
For me, with the version 3.2.2 the first answer didn't work.
I've put together a script from the two apache_start.bat and apache_stop.bat files.
#echo off
cd /D %~dp0
echo Apache 2 is stopping...
apache\bin\pv -f -k httpd.exe -q
if not exist apache\logs\httpd.pid GOTO exit
del apache\logs\httpd.pid
echo Apache 2 is re-starting ...
apache\bin\httpd.exe
if errorlevel 255 goto finish
if errorlevel 1 goto error
goto finish
:error
echo.
echo Apache konnte nicht gestartet werden
echo Apache could not be started
pause
:finish
#adrianthedev's version didn't work for (XAMPP v3.2.4) me but helped me find a solution.
It's a lot less sophisticated as I don't know much about scripting but here it is and it worked for me:
#echo off
C:/xampp/apache/bin/httpd -k stop
C:/xampp/apache/bin/httpd -k start
Note: apache\logs\httpd.pid doesn't need to be deleted as it's done already by the httpd -k stop command.