How to Run a PHP File in a Browser
How to Run a PHP File in a Browser
This wikiHow will teach you how to run a PHP script in your web browser using a free web server called MAMP. Unlike a regular HTML file, you can't just double-click a PHP file to run a script in your browser. Web servers like MAMP will translate your code to something that can be interpreted appropriately by any web browser on your computer.
Steps

Go to https://www.mamp.info/en/downloads. MAMP is a free, local server environment that you'll need to use to see PHP in your web browser.

Click the download link for your operating system. If you're using a Windows PC, you'll run the downloaded file, then follow the installer wizard install MAMP. If you're using a Mac, you'll run the downloaded file, then drag-and-drop the MAMP file icon to your Applications folder.

Open MAMP. You'll find this program in your Start Menu or Applications folder in Finder once it's installed.

Click Preferences. This grey gear icon is on the left side of the window that opens when you launch MAMP.

Check that all the defaults are set correctly. Click through the tabs on the top and check to make sure the information is listed similarly so your server works. In the Start/Stop tab, make sure "Start Servers" and "Open WebStart Page" are checked under "When starting MAMP." "Stop servers" should be selected under "When quitting MAMP." On the Ports tab, enter 8888 in the text field next to "Apache Port," "Nginx Port," and 8889 in the text field next to "MySQL Port." On the PHP tab, select "7.1.1" if it's not already selected. On the Web Server tab, select "Apache" if it's not already selected.

Map to your folder that contains the PHP file. You can have multiple PHP files in that folder, but make sure you map a folder instead of a file by dragging and dropping the folder from your file browser. For example, you can open your file browser and navigate to your PHP file, navigate one folder back, then drag-and-drop it in the open window. You'll have MAMP set to the folder that your PHP file is inside, not the file ending in .PHP.

Click OK to apply your changes to preferences before continuing. This might take about 20 seconds.

Click Start Servers. This power icon button is toward the right side of the window that opens when you launch MAMP. Enter your computer password and username when prompted to continue.

Open your browser. You can use any browser to preview your PHP file.

Navigate to "localhost:8888" in your browser's address bar. The address bar is where you normally see "https://www." To do this, type "localhost:8888" and press ↵ Enter (Windows) or ⏎ Return (Mac). You'll see a directory of your PHP files displayed on the page.

Click the PHP file to run the script in your browser. Your PHP file now run and display its output in the browser window.

What's your reaction?

Comments

https://popochek.com/assets/images/user-avatar-s.jpg

0 comment

Write the first comment for this!