Linux Tutorial: How to Build Apache, PHP5 and MySQL From Source
I’m going to show you how to do it the hard way, building everything from source, the way Linus intended. Let’s get started.
Step 1: Determine if it’s right for you.
This is not the only way to get a LAMP server going and not always the best way. You can get these files from your package manager in your favorite distribution or use something like XAMPP like I mentioned in previous articles. For most developers this a perfectly acceptable way to do it, and likely a better use of your time. Here are the reasons you would want to build from source:
You should only build from source if:
You have a good idea of what you’re doing.
You have time and patience.
You want the latest and greatest stuff and your package manager doesn’t have it yet.
You want to do something really custom and need to change crucial options.
You want full control over the installation details.
You need the maximum performance and stability possible.
You should verify all your files before building, just to make sure you didn’t get a corrupt file.
Notes before you start:
You will see version numbers here, and those numbers are for the latest version of the software available when I wrote this. By the time you read this, they will have changed. If you want you can get these exact version numbers and build them exactly as in the article, but usually the newest version of the software is best.
I use “nice -20” before running make to ensure it gets priority. You don’t have to do this, and usually its not even required as most kernels will prioritize it pretty well.
You do not have to be root to build this stuff, in fact you shouldn’t be. You only need root privileges to install the software but you can build it with a regular user.
tar zxvf mysql-5.5.24.tar.gz (file name will differ)
cd mysql-5.5.24 ./configure –prefix=/usr/local/mysql make make install cd /usr/local/mysql chown -R mysql . chgrp -R mysql . scripts/mysql_install_db –user=mysql chown -R root . chown -R mysql var cp support-files/my-medium.cnf /etc/my.cnf
bin/mysqld_safe –user=mysql &
This will install your MySQL server. If you have issues getting it working, consult this page and follow those instructions.
bunzip2 libmcrypt-2.5.8.tar.bz2 tar xvf libmcrypt-2.5.8.tar cd libmcrypt-2.5.8 ./configure –prefix=/usr –mandir=/usr/share/man nice -20 make make install
tar xvzf apr-1.4.6.tar.gz /usr/src/http-2.4.2/srclib cd apr-1.4.6 ./configure nice -20 make
tar xvzf apr-util-0.9.19.tar.gz ./buildconf –with-apr=/usr/src/apr-1.4.6/ ./configure
tar xvzf pcre-8.30.tar.gz ./configure nice -20 make make install
cd httpd-2.4.2 CFLAGS=”-O2” ./buildconf –with-apr-util=/usr/src/httpd-2.4.2/srclib/apr-util-1.4.1 –with-apr=/usr/src/httpd-2.4.2/srclib/apr-1.4.6/ –enable-so –prefix=/usr/local/apache2 CFLAGS=”-O2” ./configure nice -20 make make install
We are going to install PHP 5.4.3 which was the most current at the time of this writing.
tar -xvzf php-5.4.3.tar.gz cd php-5.4.3
Note: The configure paramaters are where you really customize your installation. The following is the one I used for my machine, but your needs may be different. I will show you two of them and if mine doesn’t work, you can use a failsafe one.