How to make php work on Mac OS X?

I recently updated Lion and turned on web access in the system settings, but I can't get php to work.

I added the information file to the root directory of the website and it displays the file as text.

info.php with the content <?php phpinfo(); ?> 
+52
php osx-lion macos
Jul 22 '11 at 13:17
source share
6 answers

(Edit: this method works fine for 10.9 (Mavericks), 10.10 (Yosemite) and 10.11 (El Capitan), so I decided that I mentioned that for any new influx of slightly disappointed OS X: D updates)

Edit the file / etc / apache 2 / httpd.conf and verify that the line:

 LoadModule php5_module libexec/apache2/libphp5.so 

... exist. I think it was commented out by default in the standard OS X configuration, but from what I remember, you just need to uncomment it and then restart Apache:

 sudo apachectl restart 

And you should be good to go.

+106
Jul 22 '11 at 13:25
source share

UPDATE: Please note that this was written for OS X pre- (High) Sierra. If you are using OSX 10.12 or later, please follow this excellent Andy Miller guide: macOS 10.13 High Sierra Apache Setup: several versions of PHP




I also like to use things that basically already exist. I don’t understand why someone would use MAMP or AMPPS (or any other packaged third-party web server application) when Mac OS X comes with apache and PHP by default.

It took me a few tries to get it to work, so here is basically what did it for me, and hopefully this helps you guys save some time.

As Matt Gibson said, start the terminal and type: (sudo requires your root password)

 sudo nano /etc/apache2/httpd.conf 

Then uncomment this line by removing the β€œ#” character in front of it (Ctrl + V can be used as a page down).

 LoadModule php5_module libexec/apache2/libphp5.so 

To make sure you can include files, etc. In PHP, highlight "User _www" (in my case) and change it to: (where "yourusername" is the user you are logging in with)

 User yourusername 

You can leave the group as is, Group _www by default with a new installation of OS X Mountain Lion.

By default, apache only searches index.html, so look for "DirectoryIndex index.html" and change it to: (adding index.html at the end is optional, of course)

 DirectoryIndex index.php index.html index.htm 

Exit and save by pressing Ctrl + X (and confirm by pressing "y")

Then restart Apache:

 sudo apachectl restart 

My phpinfo (); returns with PHP version 5.3.15

===================

Since I find it useful to have my local sites in my user directory, I created the directory / Users / yourusername / Sites (which is no longer the default in Mountain Lion).

Edit httpd.conf again through "sudo nano / etc / apache2 / httpd.conf" and ...

Scroll down to "DocumentRoot" and change it to: (where "yourusername" is the name of the user you are logging in with)

 DocumentRoot "/Users/yourusername/Sites/" 

Scroll to where it says: "# This should be changed to what you set for DocumentRoot." and change the following line to: (where "username" is the name of the user you are logging in with)

 <Directory "/Users/yourusername/Sites/"> 

Then exit and save by pressing Ctrl + X (and confirm by pressing "y")

Restart Apache.

+26
Mar 29 '13 at 21:31
source share

I have one word for you. MAMP .

+4
Jul 22 '11 at 13:23
source share

Try phpbrew

This makes it easy to build, install the tool for PHP, any version.

+2
Mar 26 '13 at 23:26
source share

For the latest version of Mac OS, i.e. Mojave 10.14, follow these steps to activate the PHP server:

  1. Open a terminal. Press Ctrl + Space, type terminal and press Enter.

  2. Enter the command $ sudo nano/etc/apache2/httpd.conf to edit the httpd.conf file in nano, which is the built-in file editor on macOS.

  3. Enter password.

  4. Now find the boot module by pressing control + w.

  5. Find a file named #LoadModule php7_module libexec / apache2 / libphp7.so

  6. Uncomment the file by removing the # symbol, which is present at the very beginning of the module.

  7. Now exit the editor by pressing control + x, press y to save the changes, and press enter to confirm the changes in the httpd.conf file.

  8. Now restart the Apache server by entering the command

    $ sudo apachectl restart

  9. PHP server must be running.

Now you can check the operation of your server by opening the PHP file from the default directory of your server, or you can also change the directory.

0
Oct. 13 '18 at 5:28
source share

After upgrading MAC OSX to 10.14.5, my Apache configuration file was new and all of my previous settings were replaced with the default settings.

I was unable to open any PHP files in my browser. I followed the above steps and this solved the problem.

Note. OSX 10.14.5 has Php7.1.23.

The steps I followed

  1. Edit the httpd.conf file located in /etc/apache2/httpd.conf
  2. This below is given live was commented. I uncommented it by removing the # sign, saved the httpd.conf file, and restarted the apache service.

LoadModule php7_module libexec / apache2 / libphp7.so

  1. restart sudo apachectl

Thanks for the decision, friends appreciated your help.

With respect,

Vicki Jadhav (India - Pune)

0
Jun 04 '19 at 15:25
source share



All Articles