The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   Networking (http://hintsforums.macworld.com/forumdisplay.php?f=14)
-   -   Apache configuration files missing (http://hintsforums.macworld.com/showthread.php?t=64028)

0rthodontist 11-28-2006 07:37 PM

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?

hayne 11-28-2006 07:45 PM

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

0rthodontist 11-28-2006 08:29 PM

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.

0rthodontist 11-28-2006 08:50 PM

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?

tlarkin 11-28-2006 09:24 PM

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

0rthodontist 12-01-2006 03:32 PM

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)

hayne 12-01-2006 04:17 PM

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:

Originally Posted by 0rthodontist
is there a way I can open a document in TextEdit with administrative privileges? (sudo open -a TextEdit <doc> does not work)

I recommend against using TextEdit for Unix config files. Instead use one of the other available text editors - e.g. TextWrangler (which has specific support for editing files owned by root)

0rthodontist 12-01-2006 04:51 PM

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.

hayne 12-01-2006 05:00 PM

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

0rthodontist 12-01-2006 05:06 PM

Oh, thanks, I missed deleting one of the ?'s that appeared from ctl-f :).

hayne 12-01-2006 05:09 PM

Quote:

Originally Posted by 0rthodontist (Post 338627)
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.

I think the paths are taken relative to 'ServerRoot' (which is "/usr")

0rthodontist 12-01-2006 06:50 PM

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?

schwartze 12-01-2006 07:07 PM

Quote:

Originally Posted by 0rthodontist (Post 338659)
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?

Here:
<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.

0rthodontist 12-01-2006 07:12 PM

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
</IfModule>

# ... (large amount of omitted text here) ...

<IfModule mod_php4.c>
    # If php is turned on, we repsect .php and .phps files.
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps

    # Since most users will want index.php to work we
    # also automatically enable index.php
    <IfModule mod_dir.c>
        DirectoryIndex index.html index.php
    </IfModule>
</IfModule>
<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>

I also tried adding
DirectoryIndex index.html index.php
on a line outside of any tags, and that also did not work.

NovaScotian 12-01-2006 07:13 PM

Quote:

Originally Posted by hayne (Post 337887)
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.

Just a minor point. If you are logged as an Admin user, the folder /etc/httpd/ is viewable in a Finder window. Use the Go>Go to Folder... menu selection, and type "/etc/httpd/" in the text box. Bingo.

EDIT: Further, by dragging it to TextWrangler or BBEdit, you can read and save httpd.conf. It's just a plain text file.

hayne 12-01-2006 08:28 PM

Quote:

Originally Posted by 0rthodontist (Post 338659)
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?

There is no point in having an index.php entry outside of one of the <IfModule> sections that covers PHP since index.php only makes sense if PHP is enabled.

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)

0rthodontist 12-01-2006 10:15 PM

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 1456
127.0.0.1 - - [01/Dec/2006:22:09:19 -0500] "GET /apache_pb.gif HTTP/1.1" 200 2326
127.0.0.1 - - [01/Dec/2006:22:09:19 -0500] "GET /favicon.ico HTTP/1.1" 404 304

apache_pb.gif is a feather image from the test page, but I don't know what favicon.ico is. Maybe it is the icon that would normally show up on the tab to identify the page, except I am just getting the default opera icon there. Ah, actually it's a little feather icon, not used anywhere that I can see though (not in the source for the test page). Anyway apache is not returning index.php in response to that root request. There's nothing of interest in error_log that I can see.

By 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?

hayne 12-01-2006 10:42 PM

Quote:

By 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?
I think you should be able to use '/usr/sbin/tcpdump' to capture from 'lo0' (the loopback interface - i.e. local messaging)
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.

hayne 12-01-2006 10:46 PM

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

0rthodontist 12-01-2006 10:53 PM

tcpdump says "tcpdump: no suitable device found" and quits.

Code:

$ curl -IL localhost
HTTP/1.1 200 OK
Date: Sat, 02 Dec 2006 03:50:27 GMT
Server: Apache/1.3.33 (Darwin) PHP/5.2.0
Content-Location: index.html.en
Vary: negotiate,accept-language,accept-charset
TCN: choice
Last-Modified: Fri, 04 May 2001 00:00:38 GMT
ETag: "b779b-5b0-3af1f126;4570d39e"
Accept-Ranges: bytes
Content-Length: 1456
Content-Type: text/html
Content-Language: en

So it is getting index.html.en. But that still doesn't tell me why it isn't getting index.php, or even why it's getting index.html.en in the first place--after all I didn't put that in the DirectoryIndex list. If I try mdfind index.html.en it only turns up files whose name happens to be index.html.en, so I don't know where that is being configured--maybe it is hard coded into apache.


OK, 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*.

hayne 12-01-2006 11:25 PM

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.

hayne 12-01-2006 11:31 PM

Quote:

Originally Posted by 0rthodontist (Post 338707)
tcpdump says "tcpdump: no suitable device found" and quits

I think that is its rather-too-subtle way of saying that you need to run it with root privileges - try prefacing the command with 'sudo'

acme.mail.order 12-02-2006 07:25 AM

Quote:

Originally Posted by hayne (Post 338631)
I suspect that you can't have both PHP4 and PHP5 active at the same time - choose one.

You can, what you can't do is run the same file extension through both versions.

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>
<?php phpinfo(); ?>

and load it with :
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.