Use the source: Apache 1.3.x + mod_ssl + PHP5 + PEAR
Saturday, 31 July 2004 @ 23:14Here’s version 1 of my Apache+PHP5 source install tutorial. This is a tweaked version of my Gentoo-speific instructions to be more generic to any Linux distro.
Updates (if needed) will be on the Gentoo Forums where I originally posted it online.
Download the packages
# cd /tmp# wget http://us2.php.net/get/php-5.0.0.tar.bz2/from/us3.php.net/mirror# wget http://apache.247available.com/httpd/apache_1.3.31.tar.gz# wget http://www.modssl.org/source/mod_ssl-2.8.19-1.3.31.tar.gz
Unpack packages
Please note — package versions will definately change as they get updated. Just replace my examples with real world filenames.
# tar zxf apache_1.3.31.tar.gz# tar zxf mod_ssl-2.8.19-1.3.31.tar.gz# tar jxf php-5.0.0.tar.bz2
Configure mod_ssl
# cd mod_ssl-2.8.19-1.3.31/# ./configure --with-apache=../apache_1.3.31/
You should see some output similar to this:
Configuring mod_ssl/2.8.19 for Apache/1.3.31 + Apache location: ../apache_1.3.31/ (Version 1.3.31) + Auxiliary patch tool: ./etc/patch/patch (local) + Applying packages to Apache source tree: o Extended API (EAPI) o Distribution Documents o SSL Module Source o SSL Support o SSL Configuration Additions o SSL Module Documentation o AddonsDone: source extension and patches successfully applied.Now proceed with the following commands (Bourne-Shell syntax): $ cd ../apache_1.3.31/ $ SSL_BASE=/path/to/openssl ./configure ... --enable-module=ssl $ make $ make certificate $ make install
Configure Apache 1.3.x + test certificate
If you have any custom configuration options you want to pass when compiling Apache, now is to make sure you know what they are. This guide uses three common ones:[list]–enable-module=so # to let php run as an apache module + required for php installation–enable-module=ssl # required to install mod_ssl as a module, optional if you don’t want https support–prefix=/www # instead of putting apache binaries and config files in different directories, this creates and puts everything in /www. You can change the value to whatever you would like.[/list]For this instance, we’re also making a test certificate.
# cd ../apache_1.3.31# ./configure --enable-module=ssl --prefix=/www --enable-module=so# make certificate TYPE=test
Fill in all the answers. I don’t know a lot about making certificates, so you’ll have to look for another guide there. :T I’m only making a self-signed one that will have to be manually accepted on most browsers just so I can have https support.
Install apache + mod_ssl
# make install
Now you’ve got apache + mod_ssl configured with SSL support, and you should be good to go. If you aren’t looking for PHP support, you could stop here. If you’d like to test your apache configuration right now, try this:Start apache:
/www/bin/apachectl start
Start apache with SSL support:
/www/bin/apachectl startssl
After you’ve browsed to http://localhost/ or https://localhost/ stop apache since we’ll have to start it back up after installing PHP. I also include a custom init.d script you can use later in the guide to start/stop apache easily.
/www/bin/apachectl stop
Configure PHP5
# cd ../php-5.0.0/
DO NOT FORGET that MySQL support is disabled by default in PHP 5.0.0. I can’t remember why. The point is that you have to make sure to enable it if you want to be able to connect to a MySQL database with PHP.I’ll start with some basic configuration options, and present some other common PHP options you might want to use, and which packages you will need to emerge in order to use them.Basic PHP configuration for a PHP5 module:
#./configure --with-apxs=/www/bin/apxs
Basic + MySQL support:
# emerge mysql# ./configure --with-apxs=/www/bin/apxs --with-mysql
Basic + PostgreSQL support:
# emerge postgresql# ./configure --with-apxs=/www/bin/apxs --with-pgsql
Basic + zlib support (gzip compress/uncompress):
# ./configure --with-apxs=/www/bin/apxs --with-zlib
zlib is probably already installed. I’d be surprised if it wasn’t.Add SQLite support by installing SQLite (see http://www.sqlite.org/ ). SQLite support in php5 is enabled by default, and will be included in your configuration if it can link against the sqlite libraries.Add zip support:
# wget http://unc.dl.sourceforge.net/sourceforge/zziplib/zziplib-0.10.82.tar.bz2install zziplib
You install ZIP support later with PEAR, but you need zziplib installed before you get there.Disable CGI support if you don’t need it:
#./configure --with-apxs=/www/bin/apxs --disable-cgi
Add them all up:
# ./configure --with-mysql --with-zlib --with-pgsql --disable-cgi --with-apxs=/www/bin/apxs
Then, compile and install php:
# make && make install
Use the default php.ini:
# cp php.ini-dist /usr/local/lib/php.ini
Tweaks — Make life a bit easier:
# ln -s /usr/local/lib/php.ini /etc/php.ini# ln -s /www/conf/httpd.conf /etc/httpd.conf
There you go — now you have Apache + php5 setup. Congratulations. :) All that’s left is to setup PEAR (optional) tweak your apache config files and setup a custom init script.
Setup PEAR
PEAR stands for PHP Extension and Application Repository. I think. I prefer to think of it as official php classes that absolutely rock and save a lot of time. Unfortunately, PEAR can be a bit annoying to setup (especially with dependencies). Here’s the basics.Upgrade all your packages to the latest version:
# pear upgrade-all
Tweaks — Fix PEAR’s funky settings for PECL extensions:
# mkdir /usr/local/lib/php/extensions# pear config-set ext_dir /usr/local/lib/php/extensions
Running pear-config modifies ~/.pearrc so MAKE SURE you run that command as root, since you’ll be installing PEAR packages as root.Now you can install some PECL modules (such as bz2 and zip) and they will drop the modules in /usr/local/lib/php/extensionsUse PEAR — Add the classes directory to your include_path:
# vim /usr/local/lib/php.iniOld: include_path = ".:/php/includes"New: include_path = ".:/usr/local/lib/php"
Apache config files
After you run make install on php5, it will automatically add a line to the apache config (/www/conf/httpd.conf) that will include the php5 module. However, it doesn’t set it up to start parsing .php files through the module. You’ll have to do that yourself:
# echo "AddType application/x-httpd-php .php" >> /www/conf/httpd.conf# echo "AddType application/x-httpd-php-source .phps" >> /www/conf/httpd.conf
Next, change the conf file to read index.php as the index page of a directory:
# vim /www/conf/httpd.confOld: DirectoryIndex index.htmlNew: DirectoryIndex index.php index.html
That’s it — you should be set and ready to go, and start serving up PHP pages without any problems. :) What’s next is some of my own tweaks I like to use INSTEAD OF manually editing httpd.conf and adding those lines I just mentioned.I like to save all my custom apache config files in one place and then “include” them in the original httpd.conf. That way, anytime I upgrade Apache, all I have to add one line to the config file. It makes things pretty simple. Here’s how it works:Create a place to store custom config files:
# mkdir /etc/conf# mkdir /etc/conf/apache
Create a config file for the general settings:
# vim /etc/conf/apache/general.confAdd:ServerName localhostDocumentRoot "/home/steve/public_html"Options FollowSymLinksAllowOverride None Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all
Create a file to include the php settings:
# vim /etc/conf/apache/php.confAdd:AddType application/x-httpd-php .phpAddType application/x-httpd-php-source .phpsDirectoryIndex index.php index.html
Create a file for virtualhosts:
# echo "127.0.0.1 dev" >> /etc/hosts# vim /etc/conf/apache/vhosts.confAdd:NameVirtualHost *:80ServerName localhostOptions IndexesDocumentRoot /home/steve/public_htmlServerName devDocumentRoot /home/steve/dev
Tell apache to include all those config files with one line:
# echo "Include /etc/conf/apache/*" >> /www/conf/httpd.conf
And you’re done. :)
Test your setup
Now you should be ready to go. The best way to test your setup is to start up apache manually and goto http://localhost/ with your browser.
# /www/bin/apachectl start
You should see some kind of generic welcome to apache screen.Now, create a test php script to make sure that’s working as well:
# vim /www/htdocs/phpinfo.phpAdd:
Save the file then browse to http://localhost/phpinfo.php You should see the PHP configuration page. If not, make sure your PHP settings are setup correctly in the apache config file.
I hope that helps — please let me know about any errors I may have hit along the way. Good luck with your Apache+PHP setup!
Steve