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.

Method 1
Method 1 of 2:

Using XAMPP

  1. 1
    Make sure you have XAMPP installed. XAMPP is one of the most popular PHP-testing environments for both Windows and Mac computers.
  2. 2
    Close 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
  3. 3
  4. 4
    Open XAMPP. Click or double-click the XAMPP app icon, which resembles a white "X" on an orange background.
  5. 5
    Start 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]
  6. 6
    Note 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".
  7. 7
    Open a web browser. You can use any web browser (e.g., Chrome) to test your PHP scripts.
  8. 8
    Click the address bar. It's at the top of the browser.
    • If there's any text in the address bar, delete it before proceeding.
  9. 9
    Enter 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.
  10. 10
    Press 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.
  11. Advertisement
Method 2
Method 2 of 2:

Using Online PHP Functions

  1. 1
    Open your PHP document. You'll use your computer's PHP-editing software (e.g., Notepad++ on Windows or BBEdit on Mac) to do so:
  2. 2
    Select your document's contents. Click once anywhere in the document, then press Ctrl+A (Windows) or Command+A (Mac) to select the entire document.
  3. 3
    Copy the contents. Press either Ctrl+C (Windows) or Command+C (Mac) to do so.
  4. 4
    Open the Online PHP Functions site. Go to http://sandbox.onlinephpfunctions.com/ in your computer's web browser.
  5. 5
    Paste 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.
  6. 6
    Select 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.
  7. 7
    Click 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.
  8. 8
    Review 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.
  9. Advertisement

About This Article

Jack Lloyd
Written by:
wikiHow Technology Writer
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.
How helpful is this?
Co-authors: 5
Updated: January 31, 2021
Views: 16,383
Advertisement