LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-19-2005, 03:46 AM   #1
rubella
Member
 
Registered: Sep 2005
Location: Europe
Distribution: debian sarge
Posts: 65

Rep: Reputation: 15
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!
 
Old 10-19-2005, 03:54 AM   #2
fouldsy
Senior Member
 
Registered: Jan 2002
Location: St Louis, MO
Distribution: Ubuntu
Posts: 1,284

Rep: Reputation: 47
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?
 
Old 10-19-2005, 04:02 AM   #3
rubella
Member
 
Registered: Sep 2005
Location: Europe
Distribution: debian sarge
Posts: 65

Original Poster
Rep: Reputation: 15
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!
 
Old 10-19-2005, 04:10 AM   #4
fouldsy
Senior Member
 
Registered: Jan 2002
Location: St Louis, MO
Distribution: Ubuntu
Posts: 1,284

Rep: Reputation: 47
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!
 
Old 10-19-2005, 04:12 AM   #5
rubella
Member
 
Registered: Sep 2005
Location: Europe
Distribution: debian sarge
Posts: 65

Original Poster
Rep: Reputation: 15
great job man! i know what to do! ;-)
 
Old 10-19-2005, 04:40 AM   #6
fouldsy
Senior Member
 
Registered: Jan 2002
Location: St Louis, MO
Distribution: Ubuntu
Posts: 1,284

Rep: Reputation: 47
Glad to help, come back if you get any problems with it!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Start a daemon/program at boot SchwipSchwap Linux - Newbie 15 01-24-2006 01:58 AM
Starting daemon at boot up Buto Slackware 2 09-07-2004 08:44 PM
Startup Daemon on Boot EuroJovi Linux - Newbie 4 01-09-2004 10:39 AM
Getting a daemon to start at boot cmfarley19 Linux - General 5 12-14-2002 02:54 PM
Starting daemon during boot up chuck77 Linux - General 3 03-27-2002 06:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration