Sky
Sky

Reputation: 7711

How to configure PHP on Mac for developing

I'm doing the installation for PHP on Mac, following this tutorial .

I checked my httpd.conf, which is a little different from mine for the following items.

  1. Load Module php5_module

  2. AddModule mod_php5.c AddType

  3. application/x-httpd-php .php

What I have is Load Module php4_module, I don't have the item 2 and item 3, so I added these to my httpd.conf file. But after I restart my apache server with apachectl restart, it says that This webpage is not available. I checked the console of Chrome and found this GET http://localhost/info.php net::ERR_CONNECTION_REFUSED.

And I also found that:

Anyone knows what's going on here? Did I miss any more configuration?

By the way, it will be grateful if you can provide a proper tutorial for beginner to set up the envrionment for learning PHP, just found so many articles online, but no one can work correctly.

Upvotes: 0

Views: 230

Answers (4)

kd4ttc
kd4ttc

Reputation: 1203

Update: 6/26/2019

There have been a few changes in PHP and Apache since the other answers were written. Currently php7 has defaults built in. They are documented in the file php.ini.default. That file is not read by the PHP engine because the suffix .default hides the file from the PHP engine. If you want to change the PHP configuration then rename php.ini.default to php.ini. found at

/etc/php.ini.default

Apache just requires 2 things. Open the file

/etc/apache2/httpd.conf

Uncomment the line

LoadModule php7_module libexec/apache2/libphp7.so

and add the following to http.conf

# Set Apache to hand off php files the the PHP processor
<IfModule php7_module>
<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>
</IfModule>

I put mine in the Supplemental configuration section near the end of the file.

Upvotes: 0

Sky
Sky

Reputation: 7711

Thanks for all your help. I found one useful tool to set up PHP environment quickly. It is XAMPP, which is really easy to set up the environment. Now I can start learning PHP freely. But, of course, I will study the configuration about all of this after I have a basic knowledge of PHP.

Thanks again for all your kindly help, hope will discuss with you later in the details.

Upvotes: 0

heiglandreas
heiglandreas

Reputation: 3861

Have a look at akrabats tutorials on how to install PHP on a mac. You can find the one for Maverics at http://akrabat.com/setting-up-php-mysql-on-os-x-mavericks/ and there is also one for yosemite.

Alternatively you could use homebrew or phpbrew to install php beneath the one delivered with MacOS as they are updated more frequently.

And there is also a third was by using the PHP-installer provided by liip at http://php-osx.liip.ch

Besides that I'd definitely recomend having a look at VirtualBox and Vagrant as lots of PHP-projects provide a vagrantfile to ensure all developers have identical development-environments. But that's a totaly different story!

Upvotes: 1

maharg101
maharg101

Reputation: 527

If your intention is to learn PHP, regardless of the underlying OS, I would recommend that you install VirtualBox and install Linux so that you can follow any of the many 'LAMP on linux' tutorials e.g. http://community.linuxmint.com/tutorial/view/486

This will probably be more straightforward to get up and running, and won't pollute your Mac environment to the same degree.

Upvotes: 0

Related Questions