Apache Installation Tips for PHP, SQL Server, MySQL on FreeBSD, Linux, OpenBSD, NetBSD Logo Thursday, November 23, 2017
By The Voodooman what's new | faq | about

Installation Instructions

These are the installation instructions that you have to follow to install Apache/PHP with database support. Depending on what features you decide to have (such as types of database support), you can skip certain sections.

Important: It is necessary to follow the installation instructions in sequence otherwise some of the features may not work correctly. It is assumed that you know how to change directories, unzip files and use an editor under a *nix environment at this stage. It is also assumed that you've downloaded all the files to /usr/local/src. Modify the commands accordingly, if you're using a different directory.

Some of the commands that are issued in the instructions below may be unfamiliar to you. If you are not really sure what the output of certain commands look like, then click on these images below for reference. Your screen should look like something similar when you issue the respective commands.

  • Sample output while running a tar command.
  • Sample output while running a ./configure command.
  • Sample output while running a make command.
  • Sample output while running a make install command


    1. Uncompress Files

    It is assumed that you've already changed directories to /usr/local/src. If you've not done so, then type:

    cd /usr/local/src
    Proceed to uncompress all the downloaded files as follows:
  • tar -zxvf apache_*.tar.gz
  • tar -zxvf php-*.tar.gz
  • tar -zxvf ZendOptimizer*.tar.gz
    (Note: Do this only if you're planning to use the Zend Optimizer module (recommended).
  • gzip -d mod_gzip.c.gz
    (Note: Do this only if you're planning to use the mod_gzip module (recommended).
  • tar -zxvf mhash-*.tar.gz
    (Note: Do this only if you're using the mhash module for PHP)
  • tar -zxvf mysql-*.tar.gz
    (Note: Do this only if you're using the MySQL database engine)
  • tar -zxvf freetds-*.tgz
    (Note: Do this only if you're using the SQL Server database engine)
  • tar -zxvf DBD-Sybase-*.tar.gz
    (Note: Do this only if you're using the SQL Server database engine AND you want perl support for SQL server. It's generally a good idea to do this, if you're using SQL server.)
  • tar -zxvf DBI-*.tar.gz
    (Note: Do this only if you want perl support for any database engine. It's generally a good idea to do this always.)
  • tar -zxvf Msql-Mysql-modules-*.tar.gz
    (Note: Do this only if you're using the MySQL database engine AND you want perl support for MySQL. It's generally a good idea to do this, if you're using MySQL.)


  • TOP

    2. Compile MHASH Module

    Note that you need to do this step ONLY if you want to enable MHASH support for the PHP module. If you do not use any of PHP's mhash_xx functions, then you probably don't want this module. If you have already installed Apache completely and find that you need this module at a later time, then follow this step and then from step 8 to the end.
  • cd /usr/local/src/mhash-*
  • ./configure
  • make
  • make install


  • TOP

    3. Compile MySQL

    Note that you need to do this step ONLY if you are using MySQL as your database engine and it is not already installed for you. If you've already installed Apache completely and find that you need this module at a later time, then follow this step, step 5 and then step 8 to the end.
  • cd /usr/local/src/mysql-*
  • ./configure --prefix=/usr/local (Note that if you have low memory in your system, then add the parameter: --with-low-mem to the configure command)
  • make
  • make install
  • scripts/mysql_install_db
    The next two steps are optional, but mysql.server is a handy batch file to stop and start mysql
  • cp support-files/mysql.server /usr/local/bin
  • chmod 700 /usr/local/bin/mysql.server

  • Now, the next steps would be to create a mysql user account/group for the mysqld daemon to use and set the shell so that no one can login with this account. Also, we need to set the proper directory permissions for this account.
  • adduser
  • Create an account called mysql and be sure to set the default shell to nologin (or no, depending on OS).
  • chown mysql:mysql /usr/local/var
  • /usr/local/bin/mysql.server start

  • The last command should start up MySQL. Now all that remains is for you to secure it. See the Official MySQL Guide for documentation on how to secure your MySQL server. At the very minimum, you must set the password for the root account in MySQL (the default password is blank). To do this:
  • /usr/local/bin/mysql -u root
  • use mysql;
  • UPDATE user SET Password=PASSWORD('somepasswd') WHERE user = 'root';
  • FLUSH PRIVILEGES;
  • exit

  • Instead of executing FLUSH PRIVILEGES, you can alternatively stop and start mysql (using /usr/local/bin/mysql.server) to reread the new password. Either way, after you do this, you should no longer be able to log into MySql using /usr/local/bin/mysql -u root. You should only be allowed to log in using /usr/local/bin/mysql -u root -p and only after you type the correct password. For more MySQL information, the best documentation is found on the official MySQL website.

    TOP

    4. Compile DBI

    This is the Database Independent driver for Perl. It is a good idea to install this anyway, because it does not affect the running of Apache.
  • cd /usr/local/src/DBI-*
  • perl Makefile.PL
  • make
  • make install


  • TOP

    5. Compile Msql-Mysql-modules

    Note that you need to do this step ONLY if you are using MySQL as your database engine and it is not already installed for you. If you are going to do this step, you should have already completed step 3 first.
  • cd /usr/local/src/Msql-Mysql-modules-*
  • perl Makefile.PL
    Select MySQL install only and hit enter for the rest of the questions (the defaults should work OK)
  • make
  • make install


  • TOP

    6. Compile FreeTDS

    Note that you need to do this step ONLY if you are using SQL Server as your database engine. Here's where things get a little different between Linux and FreeBSD. Follow the necessary steps according to your OS.

    FreeBSD/OpenBSD/NetBSD users ONLY

    Some BSD systems do not have GNU make (gmake) installed by default. If this is the case, you'll need to download and install gmake and gettext for FreeTDS to compile correctly. The steps to do this are as follows:

  • cd /usr/local/src
  • tar -zxvf gettext*.tar.gz
  • tar -zxvf make*.tar.gz
  • cd /usr/local/src/gettext*
  • ./configure
  • make
  • make install
  • cd /usr/local/src/make*
  • ./configure
  • make
  • make install
  • mv /usr/local/bin/make /usr/local/bin/gmake
  • rehash Use this only if you're using tcsh or similar shell
  • For All Systems
  • cd /usr/local/src/freetds*
  • ./configure --with-tdsver=7.0 --prefix=/usr/local --enable-dbmfix
  • gmake
  • gmake install

  • The freetds driver (pre-version 0.60) doesn't quite follow the filesystem hierarchy standards and puts a file called interfaces into /usr/local. In order to comply with the standards, the author suggests moving the file into /usr/local/etc/ and renaming it something more meaningful like freetds.conf. If you are using freetds-0.60 or later, this is already done for you.
  • mv /usr/local/interfaces /usr/local/etc/freetds.conf

  • If you're using sh, bash or ksh for your shell, then type:
  • SYBASE=/usr/local
  • LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$SYBASE/lib
  • export SYBASE LD_LIBRARY_PATH
  • If you're using csh, then type:
  • setenv SYBASE /usr/local
  • setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:$SYBASE/lib

  • You may sometimes see the shell complain about ${LD_LIBRARY_PATH} not already being defined. If you see this error, ignore it and proceed forward.

    TOP

    7. Compile DBD-Sybase

    This is the Sybase Driver for Perl. It is a good idea to install this anyway, if you are using SQL Server, because it does not affect the running of Apache.
  • cd /usr/local/src/DBD-*
  • If you're using freetds version 0.60 and above, edit the file dbdimp.c and change all instances of cs_ctx_global to cs_ctx_alloc.
  • perl Makefile.PL
    You may see some warning messages here. Most can be ignored.
  • make
  • make install


  • TOP

    8. Compile Apache/PHP

    Here we are.... almost at the end of our journey! For installing apache, the following layout will be adopted by this guide:
  • Apache Binaries - /usr/local/bin
  • Loadable Modules - /usr/local/libexec
  • Manuals - /usr/local/man
  • Configuration Files - /usr/local/etc/httpd
  • Data Directory Base - /var/www
  • Documents (where the website files are placed) - /var/www/htdocs
  • CGI Scripts (where CGI scripts are placed) - /var/www/cgi-bin
  • Log Files - /var/log
  • State Files - /var/run

  • You may change the directories to your own needs, as will be explained below.

  • cd /usr/local/src/apache*
  • Open your favourite text editor and type the following into it (Enable the modules that you need accordingly and adjust the paths to your requirements -- also see the layout notees below):
    ./configure \
    --prefix=/usr/local \
    --sysconfdir=/usr/local/etc/httpd \
    --datadir=/var/www \
    --localstatedir=/var \
    --runtimedir=/var/run \
    --logfiledir=/var/log \
    --proxycachedir=/var/www/proxy \
    --disable-module=imap \
    --disable-module=actions \
    --disable-module=alias \
    --disable-module=asis \
    --disable-module=auth \
    --disable-module=cgi \
    --disable-module=env \
    --disable-module=include \
    --disable-module=setenvif \
    --disable-module=status \
    --disable-module=userdir \
    --add-module=../mod_gzip.c \
    --activate-module=src/modules/php4/libphp4.a
    If you are wondering about how the layout directories are specified, you can check out the config.layout file which explains what some of the options are. If you want to go for a layout designed for your specific OS, then replace all the lines from --prefix to --proxycachedir with --with-layout=YourOS, where YourOS is the name of your OS in config.layout (match the case exactly). When you are done deciding on the layouts and options to enable/disable, save this file and call it apache_conf. Now exit your editor.
  • chmod 755 apache_conf
  • ./apache_conf
    This will take a little while to complete the command.
  • cd ../php-*
  • Again, fire up your favourite editor and type the following into it (enabling/disabling the modules you need and adjusting the path names according to your setup):
    ./configure \
    --with-mysql \
    --with-mhash \
    --with-sybase=/usr/local \
    --with-apache=../apache_1.3.28 \
    --without-gd \
    --without-java \
    --disable-xml \
    --disable-debug \
    --enable-debug=no \
    --disable-session \
    --enable-sigchild
    Save this file as php_conf and exit your text editor again.
  • chmod 755 php_conf
  • NOTE: If you're using SQL Server AND PHP version below 4.0.6 ONLY: Open the file ext/sybase/php_sybase_db.c with your favourite text editor and replace all occurrences of 'dbopen' with 'tdsdbopen' (there should be 3 instances). Save this file and exit. If you've been following the steps in this guide, you would have downloaded the source for a later PHP version, so this step is totally UNNECESSARY for you.
  • ./php_conf
  • make
  • make install
  • cd ../apache*
  • ./apache_conf
  • make
  • make install


  • TOP

    9. Installing the Zend Optimizer

    This is an optional step that is recommended, because the Zend Optimizer makes the PHP code run so much smoother when it is installed. To install the optimizer, do the following:
  • cd /usr/local/src/ZendOptimizer*
  • cd data/4_2_x_comp
  • cp ZendOptimizer.so /usr/local/libexec

  • Next, create a file called php.ini in the directory /usr/local/lib using your favourite text editor. Add the following lines into it (adjusting your paths as necessary):
    zend_optimizer.optimization_level = 15
    zend_extension = "/usr/local/libexec/ZendOptimizer.so" 
    zend_loader.enable = Off
    
    ; Compress output for .gz compliant browsers
    output_handler = ob_gzhandler           
    
    ; allow ASP-style <% %> tags
    asp_tags = Off
    
    ; number of significant digits displayed in floating point numbers
    precision = 14
    
    ; Whether to be year 2000 compliant 
    ;(will cause problems with non y2k compliant browsers)
    y2k_compliance = Off                    
    
    ; Implicit flush tells PHP to tell the output layer to flush itself
    implicit_flush = Off
    
    ; Decides whether PHP may expose the fact that it is installed on 
    ; in the HTTP header reply
    expose_php = Off
    
    ; Maximum execution time of each script, in seconds	
    max_execution_time = 30                 
    
    ; Maximum amount of memory a script may consume (8MB)
    ;memory_limit = 8M                      
    	
    sybase.interface_file = "/usr/local/etc/freetds.conf"
    	
    ;error_reporting        =       E_ALL
    ;display_errors =       On
          
    You may wish to adjust some of the parameters such as max_execution_time, precision etc. to your own requirements. Notice that some of the options (memory_limit, error_reporting, display_errors) are commented out. These options may be enabled for debugging and removed when you move the code into production. Feel free to experiment with the settings for your own optimal needs.

    TOP

    Reinstalling Features

    Let's say you've installed apache completely and you wish to add or subtract something (let's say you want to enable the MHASH module and enable Image Mapping on Apache). It's pretty simple -- all you have to do is to repeat the steps from the module downwards (in this case Step 2). Don't forget that if something has already been compiled, then do a make clean before you type make at every stage. In this case, you'll need to do a make clean while recompiling apache in step 8.

    TOP


  • <<Previous: Downloads ^Up to Mayukh's World^ Next: Configuration >>

    Apache Installation Walkthrough
    Last updated 08/01/2003