From PHP installation to command line execution
#Introduction I have decided to write a simple program that runs in batch in PHP. When I looked it up with PHP, it was mostly the contents displayed on the screen by the browser, so I thought I would leave the procedure to move with the command line. The purpose is to check the operation of a program written in PHP on your own PC. It’s insanely easy.
#Environment Windows 10 Home 64-bit
From this link go to the installer download page and click “Downloads” at the top of the screen. https://www.php.net/ ![Screenshot_2020-08-26 PHP Hypertext Preprocessor.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/210577/c7127109-5cb4-3615-cbe7-1dc1e36c2b78.(png)
Current Stable PHP x.x.x is the latest version of PHP. If you need an older version, check Old Stable PHP x.x.x. *If you are looking for an older version than the old version on the download page, it seems to be the page with the URL link below. https://www.php.net/releases/
I’m going to put in the latest version this time, so click “Windows downloads” of Current Stable PHP 7.4.9.
Since my own terminal is 64-bit, select x64. There are two patterns, “Thread Safe” and “Non Thread Safe”, but in most cases it is assumed that PHP is run on the WEB server, so select “Thread Safe”. *Reference: What does “thread safe” mean when downloading PHP? https://www.php.net/manual/ja/faq.obtaining.php#faq.obtaining.threadsafety
In my case this time, either is fine because it is for the purpose of verifying the operation of a simple program, but I decided to select “Thread Safe” which seems to be the majority. ![Screenshot_2020-08-26 PHP For Windows Binaries and sources Releases.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/210577/f512d294-ab73-227c-(3bd1-2a348f66c382.png)
Extract the downloaded ZIP file to any location. *I placed it directly under C drive. This completes the PHP installation.
If you execute the command to check the PHP version immediately after installation… ‘php’ is not recognized as a command. So, set it so that it is recognized.
Enter “System Details” in the search box on the right side of the Start button to launch “Display advanced system settings”.
Click “Environment Variables”.
Select the system environment variable “Path” and click “Edit”.
Double-click the empty space at the bottom of Edit Environment Variable Name and enter the path where you installed PHP. *In my case, I installed it in “C:\php-7.4.9”, so I entered that path. After entering, click “OK”.
Click OK to finish the environment settings.
After completing the setting, restart the command line and execute the command to check the PHP version. ‘php’ is recognized as a command! This completes PHP settings.
PHP command line execution
I will write a simple program that just outputs characters to the command prompt screen.
<?php echo "command prompt character output"; ?>
Save it with Notepad, change the extension from “txt” to “php”, and place it anywhere. *I placed the file name “test.php” under “C:\work”.
Start the command prompt, enter the’php’ command, a space, and the path of the PHP file. “Command prompt character output” is displayed on the command prompt screen! This completes command line execution.
If you write the program you want to process in , you can execute it from the command line and check the operation.