dimanche 5 août 2012

fastcgi with apache on mac os x lion


First of all, I had many issues with apache to make it running. It does not start well from the preferences. Google it to find some workarounds, but none of them really worked for me.
Even sometimes, it indicates as not running but it is :-/

just few tips about apache on max os x (lion):

> sudo apachectl stop
to stop apache

> sudo apachectl start
to start apache

> sudo apachectl -t
to check what was wrong

> cat /var/log/apache2/error_log
to check the error log

1. First we would need to get the fastcgi library:

unzip it somewhere and go the the unzipped folder.
> ./configure
> make
> sudo make install
as an alternative for clang++ with c++11 and libc++ (with c++11 support)
>  CC="clang" CXX="clang++" CFLAGS="-stdlib=libc++" CXXFLAGS="-stdlib=libc++" ./configure

... easy for now :-)

2. Now we would need the apache module

unzip it somewhere and go the the unzipped folder.
> sudo apxs -n mod_fastcgi -i -a -c mod_fastcgi.c fcgi_buf.c fcgi_config.c fcgi_pm.c fcgi_protocol.c fcgi_util.c

it will compile and install the mod_fastcgi for apache.

3. To Configure apache, let's edit the config file:
> sudo nano /private/etc/apache2/httpd.conf

add the line:
LoadModule fastcgi_module libexec/apache2/mod_fastcgi.so

and at the end of the file:

<IfModule mod_fastcgi.c>
FastCgiIpcDir /tmp/fcgi_ipc/
AddHandler fastcgi-script .fcgi
now CTRL+O to save the file
CTRL+X to quit

4. let's create the folder /tmp/fcgi_ipc
> sudo mkdir /tmp/fcgi_ipc
> sudo chmod 777 /tmp/fcgi_ipc
5. it should be ready now, let's test it.
so just take an example from the lib http://www.fastcgi.com/dist/fcgi.tar.gz in the folder "examples"

just take "echo.c", put it on a folder then
> gcc echo.c -lfcgi -o echo.fcgi
> sudo cp echo.fcgi /Library/WebServer/CGI-Executables/
now you can access it with your browser with the url:

Hope it will be useful for you, happy coding!

Aucun commentaire:

Enregistrer un commentaire