LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   boot php daemon (https://www.linuxquestions.org/questions/linux-newbie-8/boot-php-daemon-374573/)

rubella 10-19-2005 03:46 AM

boot php daemon
 
hay all! i want to run a php-script at bootup. how can i fix this?

at boot, it must start... but when i do something like:
script.php restart
script.php stop
or
alias restart
alias stop

do i place the script in rc0.d or somewhere else? i'm completely new in this stuff. :( thx folks!

fouldsy 10-19-2005 03:54 AM

You'll probably need to look at installing php-cgi to run php scripts from the command line. For debian, simply apt-get install php4-cgi. Then you simply call:
Code:

/usr/bin/php4 /path/to/script.php
Include that code in quick shell script such as:
Code:

#!/bin/bash
echo "Running PHP script on boot..."
/usr/bin/php4 /path/to/script.php

save it to myphp.sh or whatever you want to call it within /etc/init.d and give it execute permissions:
Code:

chmod a+x /etc/init.d/myphp.sh
then symlink to whatever run level you want it to start at:
Code:

ln -s /etc/rc2.d/S30MyPHP /etc/init.d/myphp.sh
to start at runlevel 2, for example.

What is you're trying to actually do with your PHP script?

rubella 10-19-2005 04:02 AM

nice reply!

php5 allready installed, so that won't be a prob. i can run php on cli.

so you should run a shell-script, not directly the php-page? is it not possible?

with run-levels, are they always executed at boot-time? i'll do some search on the web...

but most important, can i start and stop these things with "blabla start" and "blabla stop" or "blabla restart" ?

at this moment, i'm writing time to a file every 10 seconds, but in future i would make a daemon listening to a port... (enough information on the web, but not how to start etc... )

thx doed!

fouldsy 10-19-2005 04:10 AM

I don't think you can call the php page directly as you need a boot script to execute your command within init.d. Otherwise the system doesn't know how to interpret the php code.

You can use start + stop - have a quick look at other boot scripts and how they use the case switch to check whether you're wanting to start or stop the script. This way you can have it execute something else at shutdown. Also, check out some basic bash scripting resources on the net for more detailed stuff you can do.

And yes, runlevels are ran through sequentially on boot and shutdown. Read up on how the boot process works to understand the different levels, what the S and K mean, the ordering of scripts, etc. One, it helps you learn about you system in general, and also lets you better define where you want your script to start + stop.

Have fun!

rubella 10-19-2005 04:12 AM

great job man! i know what to do! ;-)

fouldsy 10-19-2005 04:40 AM

Glad to help, come back if you get any problems with it!


All times are GMT -5. The time now is 01:12 AM.