Run any PHP Script as a Windows Service with AlwaysUp

How to Run any PHP Script as a Windows Service with AlwaysUp

Start your PHP script in the background when your PC boots. Keep it running 24/7 or schedule it to restart several times a day

PHP is a popular programming language. It is often integrated with web servers but works just as well when creating standalone applications.


To set up a PHP script to run as a background windows service with AlwaysUp:

  1. Download and install AlwaysUp, if necessary.

  2. Download and manually install the PHP package, if necessary.

    We have installed PHP in C:\PHP and we'll reference that location throughout this tutorial.

  3. Next, let's ensure that your PHP script can run normally from the command line.

    1. Start a command prompt (Start button > Run > cmd.exe)

    2. In the window that appears, type the full path to the PHP executable (php.exe) followed by the full path to the script you wish to run as a windows service. Be sure to quote each component containing at least one space!

      Since we have placed PHP in C:\PHP, and our script is C:\PHP\sample-php-script.php, our command line is:

      C:\PHP\php.exe C:\PHP\sample-php-script.php

    3. Hit the Enter key to execute the command line. If your script doesn't work as expected please resolve the issues now. For example, if you get the MSVCR110.dll is missing error, please install the Visual C++ Redistributable package for Visual Studio 2012.

      Note that if your script doesn't work here then it won't work with AlwaysUp!

      Here is the code of our simple script:

      Sample PHP script code

      And here is the result from running it on the command line:

      Sample PHP script code running

      Everything looks good!

  4. Next, start AlwaysUp.

  5. Select Application > Add to open the Add Application window:

    Add Application

  6. On the General tab:

    • In the Application field, enter the full path to the PHP executable (php.exe). Again, this is C:\PHP\php.exe for our installation.

    • In the Arguments field, enter the full path to your PHP script. We want to run our sample script, C:\PHP\sample-php-script.php.

    • In the Name field, enter the name that you will call this application in AlwaysUp. We have used My PHP Script but you can specify virtually anything you like.

    PHP Script Windows Service: General Tab

  7. If you only want your script to run periodically (that is, not 24x7), click over to the Restart tab and choose when to run. For example, if you wish to kick off the script at 6 AM every day, check the Not immediately and At boxes and enter that time in the corresponding field. However we'll stick with the default of restarting immediately to keep our script running continuously.

    PHP Script Windows Service: Restart Tab

  8. Click the Save >> button. In a couple of seconds, an application called My PHP Script will show up in the AlwaysUp window. It is not yet running though.

    PHP Script Windows Service: Created

  9. To start the service, which will kick off the PHP script, choose Application > Start "My PHP Script". In a few seconds, the state should transition to Running:

    PHP Script Windows Service: Running

    On Windows 8/7/Vista and Server 2012/2008, your PHP script will be running in the background on the isolated Session 0. Select Tools > Switch to Session 0 to move to Session 0 where you should see a CMD window hosting your script:

    PHP Script Windows Service: Running in Session 0

  10. That's it! Next time your computer boots, your PHP service be launched immediately, before anyone logs on. We encourage you to explore the many other AlwaysUp settings that may be appropriate for your environment.



PHP script not working properly as a Windows Service?

  • From AlwaysUp, select Application > Report Activity > Today... to bring up a HTML report detailing the interaction between AlwaysUp and your application. The AlwaysUp Event Log Messages page explains the more obscure messages.
  • Some PHP scripts need to be run in a user account to have access to their settings and resources. In that situation, edit your application in AlwaysUp, switch to the LogOn tab and enter the user name and password of the account where you can run your PHP script normally (the one you were logged in to for step 3).

    PHP Script Windows Service: LogOn Tab

  • Consult the AlwaysUp FAQ for answers to commonly asked questions and troubleshooting tips.
  • Contact us and we will be happy to help!

Download & Try it Free!

Download AlwaysUp and Run as a Service Today! Version 9.7 New!

4.6 MB Installer
  • Unrestricted 30-day trial for new users; upgrade for existing users
  • Windows 10/8.1/8/7/XP & Windows Server 2012 R2/2008/2003
  • How to Install | EULA
Our customers include...


Compatible with Windows 10 (32 & 64-bit)

Windows Server 2012 Certified (32 & 64-bit)

Windows 8 Compatible (32 & 64-bit)

Compatible with Windows 7 (32 & 64-bit)

Works with Windows Server 2008 R2 (32 & 64-bit)



Over 68,000 installations, and counting!
 
AlwaysUp is number 1! Run as a Service with AlwaysUp

Rock-solid for the past 10+ years!