将一个php 程序 添加到linux开机自动启动

最近遇到一个问题,有一个php的程序须要开机自动启动,网上主要的有3种办法,我试了2种php


(1)编辑“/etc/rc.local”,把启动程序的shell命令输入进去便可(要输入命令的全路径),结果失败了,具体 缘由不清楚html

      (2)能够看到“/etc/rc.d/init.d”下有不少的文件,每一个文件都是能够看到内容的,其实都是一些shell脚本。
系统服务的启动就是经过“/etc/rc.d/init.d”中的脚本文件实现的。咱们也能够写一个本身的脚本放在这里。
脚本文件的内容也很简单,相似于这个样子(例如起个名字叫作“hahad”):
nginx

        #chkconfig: - 85 15shell

   #description: nginx is a World Wide Web server. It is used to serve
(上面的两行看状况添加,若是报错 “service XXX does not support chkconfig”,就须要添加上 面的两行

. /etc/init.d/functions
start() {
        echo "Starting my process "
        cd /opt
        php  a.php
}
stop() {
        killall a.php
        echo "Stoped"
}
写了脚本文件以后事情尚未完,继续完成如下几个步骤:
chmod +x hahad                    #增长执行权限
chkconfig --add hahad             #把hahad添加到系统服务列表
chkconfig hahad on                 #设定hahad的开关(on/off)
chkconfig --list hahad               #就能够看到已经注册了hahad的服务
bash



参考网址:http://www.cnblogs.com/gzggyy/archive/2012/08/07/2626574.htmlide


       http://professor.blog.51cto.com/996189/1579791/
spa