PDF download Download Article PDF download Download Article

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

PDF download Download Article
  1. XAMPP is one of the most popular PHP-testing environments for both Windows and Mac computers.
  2. This will allow you to update the "htdocs" folder without interfering with existing processes.
    • Skip this step on a Mac.
    Advertisement
  3. 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.
  4. Click or double-click the XAMPP app icon, which resembles a white "X" on an orange background.
  5. 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.
  6. 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. You can use any web browser (e.g., Chrome) to test your PHP scripts.
  8. It's at the top of the browser.
    • If there's any text in the address bar, delete it before proceeding.
  9. 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. 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

PDF download Download Article
  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:
    • 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.
  2. Click once anywhere in the document, then press Ctrl + A (Windows) or ⌘ Command + A (Mac) to select the entire document.
  3. Press either Ctrl + C (Windows) or ⌘ Command + C (Mac) to do so.
  4. Go to http://sandbox.onlinephpfunctions.com/ in your computer's web browser.
  5. 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. 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. 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. 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

Expert Q&A

Ask a Question
      Advertisement

      Tips

      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Name
      Please provide your name and last initial
      Thanks for submitting a tip for review!

      Expert Interview

      Thanks for reading our article! If you’d like to learn more about programming, check out our in-depth interview with Tyrone Showers .

      About This Article

      Thanks to all authors for creating a page that has been read 28,253 times.

      Is this article up to date?

      Advertisement