Frequently Asked Questions:

TEST>FAQ>Mirror>rsync



How to Install Apache with PHP and cURL on a Unix or Linux Platform

How to install Apache with PHP and cURL on a Unix or Linux platform

Instructions current as of 11/03/2004

  1. Download the Apache 2.0.52 Unix source distribution, available via URL

    http://www.apache.org/dist/httpd/httpd-2.0.52.tar.gz

    > wget http://www.apache.org/dist/httpd/httpd-2.0.52.tar.gz

  2. Uncompress and extract the downloaded source distribution:

    > zcat httpd-2.0.52.tar.gz | tar xvf -


  3. Change your working directory to the source directory which was just created and run the configure script with DSO capability:

    > cd httpd-2.0.52
    > ./configure
    --enable-so


  4. Build the Apache web server once the configure script has completed by typing make at the shell prompt:

    > make

  5. When the compilation finishes, become superuser and install the package by typing make install at the shell prompt:

    > su (enter root password)
    # make install


  6. Edit the Apache web server configuration file and, at a minimum, modify the following configuration directives:

    # vi /usr/local/apache2/conf/httpd.conf

    Uncomment #ExtendedStatus On:


    ExtendedStatus On


    Change Group #-1:

    Group nobody

    Configure ServerAdmin you@example.com by changing you@example.com to your actual email address:

    ServerAdmin subrata@thermo.sdsu.edu

    Configure #ServerName www.example.com:80 to reflect the fully qualified domain name of the system upon which you are installing Apache:

    ServerName thermo.sdsu.edu:80

    Uncomment the following configuration directives and allow server-status queries to be invoked from the system upon which you are installing Apache by changing

    #<Location /server-status>
    # SetHandler server-status
    # Order deny,allow
    # Deny from all
    # Allow from .example.com
    #</Location>


    to

    <Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from thermo.sdsu.edu (enter your fully qualified domain name here)
    Allow from localhost
    </Location>


  7. Use the Apache control utility to check the syntax of the configuration file to make sure you did not make any mistakes:

    # /usr/local/apache2/bin/apachectl configtest
    Syntax OK


  8. If you receive the Syntax OK response, then go ahead and start the webserver:

    #
    /usr/local/apache2/bin/apachectl start

  9. Use the Apache control utility to check the status of the running webserver:

    # /usr/local/apache2/bin/apachectl status

    Apache Server Status for localhost

    Server Version: Apache/2.0.52 (Unix)
    Server Built: Nov 4 2004 17:15:11
    _________________________________________________________________

    Current Time: Friday, 05-Nov-2004 11:56:12 PST
    Restart Time: Friday, 05-Nov-2004 10:45:11 PST
    Parent Server Generation: 0
    Server uptime: 1 hour 11 minutes
    Total accesses: 1 - Total Traffic: 2 kB
    CPU Usage: u.1 s.18 cu0 cs0 - .00657% CPU load
    .000235 requests/sec - 0 B/second - 2048 B/request
    1 requests currently being processed, 4 idle workers

    ___W_S..........................................................
    ................................................................
    ................................................................
    ................................................................

    Scoreboard Key:
    "_" Waiting for Connection, "S" Starting up, "R" Reading Request,
    "W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
    "C" Closing connection, "L" Logging, "G" Gracefully finishing,
    "I" Idle cleanup of worker, "." Open slot with no current process

  10. Navigate your web browser to the address of your server and verify that you see the default test page for the Apache webserver.

  11. Congratulations, you now have a running webserver! You are 1/3 of the way to finishing these steps.

  12. Now you will install cURL. Download the cURL Unix source distribution, available via URL

    http://curl.haxx.se/download/curl-7.12.2.tar.gz

    > wget
    http://curl.haxx.se/download/curl-7.12.2.tar.gz

  13. Uncompress and extract the downloaded cURL source distribution:

    > zcat curl-7.12.2.tar.gz | tar xvf -


  14. Change your working directory to the cURL source directory and invoke the configure script as follows:

    > cd curl-7.12.2
    > ./configure

  15. After the configuration script runs, invoke make to compile the cURL sources:

    > make


  16. When the compilation finishes, become superuser and install cURL by typing make install at the shell prompt:

    # make install


  17. Congratulations, you have installed the cURL libraries! You are 2/3 of the way to finishing these steps.

  18. Now, the final task is to install PHP. Change your working directory one level up and download the PHP 4.3.9 Unix source distribution, available via URL

    http://us2.php.net/get/php-4.3.9.tar.gz/from/this/mirror

    > cd ..
    > wget http://us2.php.net/get/php-4.3.9.tar.gz/from/this/mirror

  19. Uncompress and extract the downloaded PHP source distribution. Make sure you extract the PHP distribution so that it is parallel to the cURL distribution. That is, the php source directory and the cURL source directory have the same parent directory.

    > zcat php-4.3.9.tar.gz | tar xvf -


  20. Change your working directory to the PHP source directory and invoke the configure script as follows:

    > cd php-4.3.9
    > ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql
    \
         --with-curl=../
    curl-7.12.2

  21. After the configuration script runs, invoke make to compile the PHP sources:

    > make

  22. When the compilation finishes, become superuser and install PHP by typing make install at the shell prompt:

    # make install

  23. When the installation is finished, install the PHP initialization file:

    # cp php.ini-dist /usr/local/lib/php.ini

  24. Configure Apache to treat the .php extension as a PHP source file:

    # vi /usr/local/apache2/conf/httpd.conf


    Locate the region where the AddType directives are configured. Append the directive

    AddType application/x-httpd-php .php .phtml

    after the commented #AddType application/x-tar .tgz line as follows:

    #
    # AddType allows you to add to or override the MIME configuration
    # file mime.types for specific file types.
    #
    #AddType application/x-tar .tgz
    AddType application/x-httpd-php .php .phtml

  25. Save the configuration file and use the Apache control utility again to check the syntax to make sure you did not make any mistakes:

    # /usr/local/apache2/bin/apachectl configtest
    Syntax OK


  26. Stop and restart the Apache webserver. Then verify that Apache is PHP enabled by looking for the PHP/4.3.9 string in the Server Version line in the output of a status request:

    # /usr/local/apache2/bin/apachectl stop
    # /usr/local/apache2/bin/apachectl start
    # /usr/local/apache2/bin/apachectl status

    Apache Server Status for localhost

    Server Version: Apache/2.0.52 (Unix) PHP/4.3.9
    Server Built: Nov 4 2004 17:15:11
    _________________________________________________________________

    Current Time: Friday, 05-Nov-2004 13:19:52 PST
    Restart Time: Friday, 05-Nov-2004 13:19:47 PST
    Parent Server Generation: 0
    Server uptime: 5 seconds
    Total accesses: 0 - Total Traffic: 0 kB
    CPU Usage: u0 s0 cu0 cs0
    0 requests/sec - 0 B/second -
    1 requests currently being processed, 4 idle workers

    _W___...........................................................
    ................................................................
    ................................................................
    ................................................................

    Scoreboard Key:
    "_" Waiting for Connection, "S" Starting up, "R" Reading Request,
    "W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
    "C" Closing connection, "L" Logging, "G" Gracefully finishing,
    "I" Idle cleanup of worker, "." Open slot with no current process

  27. Congratulations, you now have a running PHP enabled webserver with cURL support!

  28. The final step is to make sure PHP with the cURL module is working. Using your favorite HTML authoring tool or editor, save the following content to a file named phptest.php in the /usr/local/apche2/htdocs directory:

    <html>
    <head><title>PHP test page</title></head>
    <body bgcolor="#ffffff">
    <P>
    <?php phpinfo(); ?>
    </body>
    </html>


    Then, use your web browser to view the phptest.php file via a URL based on your fully qualified domain name (i.e. http://host.domainname/phptest.php). Verify that the cURL module is listed in the PHP status web page generated by the phpinfo() function. You should find a content block similar to the following, showing cURL support is enabled:

    curl

    CURL support enabled
    CURL Information libcurl/7.12.2