Search code examples
phplinuxboot

Start PHP command line on boot


I am running a script that has to run at the user level, I do not want to change the PHP daemon to run as another user.

Currently I have to manually type php -S 0.0.0.0:8080 /home/user

This works if I input it manually but I want to be able to do this when it boots up.


Solution

  • Write a script containing your command.

    it can be a one-liner such as #!/usr/bin/php -S 127.0.0.1:8081 /home/knb (does NOT work for me)

    Make the script executable with chmod ugo+x myscript.php

    In Ubuntu, there is a GUI tool called "Startup Applications" where you have to enter the full pathname of your script in the textfield labeled "Command:".

    ALternatively, If you want to use systemd for this (e.g., to execute the script at bootup for all users, no matter who logs in), read this : https://unix.stackexchange.com/questions/47695/how-to-write-startup-script-for-systemd and follow the instructions (copy + paste an existing minimal startscript, customize it)