Open PHP file on Mac

PHP 5 is installed in macOS / OS X by default, but the built-in Apache web server may not be configured to automatically run PHP. To enable PHP, the apache configuration file needs to be modified. This file is located in the following location:


In order to edit this file, the permissions on the file must be changed. This can be accomplished by doing the following:

1. Open a terminal windows (Applications -> Utilities -> Terminal)

2. Change to the correct directory (cd /etc/apache2)

3. Change the permissions on the file (sudo chmod 755 httpd.conf)

Once the file permissions are changed, you can use a tool like EditRocket to open the httpd.conf file and modify it. After opening the httpd.conf file, we need to look for the following line:

#LoadModule php5_module libexec/apache2/

This line needs to be uncommented by removing the # in front of the line. Remove the # and then save the file.

PHP is now enabled, but we need to restart the apache web server for the changes to take effect. To restart the web server, do the following:

1. Go to System Preferences -> Sharing View

2. Uncheck the Web Sharing box. Then check the Web Sharing box again. This will start and stop the apache web server.

The macOS / Mac OS X operating system comes pre-installed with the libraries needed to run PHP programs. You can interact with PHP programs via the Terminal application (Applications -> Utilities -> Terminal). You can also use the built-in web server that comes with Mac, the Apache web server, to execute PHP programs. For more information on running PHP via the local web server, see the following:

Running PHP on Apache for Mac

PHP programs can be created using any text editor such as EditRocket. PHP programs and scripts typically end with the .php extension. EditRocket will automatically recognize files with the .php extension as PHP programs, and will color the syntax accordingly.

To create a PHP program, simply create a new file, such as hello.php. In the file, place the following:

The above program can be executed using the EditRocket Tools -> PHP -> Execute Program option, or you can execute it from the Terminal window. To execute the script in the Terminal, use the cd command to cd to the directory where the hello.php file was saved, such as

What am I massing here? A .php file is not a movie or sound file. It's script (text I believe). It's on the server. Even if you downloaded it you couldn't do anything with it other than steer at the code (text). Wiki has as good a definition as any as to what php files are.

I would assume that when you click on a php link on a web site it cause code on the server to do what is instructed by that script. If it's to play a movie or sound or whatever that that is what the script is instructing the server to do.

If you clicked on a link and got the error you saw in your first post then there is a problem with that web page's html (another scripting language) and it's access to executing the .php file.

Some references:

Learn PHP - A Beginner's Guide to PHP Programing

Your first PHP-enabled page

I guess the answer to your original question in the title of this thread -- how do you open .php files? -- you don't.

Recently I got the source code of a simple PHP website. Obviously I’m not a PHP developer. However, I’m curious on how to launch the website on my MacBook. In searching, I found a simple way to launch a PHP website on macOS using its in-built PHP server. This may not be a solution for someone to develop and debug PHP websites. But, it will help you to check basic PHP websites and web pages.

Tools Used

  • PHP 7
  • macOS Big Sur

Start the PHP server

First, start the inbuilt PHP server by following these steps:

  1. In the finder, go to the folder with the php website code.
  2. Right click the folder. From the popup menu, select the option New Terminal at Folder to launch the terminal window for the folder.
  3. In the terminal window run the command php -S localhost:9000.
  4. The server starts listening to http://localhost:9000. Just leave the terminal window without disturbing it. Once you close the terminal, the server will stop running.

Launch the PHP website

Now, go to any browser and run the address http://localhost:9000/. If the folder has an index.php file, then it will load the webpage. Else, you have to add the webpage name to the url like http://localhost:9000/something.php.

Shutting down the PHP server

Go back to the terminal window and press Ctrl + C buttons to shut down the PHP server. Then you can quit the terminal.

How do I use PHP on Mac?

How to Install PHP on a Mac.
of 04. Enable Apache on MacOS. To enable Apache, open the app, which is located in the Mac's Applications > Utilities folder. ... .
of 04. Enabling PHP for Apache. Make a backup of the current Apache configuration before you begin. ... .
of 04. Verify That PHP Is Enabled. ... .
of 04. Additional Apache Commands..

How do I open a PHP file in Chrome Mac?

How to run a PHP file in Chrome in 2021.
Starting XAMPP Control Panel..
How to run a PHP file: XAMPP Control Panel View..
Start Apache and MySQL in XAMPP..
Apache and MySQL running in XAMPP..

How to open PHP file in browser?

php” file is placed inside the “htdocs” folder. If you want to run it, open any web browser and enter “localhost/demo. php” and press enter. Your program will run.

How to open a PHP file?

Go to the location of your PHP file, then click the PHP file to select it. Click Open. It's in the bottom-right corner of the window. This will open the PHP file in Notepad++, allowing you to view the file's code and make any necessary edits.