How to Run a PHP File in a Browser

How to Run a PHP File in a Browser thumbnail
To view a PHP page, you need to enter its address in a browser or follow a link to its location.

Unlike static HTML pages, you cannot view the Web page created by a PHP script simply by opening the file in a browser. PHP scripts must be saved on a Web server with PHP facilities, and you must then browse to it by entering the Web address in your browser's address bar, or by following a link to the same location. When you browse to a PHP page, this causes programming code to be executed on the server, and the resulting HTML page to be written out for viewing.

Instructions

    • 1

      Create your PHP page. If you have not already done so, create a PHP page by opening a new file in a text editor or IDE (integrated development environment) and saving it using .php extension. Use the following outline structure:

      <html>

      <head></head>

      <body>

      <?php

      echo "Page content";

      ?>

      </body>

      </html>

    • 2

      Place your PHP file on your server. If you are not ready to put it on a Web server, you can download and install a free server system such as XAMPP, which you can run on your own PC to test your PHP pages. Whether you're using a server on your own computer or on the Web, put your PHP file in the location you want it to be accessible from. For Web servers you will need to make an FTP connection using a program such as FileZilla or your Web host control panel.

    • 3

      Browse to the location of your PHP page in your Web browser. Type the address into your browser address bar. If you placed your file in the root directory, the address will have the following structure, using your own domain and file name:

      http://yourdomain.com/yourfile.php

      If your PHP file is in a sub-directory, its location will have the following structure:

      http://yourdomain.com/directoryname/yourfile.php

      If your PHP file is running on a local server installed on your own computer, the location will have the following structure: http://localhost/yourfile.php

    • 4

      Test the functionality of your page. The details of how you test your PHP will depend on its purpose. Check first that the content is all appearing and is structured correctly in HTML. If necessary you can view the source of your HTML page using your browser menus. If your page contains user controls, test these thoroughly to ensure it functions as you need it to.

Tips & Warnings

  • If you have a local server installed on your computer, you may need to manually start it running before PHP scripts will work on it. Check any instructions included with the download.

Related Searches:

References

Resources

  • Photo Credit Hemera Technologies/Photos.com/Getty Images

Comments

You May Also Like

Related Ads

Featured