Enabling PHP

Joined
Mar 10, 2009
Messages
5
Reaction score
0
Points
1
I can't seem to get php to work.

I was following a tutorial for php when I opened this file in my browser (called index.php):

Code:
<html>
 <head>
  <title>PHP Test</title>
 </head>
 <body>
 <?php echo "<p>Hello World!</p>"; ?> 
 </body>
</html>

It either displays all of the text in the file, or:
Code:
Hello World!
; ?>

I googled mac tutorials for php, and found that it needed to be enabled, so I followed the instructions, took out the comment in the /private/etc/apache2/httpd.conf file, but it still doesn't seem to work.

So basically I'm lost.

What am I doing wrong? I'm sure it's something really simple...
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
Simple instructions:
1. Turn on Web Sharing in System Preferences
2. Open /Applications/Utilities/Terminal.app
3. Execute the following in the Terminal: sudo nano /private/etc/apache2/httpd.conf
4. Scroll down to the following line: LoadModule php5_module libexec/apache2/libphp5.so (second last LoadModule line for me)
5. Uncomment it by removing the # at the beginning
6. Save that by pushing CTRL-O and then exit by pushing CTRL-X
7. Type the follwing command: sudo apachectl restart
8. Enjoy php

Let me know if you encounter any problems.
 
OP
I
Joined
Mar 10, 2009
Messages
5
Reaction score
0
Points
1
I did all of that except the "sudo apachectl restart" part - could that really be the only problem?
 
OP
I
Joined
Mar 10, 2009
Messages
5
Reaction score
0
Points
1
It seems to be working. All I had to do was run sudo apachectl restart.

Thanks a lot!
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
I did all of that except the "sudo apachectl restart" part - could that really be the only problem?
In case you're still wondering, yes that's the culprit. If you make changes to apache's config file (and many other programs), you have to restart them for the changes to take effect.

Best of luck with PHP!
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top