Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a simple question that I couldn't find an answer for on the web or on StackOverflow.

I have two PHP scripts that I would like to run as daemon (not every x seconds/days).

Now I want to run them manually. I would also like them to run every time the server reboots.

What is the best practice for doing this?

If in your answer you are suggesting to use /etc/init.d/ please explain how this is done.

share|improve this question

closed as off-topic by ThatGraemeGuy, MadHatter, Ward, Falcon Momot, Jenny D Sep 10 '13 at 7:42

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions must demonstrate a minimal understanding of the problem being solved. Try including attempted solutions, why they didn't work, and the expected results. See How can I ask better questions on Server Fault? for further guidance." – ThatGraemeGuy, MadHatter, Ward, Jenny D
If this question can be reworded to fit the rules in the help center, please edit the question.

I can't quite make sense of your request to run your scripts as a daemon and also to run them manually the way it's written. Do you want to have a daemon running but also be able to run a second copy of the script manually and have that one finish? – Ladadadada Sep 9 '13 at 12:13
No i want to run it from deamon now, but if the machine will restart it should run automatically – Liad Livnat Sep 9 '13 at 19:16
up vote 3 down vote accepted

you can do this with cronjob.

@reboot  php -f /var/scripts/script.php

share|improve this answer

Aside from the cronjob answer, which I would suggest, you can also do this inside of /etc/rc.local. If the script stays running, or runs for a period of time, you may want to fork it with & :

/usr/bin/php -f /path/to/script.php &
exit 0

Is how the line would appear in your /etc/rc.local file

Note: added the exit 0 to show you want the line above the exit call).

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.