Open a PHP File
PHP is a scripting language utilized most often by web developers in order to offer dynamic content, which means that the content on the web page can change based on the parameters set in the PHP code. You could make this as simple as changing the background image based on the user’s time of day. Or, it could be as complex as creating a publication workflow that allows different users to see a submissions based on where that submission is in the process. You can easily view PHP files on both Mac and Windows computers with a code editing software. You can also run your PHP file using a server you pay for, or locally on your computer through XAMPP. Continue below to learn several methods on how you may do this.
Contents
Steps
Opening a PHP File on Windows
- Download a code editor if you don’t already have one. Code editors are text editing programs that allow you to write code or scripting languages. A code editor is different than a standard word processing application like Microsoft Word.
- Code editors include features for writing and reading in various coding languages, such as PHP.
- Common code editors include Dreamweaver, Notepad++, TextEdit, and Komodo Edit.
- Install a code editing software. Once you find a code editing software you like, download the application and install it. Locate the .exe file and open it. Follow the installation instructions.
- When clicking to download, you can also choose to run the installer upon downloading. Click “Run” on the security dialogue box. This will automatically run the installer.
- Once you have installed a code editing software, you can open and view your PHP files.
- Right-click on the PHP file and select “Open with.” Then choose to open the file with your code editor. Depending on your computer's speed, the file may take a moment to open. Your editor will launch and load your PHP file.
- If your code editor does not appear in the new drop-down menu, then click “Choose default program...” If your program does not appear in the new screen, then click “Browse...” and find the location you installed the program to on your computer. This may even include the desktop. Click on “OK” once you've located the program.
- Once you locate the program and click “OK”, your PHP file will open in your text editor. You can now view the code and make edits to it if you wish.
- Make your software the default for PHP files. To make it easier to open PHP files in the future you can set your application as the default for this file type. Change the app for your PHP files in the default settings page.
- Go to Settings > Change PC settings > Search and apps > Defaults.
- Click “Choose default apps by file type” or “Choose default apps by protocol”. Then click on the app, such as Notepad++, to set it as the default app.
- The next time you need to open a PHP file you can just double click on the icon to open it.
Opening PHP Files on Mac
- Download an application to open PHP files on your Mac. TextWrangler and EditRocket are both code editing applications that let you view and edit different scripting language files such as PHP. You can download TextWrangler directly from the company’s website, or through the App store on your computer.
- Once your application has downloaded, run the .dmg file if you downloaded from the internet. Drag the TextWrangler icon over to your Applications folder.
- If you downloaded an application from the App store, it will automatically get placed into your Applications folder.
- Locate your PHP file. Find the PHP file you want to open whether it’s on your desktop or in a directory of folders. Once you’ve located the file, right click on it. Select the “Open With” option.
- Once you click “Open With” you will see a list of applications pop up. Click on the TextWrangler, or other code editing application. Your PHP file will open in your desired application.
- Search for the application if it doesn’t show up. If the application you downloaded, like TextWrangler, isn’t showing up in your list click “Other…”. Doing this will bring up a window with a list of applications to choose from. Scroll down until you find the application you want and click “Open”.
- Though this shouldn’t happen, if for some reason the application is grayed out, click the drop-down menu next to “Enable”. Then click on “All Applications”.
- You can also choose to click the box next to “Always Open With”. The next time you need to open a PHP file, it will automatically launch your desired code editing application.
- Make this application your default app for PHP files. Another way to make opening PHP files easier in the future is by making the app you’ve downloaded your default app for this file type.
- Click on your PHP file, but don’t open it. You just want to highlight it.
- Press “Command” and “I” at the same time. this will bring up an informational panel for the file.
- Locate the option that says “Open with:” and click on the dropdown bar. Click on the name of the app you downloaded. Below you will see an option to “Change All…”. Clicking this will make it so all PHP files in the future are opened with this app.
- You will be able to double click to open PHP files now.
Executing a PHP file in a Web Browser
- Place the PHP file on a server. In order for you to see the scripting in PHP at work, it must be processed within a server environment.This means you have to place your PHP file in your web folder.
- If you rent space from a server host, then you will need to log into your account and upload your file to a public folder in your server.
- If you are simply testing the file and do not want to purchase server space, then consider using XAMPP. XAMPP works on multiple platforms like Windows, Mac, and Linux. It will simulate a server-like environment on your personal computer.
- Download XAMPP. The application lets you host and edit PHP files directly on your computer. This is a good method for testing files that you are working on or building if you don’t want or need to rent server hosting.
- For Mac users, once your application has downloaded, run the .dmg file. Drag the XAMPP folder over to your Applications folder.
- For Windows users, either click “Run” when downloading or locate the .exe file and open it. Follow the installation steps to finish installing the software.
- Once you have started up XAMPP, you’ll have a few options. Click “Start” for Apache and MySQL. You may be prompted to enter your computer’s password if you have one setup. You can also choose to start FTP if you want to transfer files. But for testing purposes, you only need to start the first two options.
- Run your PHP file. Enter the file’s address into your web browser and hit “Enter.” This will execute the PHP file’s scripting.
- If you use a server host, then this will most likely be your domain name, followed by a forward slash, the public folder the file is in, and finally the file name. For example, “http://www.example.com/test/file.php”
- If you use XAMPP, then you need to enter “http://localhost” and then the file name. For example “http://localhost/file.php”
Tips
- If you were expecting a regular HTML webpage, then the PHP page you have most likely contains both HTML and PHP. In that event, you can simply rename the PHP file to contain a ".html" extension and open the file in a web browser. The page will not appear as it is intended to appear because the PHP programming code will appear when it shouldn't; however, you will be able to read the HTML content. If the PHP file is simply programming language and does NOT contain any HTML, then this will not work.
- Always save a copy of your original PHP file before making any changes. Editing the code incorrectly can cause your website to stop functioning. It's always best to have a backup.
Sources and Citations
- http://php.net/manual/en/intro-whatis.php
- http://windows.microsoft.com/en-us/windows/install-program#1TC=windows-7
- http://windows.microsoft.com/en-us/windows-8/choose-programs-windows-uses-default
- http://www.editrocket.com/
- http://www.phpknowhow.com/basics/running-php-files/
- https://blog.udemy.com/xampp-tutorial/