![]() |
Apache configuration files missing
I bought a new MacBook this weekend and I am new to the Mac OS. I do like most things about it though. My OS version is 10.4.8.
I am trying to set up my Apache server by using the config files (just to stress, I am not using the server edition of OS X). I got it activated through checking the box "Personal Web Sharing" under System Preferences -> Sharing and I can serve some basic pages this way. However I want to configure more than that, for example I want to change the default page from index.html to a python script. The resources I find that are supposed to tell me how to set this up, ask me to look for files like "httpd.conf" which Finder tells me I just don't have. Also a lot of the documentation files for Apache (found through Finder) have filenames like "configuring.html.html" with two html extensions instead of one. If I click on links within those documentation files (sending me to local files), I get "page not found" errors. I can fix those "page not found" errors by adding an extra .html to the end of the url. In general, nothing seems to be named what it's supposed to be named, and the tutorials I have found that talk about using Apache on OS X ask me to edit files that just are not there. Do I need to do an installation step to get these files like httpd.conf? Or is there some tutorial that will tell me how to configure the server based on the files that I *do* have? |
1) The Apache config file is /etc/httpd/httpd.conf
This file, being in the Unix-level part of the disk, is not visible via Finder. It is generally expected that anyone doing anything much past the basics with Apache will know how to do it via Unix-level commands. See this Unix FAQ for an introduction. 2) You might want to look at the O'Reilly articles on Apache with OS X: http://www.macdevcenter.com/pub/a/ma...ebserving.html |
Oh, I was accidentally saying "finder" when I meant "spotlight/mdfind."
Thanks for the information to just look directly for the file. The O'Reilly walkthrough was what I'd been looking at. |
Well I set up Spotlight so that it can index files in /etc, /usr, and /local. Thanks for pointing out that it was skipping files.
Maybe this is the wrong forum for this second question--if I want my default page to be generated by a python script, what is the best way to do it? Should I make my main page index.php and have some php bring up the script, or is there a more direct way? |
If you are familiar with webmin at all, you could look into using it. I perosnally do not use it on the mac platform but I use it on the linux platform all the time. I got tired of manually editing conf files with a text editor so I use it instead. I know they have an OS X version.
Basically it makes a nice little web based interface to configure your servers you run. I use it a lot to configure samba servers at work, since its so quick and easy. After you install it, you simply launch your favorite web browser (safari, or firefox, or whatever you use) and in the address bar type in localhost:10000 and you will have to authenticate to access all those files. Once you log in you can simply click on the icon of the server you wish to configure and start putting in your settings. Occasionally I do some things manually with a text editor but I do the bulk of the work in webmin. You can also choose what services to start when the machine boots too, like have it automatically run apache at start up. www.webmin.com |
Adding php as an apache module
I have spent a while trying various approaches to do this, none of them working because of a missing link, the wrong operating system, missing instructions, or whatever. I think that I have php installed right now, but I need to add it to Apache. Additionally I want Apache to serve index.php as a front page when I connect to localhost. How do I do this? I am new to both Apache and php.
OS: 10.4.8, client Edit: I am sure that there is a walkthrough that is not incomplete somewhere on the internet, so if you have any good links I'd love to hear them I know I need to add something like "AddType application/x-httpd-php .php" to httpd.conf but I have no file that looks like x-httpd-php. In a related issue, how do I get Nano to stop printing ^? every time I press ctrl-f to page down? (nevermind, ctrl-V does it) And is there a way I can open a document in TextEdit with administrative privileges? (sudo open -a TextEdit <doc> does not work) |
0rthodontist:
I merged your new thread into this existing one where you started your inquiries so as to preserve context. It would be good if you told us what you didn't understand or what didn't work with the O'Reilly tutorial series since they cover using PHP with Apache. And there is of course a lot of documentation available for Apache. You are expected to read it if you want to do more than the basics. Very little in Apache is specific to OS X, so any HOWTO or tutorial targeting Linux will be almost totally applicable to OS X as well. Let us know if there are some OS X-specific questions. Quote:
|
Ok, sorry. I had been looking at the O'Reilly walkthrough for general Apache configuration and did not think it covered PHP.
It says LoadModule in many places, but refers to the libexec directory, e.g. libexec/httpd/libphp5.so. Is this a problem? The actual directory of that file is /usr/libexec/httpd/libphp5.so. There is some problem. Right after the IfModule mod_php4.c clause, I added one that says: <IfModule mod_php5.c> AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps <IfModule mod_dir.c> DirectoryIndex index.html index.php </IfModule> </IfModule> This is the same as the mod_php4.c clause except I changed the 4 to a 5. It seems to already have the LoadModule and AddModule statements. Then I rebooted, and now I can't turn on "Personal Web Sharing" on system preferences. It says "WebSharing starting up" and doesn't do anything. |
I suspect that you can't have both PHP4 and PHP5 active at the same time - choose one.
In general, if you make any change to the httpd.conf file, you should test it with the command: apachectl configtest |
Oh, thanks, I missed deleting one of the ?'s that appeared from ctl-f :).
|
Quote:
|
Hmm... the DirectoryIndex line appears in 3 places in httpd.conf, twice as "DirectoryIndex index.html index.php" and once as "DirectoryIndex index.html". I changed the latter one to also say index.php, but the server still can't locate my index.php page even though I have no index.html page. Where can I look now?
|
Quote:
<IfModule mod_dir.c> DirectoryIndex index.html index.php index.htm index.php3 default.htm </IfModule> You are making backups of the httpd.conf file right? I learned that one the hard way. You also must restart Apache for changes to take effect, so if you just changed and saved the file without restarting it won't take. |
I have restarted my computer and started/stopped apache a couple times. What I have is
Code:
<IfModule mod_dir.c>DirectoryIndex index.html index.php on a line outside of any tags, and that also did not work. |
Quote:
EDIT: Further, by dragging it to TextWrangler or BBEdit, you can read and save httpd.conf. It's just a plain text file. |
Quote:
And I think if you have a directive specified more than once, it is the one that occurs latest (nearest the end of the file) that takes effect. When you say that "the server still can't locate my index.php page", you need to supply details: - where is your index.php file (in the file system) - what URL are you using to try to access it? - what does it say regarding that access attempt in the "access_log"? - anything in the "error_log"? It is impossible to develop a programmatically-driven web site without constant referral to the log files. You can most easily access the Apache logs with the "Console" application (under /Applications/Utilities) |
My index.php is located in my Documents directory, /Library/WebServer/Documents, which I have linked to ~/docs. Previously I put an index.html in the same place and that worked fine. When I type localhost into my browser, I get the standard Apache test page for installation, the same as if I have neither index.html nor index.php. When I type localhost/index.php into my browser, I get the correct page with no problems.
Now, based on the logs, it appeared that my browsers were caching a lot of stuff, though they didn't get the right page when I hit refresh either. But the browser cache is not the problem, since I just did a "reset Safari" which should clear everything including cache, and /localhost still gives me that test page. Here's the log from that last access: Code:
127.0.0.1 - - [01/Dec/2006:22:09:19 -0500] "GET / HTTP/1.1" 200 1456By the way, does Mac OS X have a built-in packet capture utility somewhere? I want to see messages received from localhost as well as messages sent to localhost. Or would that not even work because I am not using a network interface to make these requests? |
Quote:
Or install Ethereal (runs under X11) It might also be useful to try using 'curl' (in a Terminal window) to look at the HTTP transactions - e.g. with the "-I" and "-L" options. |
Note also that with URLs, it matters if you have a slash at the end or not.
The URL http://localhost is different from http://localhost/ The former will normally redirect to the latter |
tcpdump says "tcpdump: no suitable device found" and quits.
Code:
$ curl -IL localhostOK, I got it working (sort of). What I did was move all of the files except index.php out of my web documents directory. Now, localhost serves me index.php, having no way to weasel out of the deal. But how do I set it so that it does that anyway, even with all the other pages present? Maybe the DirectoryIndex list is treated as a bunch of wildcard searches, like index.html is interpreted as index.html*. |
You are hitting on two things:
1) Apache conforms to the HTTP/1.1 spec for content negotiation (http://httpd.apache.org/docs/1.3/con...gotiation.html) which means that when the browser specifies a preference for English documents, Apache will prefer index.html.en to index.html 2) The DirectoryIndex directive gives a prioritized list of files to be used when a directory URL is received: http://httpd.apache.org/docs/1.3/mod/mod_dir.html As I said earlier, you really do need to read the docs if you are doing anything out of the ordinary. |
Quote:
|
Quote:
WHY you'd want both of them at once is another issue. Orthodontist: how did you get PHP5, and are you sure PHP is working? Create a file in the /Library/Webserver directory called "phpinfo.php" containing the following: Code:
<p>File loaded. Gobs of PHP info following if PHP is running.</p>http://localhost/phpinfo.php |
| All times are GMT -5. The time now is 07:13 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.