1

Background: I want to learn PHP and in the tutorial that I'm doing, one of the first things it has you do after getting PHP and mySQL going is to to test it by making a phpinfo.php file and opening it.

Problem: In FireFox, the file loads a blank page. In Safari it only shows the code that I wrote: <?php phpinfo(); ?>.

Steps so far (not necessarily in order): I followed the steps at http://coolestguidesontheplanet.com/how-to-install-php-mysql-apache-on-os-x-10-6/
I have made a phpinfo.php file using text editor in plain text mode (as opposed to rich text) and saved that in my "sites" folder. This is the only line in that file:
<?php phpinfo(); ?>
In system preferences, I have web sharing turned on and mySQL server running. I have removed the # from in front of the load php 5 module line in the httpd.conf file as per the tutorial I mentioned. I've tried restarting the web server using "sudo apachectl restart" and then restarting Firefox.

I looked for a php.ini file in my etc folder. There wasn't one but I did find a php.ini.default. I duplicated that file and renamed the duplicate to php.ini. I'm not sure this step was a correct step to take but from the little I could find on the internet it looks like somebody else has done this and I thought, why not?. (phpinfo.php loaded a blank page before and after this step)

I typed php -i | grep php.ini into terminal and got the following:
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /private/etc/php.ini
and a timezone warning

So I decided to look for a php.ini in the /private/etc folder and there is one there. ( The one I created was in the /etc folder not the /private/etc folder.)

I have searched the internet including this website for answers.

System info:
When typing php -v into terminal it tells me that I am using PHP 5.3.28 When typing mysql -v into terminal it tells me that I am using mySQL 5.6.10 I am running Mac OS 10.7.5 on a Macbook Pro.
FireFox version: 40.0.3
Safari version: 6.1.6

Questions:
1) Did I correctly create the php.ini file?
2) What am I missing? Why is the phpinfo file not loading in my browser?
3) Is the timezone warning important?

newbie
  • 35
  • 1
  • 1
  • 6
  • 1
    Have you started apache? – Disha V. Sep 24 '15 at 05:10
  • Please find a more up to date tutorial that uses php 5.6 - Eg: http://justinhileman.info/article/reinstalling-php-on-mac-os-x/ . Don't get started with PHP using a PHP version that's years out of date. – Scopey Sep 24 '15 at 05:13
  • I typed 'sudo apachectl start' and received the message "already loaded" I think the way to start it is via turning "web sharing" on in system preferences which I did. – newbie Sep 24 '15 at 05:14
  • Try `xampp` for all in one preconfigure package for php : `https://www.apachefriends.org/index.html` – Indrasinh Bihola Sep 24 '15 at 05:15
  • Would using an outdated php version cause the problems i'm having? Seems like I tried mamp a long time ago when I thought I was going to learn php back then. I might give it a try again, I can't remember much about it, but again do you think this would solve the problem I'm having? – newbie Sep 24 '15 at 05:20
  • No that's not a problem but I think you should not spend too much time in configuration unless it's necessary. – Indrasinh Bihola Sep 24 '15 at 05:28
  • I wasn't accessing phpinfo.php through my web-server by typing in the localhost name. I was simply dragging the file into firefox which gave the file path of file:///users/... Thanks @Dagon for pointing me to the correct answer. – newbie Sep 24 '15 at 05:44
  • Nginx is better... http://blog.frd.mn/install-nginx-php-fpm-mysql-and-phpmyadmin-on-os-x-mavericks-using-homebrew/ – Elias Nicolas Sep 24 '15 at 05:52

1 Answers1

0

Make sure that your source code file has the .php extension in the end.

If you can see the code of your php file in your browser, probably your apache server is not started or it is not working properly. To set your development environment quickly, I recommend that you download an "all in one package" such as XAMPP server or WAMP server. It comes with everything that you need to get your php project working and it is very easy and quick to install.

Take a look at: https://www.apachefriends.org/index.html

Once you have installed the package, create a folder for your project and put your php file inside it. So, copy your project folder to "htdocs" folder, inside the WAMP or XAMPP path, open your browser and type the URL:

http://localhost/yourProjectFolder/phpinfo.php

You shall see your php file working on.

Good luck!

David Toledo
  • 484
  • 6
  • 13
  • Dagon marked this question as a duplicate and I found the answer to my question there. I wasn't typing in the correct URL. I wasn't typing in my localhost name. I was simply typing the file path. Thanks for your advice as well. – newbie Sep 24 '15 at 05:47