---
title: 'How to Run PHP Script  | Zomro'
description: 'Cron is a popular tool for automating tasks on Unix-like systems. However, if you are using Windows Server 2019, then you may need a similar tool called Task Scheduler. I'
image: 'https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/05/14/1.jpg'
---

![opened image]()

  * [Zomro](https://zomro.com/)
  * [FAQ](https://zomro.com/blog/faq/)
  * How to Run PHP Script via Cron in Windows Server 2019 



# How to Run PHP Script via Cron in Windows Server 2019

14-05-2023

Cron is a popular tool for automating tasks on Unix-like systems. However, if you are using Windows Server 2019, then you may need a similar tool called Task Scheduler. In this article, we will look at how to run a PHP script through the Task Scheduler in Windows Server 2019.

**Step 1: Install PHP**

The first step is to install PHP on your server. You can download the latest version of PHP from the official website (<https://windows.php.net/download/>). Once installed, check that PHP is running by running php -v on the command line.

![How to Run PHP Script via Cron in Windows Server 2019 - 1](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/05/14/1.jpg)

**Step 2: Creating a PHP script**

Create the PHP script you want to run through the Task Scheduler. For example, create a file called myscript.php with the following content:
    
    
    <?php
    echo "Hello World!";
    ?>

Save this file to a location convenient for you on the server.

**Step 3: Create a task in Task Scheduler**

Open Task Scheduler by pressing Win+R and typing **taskschd.msc**.

![How to Run PHP Script via Cron in Windows Server 2019 - 2](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/05/14/2.jpg)

Right-click on "Task Scheduler" and select "Create Task".

![How to Run PHP Script via Cron in Windows Server 2019 - 3](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/05/14/3.jpg)

On the General tab, provide a name for the task and a description. Select the "Run task at logon" or "Run task on schedule" option if you need to run the task on a schedule.

![How to Run PHP Script via Cron in Windows Server 2019 - 4](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/05/14/4.jpg)

On the Actions tab, select New and provide the path to the php.exe executable. This file is located in the folder where you installed PHP. Add command line arguments to specify the path to your script. For example, "C:\php\php.exe" "C:\myscript.php".

![How to Run PHP Script via Cron in Windows Server 2019 - 5](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/05/14/5.jpg)

On the Triggers tab, select the type of trigger you need. For example, if you want to run the task every day at 8:00 am, select "Daily" and enter the time.

![How to Run PHP Script via Cron in Windows Server 2019 - 6](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/05/14/6.jpg)

On the "Conditions" tab, you can specify additional conditions for the task to run. For example, you can specify that the task should only run when connected to a specific network.

![How to Run PHP Script via Cron in Windows Server 2019 - 7](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/05/14/7.jpg)

**Step 4: Verify the task**

Once you have created a task, you can test its operation by running it manually. To do this, open the Task Scheduler, find your task, right-click on it and select "Start".

![How to Run PHP Script via Cron in Windows Server 2019 - 8](https://dx86q6oq7ry0e.cloudfront.net/uploads/media/blog/a48%40server-panel.net/2023/05/14/8.jpg)

If the task starts successfully, then you should see the output of the script in the console. If something went wrong, you will see an error message.

**Step 5: Troubleshooting**

If the task does not start, then you need to check the task settings and fix the problem. The following are some common problems that may occur when running a PHP script through the Task Scheduler.

\- Wrong path to PHP executable. Make sure you provide the correct path to php.exe in the task settings.

\- Wrong path to PHP script. Make sure you provide the correct path to your script in the task settings.

\- Wrong PHP version. Make sure you are using the correct version of PHP for your system.

\- Not enough rights. Make sure the user who runs the task has sufficient permissions to execute the PHP script.

\- Wrong command line arguments. Make sure you provide the correct command line arguments in the task settings.

**Step 6: Automate Other Tasks**

Task Scheduler allows you to automate many other tasks besides running PHP scripts. For example, you can use it to back up files, clean up temporary files, update your database, and many other tasks.

**Step 7: Conclusion**

In this article, we have covered how to run a PHP script through the Task Scheduler in Windows Server 2019. We have covered the steps of installing PHP, creating a PHP script, creating a task in the Task Scheduler, verifying the task, and fixing issues. We also mentioned that the Task Scheduler allows you to automate many other tasks. If you are using Windows Server 2019 and need to automate tasks, then Task Scheduler is a very useful tool.

​

Similar articles:

[How to create your own Windows image for Cloud VPS (OpenStack)](https://zomro.com/blog/faq/513-how-to-create-your-own-windows-image-for-cloud-vps) [How to configure idle RDP session timeout](https://zomro.com/blog/faq/298-kak-zadat-vremja-otkljuchenija-bezdejchtvujuschih-seansov-rdp) [How to create a telegram bot for monitoring Mikrotik located behind a NAT](https://zomro.com/blog/faq/323-how-to-create-a-telegram-bot-for-monitoring-mikrotik-located-behind-a-nat) [How to file a complaint about abuse](https://zomro.com/blog/faq/595-kak-podat-zhalobu-na-zlopolzovanie) [How to get into phpMyAdmin from popular server control panels](https://zomro.com/blog/faq/389-in-this-article-we-will-look-at-how-to-use-phpmyadmin-to-importexport-databases-on-various-control-panels-such-as-ispmanager-cpanel-vestacp-and-hestiacp-how-to-get-into-phpmyadmin-from-popular-server)

[ Premium Cloud VPS from €7.95/mon ](/premium-vps)
