X
This article was co-authored by wikiHow staff writer, Jack Lloyd. Jack Lloyd is a Technology Writer and Editor for wikiHow. He has over two years of experience writing and editing technology-related articles. He is technology enthusiast and an English teacher.
This article has been viewed 16,383 times.
Learn more...
This wikiHow teaches you how to test your PHP scripts for errors and functionality. The most practical way to do this is by running your PHP scripts in your computer's web browser via XAMPP, but you can also use a free online service called "Online PHP Functions" to look for errors in your PHP code.
Steps
Method 1
Method 1 of 2:
Using XAMPP
-
1Make sure you have XAMPP installed. XAMPP is one of the most popular PHP-testing environments for both Windows and Mac computers.
- You can download and install XAMPP for free.
-
2Close XAMPP if it's running. This will allow you to update the "htdocs" folder without interfering with existing processes.
- Skip this step on a Mac.
Advertisement -
3Place your PHP files in the "htdocs" folder. Depending on your operating system, do one of the following:
- Windows — Open "This PC", double-click your hard drive's name, double-click the "xampp" folder, double-click the "htdocs" folder, and move any necessary PHP files into the folder.
- Mac — Click the Volumes tab in the XAMPP control panel, click Mount, click Explorer, double-click the "htdocs" folder, and move any necessary PHP files into the folder.
-
4Open XAMPP. Click or double-click the XAMPP app icon, which resembles a white "X" on an orange background.
-
5Start Apache. Click Start to the right of the "Apache" heading to start your Apache web server. You should see the indicator to the right of "Apache" turn green. If you encounter an error and Apache doesn't start, do the following:[1]
- Click Config next to the "Apache" heading, then click Apache (httpd.conf) in the resulting menu.
- Find the "Listen 80" line and replace "80" with "8080".
- Find the "Server name localhost: 80" line and replace "80" with "8080".
- Press Ctrl+S (Windows) or ⌘ Command+S (Mac) to save your changes, then close the file.
-
6Note Apache's second port. This is the port to the right of the first port number.
- If you edited the "httpd.conf" file, the second port should be "8080".
-
7Open a web browser. You can use any web browser (e.g., Chrome) to test your PHP scripts.
-
8Click the address bar. It's at the top of the browser.
- If there's any text in the address bar, delete it before proceeding.
-
9Enter the address of the PHP script you want to check. Type in localhost: and your Apache server's second port number (e.g., 8080), then type a slash (/) and enter the name of the PHP document you want to test (e.g., index.php).
- For example, to test a script called "LandingPage" on port 80, you would type in localhost:80/landingpage.php here.
- Make sure you include ".php" at the end of the address.
-
10Press ↵ Enter. Doing so will load your PHP script in your browser. If the script is working, you should see the page load without any problems.
- If your script has errors, they will manifest in a number of different visual ways. Look for elements of your page that failed to load correctly to discern errors.
Advertisement
Method 2
Method 2 of 2:
Using Online PHP Functions
-
1Open your PHP document. You'll use your computer's PHP-editing software (e.g., Notepad++ on Windows or BBEdit on Mac) to do so:
- Right-click the PHP document (or, on a Mac, click the document and then click File).
- Select Open With.
- Click your PHP-editing program's name.
-
2Select your document's contents. Click once anywhere in the document, then press Ctrl+A (Windows) or ⌘ Command+A (Mac) to select the entire document.
-
3Copy the contents. Press either Ctrl+C (Windows) or ⌘ Command+C (Mac) to do so.
-
4Open the Online PHP Functions site. Go to http://sandbox.onlinephpfunctions.com/ in your computer's web browser.
-
5Paste in your copied code. Select the code in the "Your script" window, then press either Ctrl+V (Windows) or ⌘ Command+V (Mac) to replace it with your copied code.
-
6Select a PHP version. Click the "Run on PHP version" drop-down box below the "Your script" window, then click your PHP version number in the drop-down menu.
- As of October 2018, the most recent version of PHP that is supported by Online PHP Functions is version 7.2.4.
-
7Click Execute code. It's below the "Run on PHP version" drop-down box. Doing so runs your PHP code and displays the results in the "Result" text box below the Execute code button.
-
8Review any errors. In the "Result" text box, you should see your code's appearance. If there are any errors in the code, they will appear in between "<br \>" tags.
- Each error will be reported as belonging to a specific line (e.g., "on line 2"). You can view each line's number by looking on the left side of the "Your script" window.
- Errors will also appear as red-and-white "X" icons to the left of the pertinent lines in the "Your code" text box.
Advertisement
References
About This Article
Advertisement