How do you get php working on Mac OS X?

Viewed 86823

I have recently updated to Lion and enabled Web Sharing in the System Preferences but I am unable to get php working.

I added an info file to the web root directory and it outputs the file as text.

info.php
with the content
<?php phpinfo(); ?>
6 Answers

For the latest version of mac os i.e Mojave 10.14, follow the steps below to activate PHP server:

  1. Open terminal. Press command+spacebar, type terminal and press enter.

  2. Enter command $ sudo nano /etc/apache2/httpd.conf to edit httpd.conf file in nano, which is an inbuilt file editor in macOS.

  3. Enter the password.

  4. Now search loadmodule by pressing control+w.

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

  6. Uncomment the file by removing the # symbol 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 changes to the httpd.conf file.

  8. Now restart the apache server by entering the command

    $ sudo apachectl restart

  9. PHP server should be running now running.

Now you can check the working of your server by opening the PHP file from your default server directory or you can also change the directory as well.

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

I was not able to open any PHP files in my browser. I followed the above steps and it resolved the issue.

Note - In OSX 10.14.5 there is Php7.1.23

Steps I followed -

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

LoadModule php7_module libexec/apache2/libphp7.so

  1. sudo apachectl restart

Thank you for the solution, appreciated your help friends.

Regards,

Vicky Jadhav (India - pune)

Related