What is PHP?
Hypertext Preprocessor or PHP is a scripting-like server-side programming language. It is used to create applications and websites.
Despite having been implemented for several years, it is even used to make elaborate websites such as online stores or mobile applications. PHP files end with the extension .php, as their name.
How to open a PHP file?
With Notepad: To view the content of a PHP file and edit it, you can access it from text applications such as Notepad.
- Select the .php file
- Right click on it and choose the Open with option
- In the list of available applications choose notepad
Now you can see all the code on the page, and even edit it. The disadvantage of opening it with this application is that the elements of the code are not identified by color and it makes it more difficult to read.
BBEdit: If you are a native user of the iOS environment, the application that you can use to read the file is BBEdit.
- Run the BBEdit app
- Click on the File / Open menu
- Select the file from the folder where it is located
NotePad ++: A free and very light application that is compatible with several programming languages. It is a plain text editor, but focused on programming, so editing the code is easier.
Paiza.IO: It is a well-known online editor and compiler. Write code in PHP directly on the platform or upload it to compile and check its operation.
How to execute a PHP file?
PHP files can be run from web server like ISS and Apache. Another usual way to do it is through the console using command lines.
One of the applications that is commonly used is Composer. It works as a dependency manager to import or export databases, clear cache or install applications.
However, the most used way is through servers. It does not have to be a paid service, there are application packages like XAMPP that are used for local testing.
It works just like a web server and is the way developers test applications before releasing them to an open environment. It is free and easy to install.
- Download the application, it is available for Windows, Linux and OS X
- Go through the installation process
- Run the application for the first time and wait for the icon to turn green
- Verify that all services such as Apache and MySQL start
- Put the PHP files in the htdocs folder in the XAMPP folder on your hard drive
- Open your browser of preference and type in the address bar localhost
- The PHP files that you installed are shown, click on the one you want to run to test its operation
To run a file from CMD you must have a previous installation of XAMPP or WAMP. Remember to start the application services before running the file.
- Put the .php files in the local folder of the server
- Enter the Control Panel
- Click System / System and Security / Advanced System Settings
- Press the Environment Variables button
- Choose the PATH variable and click Edit
- Put a semicolon (;) at the end of the path
- Click OK and close all windows
- Open the Run window with the shortcut command Win + R and type CMD
- In the console window write the path and name of the PHP file you want to run