PHP is one of the most used languages today for the design of applications and web pages. One of the reasons for its popularity is the ease for a user to run it. If you still don’t know how to do it, here we teach you step by step.
What is PHP?
Hypertext Preprocessor or PHP is a scripting-type 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 very elaborate websites such as online stores or mobile applications. PHP files end with the extension .php, like their name.
How to open a PHP file?
With Notepad: To see 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 of 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 colors 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 application
- 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 PHP code directly on the platform or upload it to compile and test it.
How to execute a PHP file?
PHP files can be executed from a web server such as ISS and Apache. Another common way to do it is through the console using command lines.
One of the applications that is often used is Composer. It works as a dependency manager to import or export databases, clean cache or install applications.
However, the most used way is through servers. It doesn’t have to be a paid service, there are application packages like XAMPP that are used for testing locally.
XAMPP
It works just like a web server and is how developers test applications before releasing them into an open environment. It is free and easy to install.
-
Download the app, it’s available for Windows, Linux and OS X
- Go through the installation process
- Run the app for the first time and wait for the icon to turn green
- Check to start all services like Apache and MySQL
- Put the PHP files in the htdocs folder in the XAMPP folder on your hard drive
- Open your preferred browser and type localhost in the address bar
- The PHP files you installed are shown, click on the one you want to run to test its operation
cmd
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
- Login to Control Panel
- Click System / System and security / Advanced system settings
- Press the Environment Variables button
- Choose the PATH variable and click Edit
- Place a semicolon (;) at the end of the path
- Click OK and close all windows
- Open the Run window with the Win + R hotkey and type CMD
- In the console window type the path and name of the PHP file you want to run