Getting Apache webserver to run on OS X PB

J.M.J.

Registered
Hello!

I read that OS X comes with Apache web server. I looked around in the system and found a few files in the "library/webserver" directory. I didn't find any program files, so I went on and opened the manual and began reading on the file "library/documentation/Administration/Services/apache/install.html". From what I understand, I don't have the so called "binary distribution", so I will have to compile Apache first before I can run it, correct?<BR>
Anyways, I don't know any UNIX stuff, so the compiling-instructions don't say much. I wonder if there is some tutorial on how to get Apache server up and running under OS X? My goal is to set up a small web server that can run C++ and Perl written CGI scripts and also do PHP stuff if possible.
<B>Any links/tips/instructions are welcome!</B><BR>
Oh, and one more question - is it the pure UNIX version of Apache that comes with OS X PB or is it a somewhat modified MacOS version of it (I read Apache is open source)? If it is pure UNIX, I though I might replace the 1.3 version that comes with OS X PB with the newer 2.0 version...

Thanks

/J.M.J.
 
Just go to system preferences, Network, Services and turn apache on. You don't need to compile it, it's included. Then point a web browser at localhost and you'll see the default page, this tells you its working.

peter
 
Originally posted by monty
Just go to system preferences, Network, Services and turn apache on. You don't need to compile it, it's included. Then point a web browser at localhost and you'll see the default page, this tells you its working.

peter

Ahh...it was <B>so</B> easy. I was looking for words like "Web sharing" like in OS 9, preferably written on a 256x64 big button ;) Ok, activating the web server from sys. prefs and typing localhost in the address field in my browser gives me the index.html file in the Documents folder of the web server. Tack Peter!
<BR>
So far, so good. But I want to be able to do serverside script execution. I tested with a perl script and a php script (and named it with .pl and .php extenstion respectively), but the web server just interpreted it as a plain HTML page - no execution of scripts resulting in that the source code showed up in the browser.
<BR>
From what I've read in Apache docs, there are two things involved in making scripts run on the server. First of all, you have to install some kind of file ("module"?) that does the actual script interpreting stuff. Second, you need to register a handler, mapping the right file suffix to the module that should take care of those kinds of files.
<BR>
I read in "Documents/manual/handler.html" that you can register a handler by typing e.g. <BR>
<I>AddHandler cgi-script cgi</I><BR>
My questions are these: <BR>1) Where should I write this? In the Terminal application or in some textfile that tells Apache what to do on startup? If I should write it in the Terminal app. what do I type to tell it that the command is aimed to the Apache application, not some other?<BR>2) How do I install new modules so that I can run everything I want to run - php, perl and C++ written CGI scripts? Is it possible to do ASP with Apache and, if so, where do I download the correct module?

/J.M.J. - one step closer to doing real webprogramming
 
Ok you're starting to step out of my expertise now but the main configuration file is /Library/WebServer/Configuration/apache.conf

This is a HUGE file but it is well commented. If you want PHP you have to activate the PHP module which you do by uncommenting a couple of things in the config file. I think there maybe a GUI configuration tool around. I know there's a good one for X Windows based Unixs called comanche.

I've only had apache working for about a month and have also set it up as a proxy server. Haven't really mucked around with CGIs, SSI and PHP yet though. When I do and if no-one has answered this then I tell you how i did it.

peter
 
In /Library/Webserver there's a folder called CGI-Executables. Put your script in there, make it executable, and you should be good to go. The key is that having done this, you have to point your browser to http://localhost/cgi-bin/ not localhost/CGI-Executables/. It's possible you have to mess with apache.conf, but I don't think so (can't remember).

This will take care of Perl scripts--for PHP, I think it's more complicated (haven't done it myself), but it's been discussed elsewhere on this site--search for PHP and you should find it.

 
yep ben's right. as long as cgis are in the CGI-Executables folder and are flagged executable by the www user (or just all) it should work. However, i'm pretty sure that for PHP you have to turn on the php module which is off by default.

peter
 
Originally posted by J.M.J.

Oh, and one more question - is it the pure UNIX version of Apache that comes with OS X PB or is it a somewhat modified MacOS version of it (I read Apache is open source)? If it is pure UNIX, I though I might replace the 1.3 version that comes with OS X PB with the newer 2.0 version...
It is a little modified.
The Mac OS X version uses apache as target-name instead of httpd for example, and a different layout.
However, Apache recognizes X since the last version, and will configure itself for the Mac OS X layout.
 
if you just turn on the wwb server in the service tab, cgi and Server Side Includes will not work. You need to edit the apache.conf file. I of course wrote a tutorial on how to get CGI and SSI working with Apache in OS X B. go to http://www.macwrite.com/columns/ The column has helped alot of people (I actually helped people? hmmm I thought I was the lost one looking to become a Super user). I am now onto the next level with OS X and apache setting up multiple sites on one server. Virtual Hosts.
 
if you just turn on the wwb server in the service tab, cgi and Server Side Includes will not work. You need to edit the apache.conf file. I of course wrote a tutorial on how to get CGI and SSI working with Apache in OS X B. go to http://www.macwrite.com/columns/ The column has helped alot of people (I actually helped people? hmmm I thought I was the lost one looking to become a Super user). I am now onto the next level with OS X and apache setting up multiple sites on one server. Virtual Hosts.
 
PHP has to be configured into apache. As far as I can see there is no way yet to have apache run with dynamic modules/apxs. Once this is done it will be very easy to add other modules such as php, mod_perl etc.

Someone has packaged some precompiled binaries of Apache with PHP, and MySQL for OS X that are extremely easy to install.

There are complete instructions and links to the downloads here: http://homepage.mac.com/LightyearDesign/MacOSX/Packages/

 
Also don't forget about using apachectl from the command line. It will let you start, stop, and do a quick reload of apache faster than going in through the system preferences panel.
 
Or you can get the PID from /Library/WebServer/Logs/apache.pid and do

<code>kill -HUP PID</code>

to force it to re-read the apache.conf file. Or (as he comes back from reading the manual)

<code>kill -USR1</code>
which won't interrupt current service. So if you feel like being cute, it's

<code>kill -USR1 `cat /Library/WebServer/Logs/apache.pid`</code>

I compared my apache.conf to the apache.conf.default file and found no differences that were attributable to CGI, so I don't think I changed anything, and CGIs are certainly working... give it a try with everything else working before you start mucking with the conf file, it's worth avoiding.

[Edit: added -USR1 bit]

[Edited by BenW on 02-06-2001 at 05:57 PM]
 
>PHP has to be configured into apache. As far as I can see
>there is no way yet to have apache run with
>dynamic modules/apxs

Do you mean Configured in at compile time? If that's what you meant you are wrong. The proxy module is a dynamically loaded module and you can get it to work by uncommenting a few things in the apache.conf. I'm not on my OSX box so from memory it's in a long list of modules and you just have to uncoment the line that loads it. The PHP module is there too, also commented out. I haven't tried it but I assume you just uncomment it and then set it up. Works for the proxy module.

If that's not what you meant then sorry.

peter
 
Ok, I followed lucifers's link and downloaded the package that contained an installer. I experienced the Mac-like install and saw the php-info appear when typing localhost/test.php in the browser. Nice that some person had made an installer, cause editing that config file wasn't a very smooth way of doing it - at least not for a Mac user :)...<BR>Anyway, while PHP is working, I still have a couple of problems: <UL><BR><LI>First of all, I can't run Perl scripts. When accessing a .pl file that lies within the CGI Executables directory, I get a "403 Forbidden" error. I linked to a cgi-bin directory, like BenW said. I was a bit unsure of how to link from my html file that contained the form (the html file was directly in the Documents folder), so I tried with both "cgi-bin/test.pl" and "../cgi-bin/test.pl" as the action parameter of the form tag (cause the cgi-bin directory is in the webserver root, and localhost points to the Documents folder). However, none of these links worked. Or maybe they did, since I get a 403 Forbidden error, which means that the webserver knows what directory I wanna use, but just won't allow me to use that particular directory...</LI><BR><LI>Second, as adding/removing documents in the Documents directory appearantly requires the web server to be inactive (?), I need to know of a fast way to activate/stop the web server - and thereby unlocking the "Documents" folder. BenW talks about PID and lucifer talks about apachetcl, but I don't know how to use any of them (although I'm a little bit familiar with TCL syntax). I haven't become a friend with the Terminal application yet I'm afraid :) so I don't know how to enter the commands that BenW mentioned.<BR> Or is there a better way? If I wanna build websites, it'll be hard, since I very frequently switch between BBEdit and IE and test the code. Could I maybe unlock the Documents folder without shutting down the webserver?</LI><BR></UL>Finally I would like to ask about a Perl-thing. This shouldn't be the cause of the 403 Forbidden error, but is it right to write the following in the beginning of a Perl script on a MacOS X machine?<BR><BR><CODE>#! /System/Library/Perl</CODE><BR><BR>Thanks everyone that tries to help me and other server-newbies with all this configuration stuff!<BR><BR>J.M.J.
 
Originally posted by J.M.J.
Finally I would like to ask about a Perl-thing. This shouldn't be the cause of the 403 Forbidden error, but is it right to write the following in the beginning of a Perl script on a MacOS X machine?<BR><BR><CODE>#! /System/Library/Perl</CODE><BR><BR>Thanks everyone that tries to help me and other server-newbies with all this configuration stuff!<BR><BR>J.M.J.
It does not matter what stands where.
Lines that start with a # are just comment lines.
 
The first line is *not* strictly a comment, and for scripts to be executable independently (that is, for the server to execute them) it must be correct--it tells the calling program where to look for the program that parses the script. Try changing it if you like, see where it gets you...

In OS X, the shebang line is
<code>#!/usr/bin/perl</code>
and nothing else.

/System/Library/Perl is the location of modules invoked within scripts as <code>use CGI;</code> and the like--it is not the location of the perl executable.

I can't reproduce the 403 problem, which leads me to think it's a file permissions problem--make sure the script is executable by all (<code>chmod +x myscript.pl</code>). If you already have, I have no idea what the problem could be... unless it's a problem with your script, of course. I assume you've debugged it from the command line, but if you haven't, it might help.
 
Hi.
You answer to the original queston was a great help. If you know where is apache.conf file is, please let me know. And how can I become a root? what's the password? I have no idea about root password.
I realy really appreciate you help.
-KC-
 
Back
Top