LinuxQuestions.org
Help answer threads with 0 replies.
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 12-09-2016, 10:53 AM   #1
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 789

Rep: Reputation: Disabled
Running a PHP file upon startup


I would like to run a script (/var/www/client.php) whenever a Raspberry Pi boots:

I believe my two options are to put /usr/bin/php /var/www/client.php & in /etc/rc.local or do something like the following:

Code:
sudo vi /etc/init.d/client
sudo chmod 755 /etc/init.d/client
sudo update-rc.d client defaults
Code:
michael@raspberrypi:~ $ cat /etc/init.d/client
#!/bin/bash
# /etc/init.d/client

### BEGIN INIT INFO
# Provides:          client
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: bla bla bla
# Description:       Start PHP client script to ask for changes from remote AJAX queries
### END INIT INFO
# /usr/bin/php /var/www/client.php &
michael@raspberrypi:~ $

I've tested both of them, and they both work. Is this correct, or should it be done differently? Is one way more appropriate/professional than another?

Next, instead of directly executing the PHP command, I would like to something like the following. As I am typing this, I expect this is why I would want to use the second option and not /etc/rc.local, right? Note that I am a not positive about the /etc/init.d/client script.

Code:
sudo /etc/init.d/client start|stop|status
 
Old 12-10-2016, 08:11 PM   #2
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
I would use:
Code:
php -r 'client()'
 
  


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
Problems in running an mp3 file in startup of linux Vijay karthik Linux - Newbie 8 11-18-2013 10:06 AM
Running Bash File On Startup Cobozco Linux - Newbie 4 06-13-2013 03:53 PM
Running a .sh file via PHP Shnooter Linux - Newbie 1 04-26-2011 06:36 PM
Running an executable file at startup in Fedora 9 vinayblore Linux - Newbie 3 04-03-2009 05:20 AM
What is the initial file running during Mandriva 2007 startup ? Cara25 Mandriva 8 12-01-2006 01:51 AM

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

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

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
Open Source Consulting | Domain Registration