03 — Local PHP
Technique 01: Command Line
PHP code can be run from the system command line. On MacOS and Linux, the required PHP setup files can be installed from directly within the command line. On Microsoft Windows, these files will need to be downloaded from the PHP official website, PHP.net. Once these files are downloaded and installed, follow these steps to run a PHP script file of your choice.
- Open the command line window if you haven't done so already.
- Open the file browser and navigate to the file you want to run.
- Copy the filepath as text to the clipboard.
-
Enter one of the following commands into the command line, replacing
filepathwith the filepath for the file you want to run.-
php filepath -
php -f filepath
-
Alternatively, you can enter PHP code directly into the command line. To do so, enter the following command into the command line, adding your desired PHP code after -r. (You'll need to surround your PHP code with single quotation marks.)
php -r
Technique 02: XAMPP
XAMPP is a free open-source Apache distribution developed by Apache Friends. XAMPP is available for computers running macOS, Linux, or Microsoft Windows. XAMPP comes equipped with PHP, Perl, and MariaDB. You can download XAMPP from the Apache Friends official website. Once you have downloaded and installed the appropriate version, open the XAMPP Control Panel and start the desired server(s). The available servers are as follows.
- Apache
- MariaDB (listed as "MySQL" in the XAMPP Control Panel)
- Mercury Mail Server
- FileZilla Server
- Tomcat
Technique 03: WampServer
WampServer is a web server stack package created and developed by Romain Bourdon. WampServer is available exclusively for Microsoft Windows devices. WampServer comes equipped with Apache, MySQL, and PHP. You can download WampServer from the WampServer official website.
Local PHP — Benefits and Malefits
Benefits
- No Payment Required: All modern computer operating systems come with a built-in command line of some sort, and most web server stack packages are completely free to use.
- Easy to Set Up: Downloading and installing the files required to run PHP from the system command line is a very simple task. Setting up XAMPP is only marginally more complicated, and the Apache Friends official website has a Frequently Asked Questions (FAQs) page that contains information regarding both how to set up XAMPP and how to use it. WampServer is slightly more difficult to set up, but not by much.
- No Additional Hardware Required: Regardless of the technique chosen, there is usually no need to acquire additional computer hardware. Usually, the only hardware components that are necessary are a computer, a keyboard, and a mouse, all of which are hardware components most computer users already have.
Malefits
- Operating System Compatibility Issues: Many command line commands differ between operating systems; additionally, some web server packages, such as WampSever, are available only for certain operating systems.
- Possible Loss of Data: If your computer crashes, your PHP script files will likely be lost or otherwise negatively affected (unless your PHP script files are in some sort of network drive or cloud drive).
- No Remote Access to Files: Unless you have access to some sort of network drive, cloud drive, or remote desktop application, you will not be able to access your PHP script files remotely.