Find the answer to your Linux question:
Results 1 to 7 of 7
Hi , Can someone tell me how register a PHP program to run as a service at the backend, which starts when the pc start...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie
    Join Date
    Dec 2005
    Location
    Singapore
    Posts
    234

    Service registeration


    Hi ,
    Can someone tell me how register a PHP program to run as a service at the backend, which starts when the pc start
    Proper Planing is a way of success

  2. #2
    Linux User
    Join Date
    Aug 2005
    Location
    Italy
    Posts
    401

    Execute the PHP interpreter

    You should run (in a init.d script)
    Code:
    /usr/bin/php4 script.php
    (check with
    Code:
    whereis php
    )
    When using Windows, have you ever told "Ehi... do your business?"
    Linux user #396597 (http://counter.li.org)

  3. #3
    Linux Newbie
    Join Date
    Dec 2005
    Location
    Singapore
    Posts
    234

    Re: Execute the PHP interpreter

    Quote Originally Posted by burnit
    You should run (in a init.d script)
    Code:
    /usr/bin/php4 script.php
    (check with
    Code:
    whereis php
    )
    u mean just to store all my php files into the bin directories, it will register become a service automatically
    Proper Planing is a way of success

  4. #4
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    No.

    In the /etc/init.d directory are a number of scripts. You could create your own that calls the PHP script.

  5. #5
    Linux Newbie
    Join Date
    Dec 2005
    Location
    Singapore
    Posts
    234
    Quote Originally Posted by Cabhan
    No.

    In the /etc/init.d directory are a number of scripts. You could create your own that calls the PHP script.
    I don't have the file init.d, i only have inetd.conf in my etc directory, is it this is the file same as what u told me
    Proper Planing is a way of success

  6. #6
    Linux User
    Join Date
    Aug 2005
    Location
    Italy
    Posts
    401
    I'm using Debian. Each distro uses some method to start system service. I'll explain how Debian do. In /etc/init.d/ (wich is a directory), there are many scripts wich are able to start system services. Then, in /etc/ there also directories named rc[0, 1, 2, 3, 4, 5, 6].d: in these directories there are soft links to the scripts in /etc/init.d. When you start your system, all script contained in a rc*.d are executed in a predetermined order.

    As example this is a part of my /etc/rc2.d/:

    luca@sirius:~$ ls -l /etc/rc2.d/
    total 0
    lrwxrwxrwx 1 root root 18 Sep 9 19:13 S10sysklogd -> ../init.d/sysklogd
    lrwxrwxrwx 1 root root 15 Sep 9 19:13 S11klogd -> ../init.d/klogd
    lrwxrwxrwx 1 root root 14 Sep 10 04:21 S12alsa -> ../init.d/alsa
    lrwxrwxrwx 1 root root 25 Oct 12 01:20 S13sirius-firewall -> ../init.d/sirius-firewall
    lrwxrwxrwx 1 root root 13 Sep 19 20:40 S14ppp -> ../init.d/ppp
    lrwxrwxrwx 1 root root 14 Sep 10 04:21 S15bind -> ../init.d/bind
    lrwxrwxrwx 1 root root 17 Oct 7 18:02 S18portmap -> ../init.d/portmap
    lrwxrwxrwx 1 root root 16 Oct 11 02:37 S20cupsys -> ../init.d/cupsys
    lrwxrwxrwx 1 root root 18 Sep 22 16:21 S20ddclient -> ../init.d/ddclient
    lrwxrwxrwx 1 root root 14 Sep 10 04:21 S20dhcp -> ../init.d/dhcp
    lrwxrwxrwx 1 root root 14 Sep 9 19:13 S20exim -> ../init.d/exim
    ...
    You should:
    - create a your own script in /etc/init.d/
    - make is executable (chmod u+x "script")
    - link it in a rc*.d directory (cd /etc/rc2.d && ln -s ../init.d/script script).

    Then the script will be executed each time you boot your system. Now, if you run you PHP script, you should call it in the just created script.

    However you should see you distro documentation, because something can differ. There are also many how-to, and probably this argument was talked in these forums.

    Good learning.
    When using Windows, have you ever told "Ehi... do your business?"
    Linux user #396597 (http://counter.li.org)

  7. #7
    Linux Newbie
    Join Date
    Dec 2005
    Location
    Singapore
    Posts
    234
    Quote Originally Posted by burnit
    I'm using Debian. Each distro uses some method to start system service. I'll explain how Debian do. In /etc/init.d/ (wich is a directory), there are many scripts wich are able to start system services. Then, in /etc/ there also directories named rc[0, 1, 2, 3, 4, 5, 6].d: in these directories there are soft links to the scripts in /etc/init.d. When you start your system, all script contained in a rc*.d are executed in a predetermined order.

    As example this is a part of my /etc/rc2.d/:

    luca@sirius:~$ ls -l /etc/rc2.d/
    total 0
    lrwxrwxrwx 1 root root 18 Sep 9 19:13 S10sysklogd -> ../init.d/sysklogd
    lrwxrwxrwx 1 root root 15 Sep 9 19:13 S11klogd -> ../init.d/klogd
    lrwxrwxrwx 1 root root 14 Sep 10 04:21 S12alsa -> ../init.d/alsa
    lrwxrwxrwx 1 root root 25 Oct 12 01:20 S13sirius-firewall -> ../init.d/sirius-firewall
    lrwxrwxrwx 1 root root 13 Sep 19 20:40 S14ppp -> ../init.d/ppp
    lrwxrwxrwx 1 root root 14 Sep 10 04:21 S15bind -> ../init.d/bind
    lrwxrwxrwx 1 root root 17 Oct 7 18:02 S18portmap -> ../init.d/portmap
    lrwxrwxrwx 1 root root 16 Oct 11 02:37 S20cupsys -> ../init.d/cupsys
    lrwxrwxrwx 1 root root 18 Sep 22 16:21 S20ddclient -> ../init.d/ddclient
    lrwxrwxrwx 1 root root 14 Sep 10 04:21 S20dhcp -> ../init.d/dhcp
    lrwxrwxrwx 1 root root 14 Sep 9 19:13 S20exim -> ../init.d/exim
    ...
    You should:
    - create a your own script in /etc/init.d/
    - make is executable (chmod u+x "script")
    - link it in a rc*.d directory (cd /etc/rc2.d && ln -s ../init.d/script script).

    Then the script will be executed each time you boot your system. Now, if you run you PHP script, you should call it in the just created script.

    However you should see you distro documentation, because something can differ. There are also many how-to, and probably this argument was talked in these forums.

    Good learning.
    Thk u very much, i have to add in more thiings in my php program in order for it to be able to run as a service.
    Proper Planing is a way of success

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •