As the title says, I want to know if it is be possible to automatically launch a PHP script when a restart of apache is done.
MORE INFO EDIT:
I will try to explain what is the purpose of this, the best I can. We are currently refactoring our application and we'll be stuck with 2 differents configuration file system for the time being, until all of the application flows are refactored (might take more than a year). The old one is using simple flat file in the key=value format (i.e. www.conf), while the new system will use cacheable php files (i.e. www.php). We need to replicate to www.php any config changes made in www.conf.
Since Apache gets restarted whenever there is a config change in www.conf, I thought it might be a good workaround solution to launch a PHP script, that would replicate the www.conf to www.php.
Add your PHP script to the installdir/apache2/htdocs/ directory, then browse to it via the URL http://localhost/FILENAME.php, where FILENAME is the name of the PHP script. For an example, refer to the section on using phpinfo. NOTE: If your script file is named index.
PHP is the most popular web backend programming language. A PHP code will run as a web server module or as a command-line interface. To run PHP for the web, you need to install a Web Server like Apache and you also need a database server like MySQL.
If you want to run it, open any web browser and enter “localhost/demo. php” and press enter. Your program will run.
You need to modify you startup script for your apache.
Open your startup script, it should be in /etc/init.d/apache or apache2
Search for the start / restart section and add your cli call for your PHP script.
Example:
restart)
[..]
php -q /tmp/myscript.php &
;;
Where /tmp/myscript.php is your php script that you want to launch.
The "&" at the end will start the script in the background so your startup will not wait until your php script has ended. If you want to wait until it has ended, remove the &.
You should not put such thing into your startup scripts, there might be better solutions. What are trying to achieve?
At the risk of offending people (like myself) who prefer neat clean solutions, is changing the Apache's default start script an option for you? If so, that'd be the simplest solution
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With