Apache and PHP

Joined
Sep 23, 2011
Messages
2
Reaction score
0
Points
1
I'm trying to run a .php file using localhost web server and i can't get it to work. I have OS X 10.6.8. I believe Apache and PHP are already installed. I have enabled File Sharing and Web Sharing under System Preferences. When I type, localhost, into my browser, I get "It works!" So I got that part working. I have placed my .php file under /myusername/Sites/file.php. So, when I type localhost/myfile.php into my browser, shouldn't I get the output of that code that I put into my .php file? Instead, I get

"Not Found The requested URL /hello.php was not found on this server."

I think I'm missing a step. Can anyone help?

Thanks
 
Joined
May 22, 2005
Messages
2,159
Reaction score
67
Points
48
Location
Closer than you think.
Your Mac's Specs
Performa 6116 2GBSCSI 8MB OS 7.5.3
You might need to uncomment the PHP module in the Apache conf files for the web server.

Also be sure that the permissions on the PHP files are appropriate.
 

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)
To enable PHP:

Edit the file /private/etc/apache2/httpd.conf and uncomment (remove the # at the beginning) line 111 which looks like the following:
Code:
#LoadModule php5_module libexec/apache2/libphp5.so
You'll need elevated privileges to do that so you might want to use something like nano or vim from the command line but open it through sudo:
Code:
sudo nano /private/etc/apache2/httpd.conf
That will enable PHP but I just noticed a secondary problem. You're putting files in ~/Sites which means that to access it through a browser, you need to navigate to http://localhost/~<username>/hello.php (replace <username> with your user name).
 

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