This is a complete working solution to build Apache (httpd-2.2.25), MySQL (MySQL-5.6.14) and PHP (PHP-5.5.5) from the sources. Article tested many times on CentOS 6.4 and you can directly copy & paste the commands below to build the lastest releases. We advise you to use a freshly installed OS as compiling may corrupt or delete your existing structure or data. The solution both tested on a clean dedicated server and a KVM virtualized VPS.

Before you begin your compilation you should need additional header files and libraries required, please use the following code to install pre-requisities, don’t delete them as you would definitely need them when you upgrade to new releases also:

yum install make gcc automake zlib-devel bison cmake libtool wget gcc-c++ unzip ncurses-devel openssl-devel pcre-devel libxml2-devel curl-devel gd-devel libxslt-devel

Building & Installing Apache prefork

download the latest release of Apache Web Server and unpack:

tar zxvf httpd-2.2.25.tar.gz 
cd httpd-2.2.25

We advise you to configure with the options below as this form is widely used:

./configure \
        "--prefix=/etc/httpd" \
        "--exec-prefix=/etc/httpd" \
        "--bindir=/usr/bin" \
        "--sbindir=/usr/sbin" \
        "--sysconfdir=/etc/httpd/conf" \
        "--enable-so" \
        "--enable-dav" \
        "--enable-dav-fs" \
        "--enable-dav-lock" \
        "--enable-suexec" \
        "--enable-deflate" \
        "--enable-unique-id" \
        "--enable-mods-static=most" \
        "--enable-reqtimeout" \
        "--with-mpm=prefork" \
        "--with-suexec-caller=apache" \
        "--with-suexec-docroot=/" \
        "--with-suexec-gidmin=100" \
        "--with-suexec-logfile=/var/log/httpd/suexec_log" \
        "--with-suexec-uidmin=100" \
        "--with-suexec-userdir=public_html" \
        "--with-suexec-bin=/usr/sbin/suexec" \
        "--with-included-apr" \
        "--with-pcre=/usr" \
        "--includedir=/usr/include/apache" \
        "--libexecdir=/usr/lib/apache" \
        "--datadir=/var/www" \
        "--localstatedir=/var" \
        "--enable-logio" \
        "--enable-ssl" \
        "--enable-rewrite" \
        "--enable-proxy" \
        "--enable-expires" \
        "--with-ssl=/usr" \

to build and install source distro, type:

make install

Build & Install MySQL

Since we need headers and libraries of mysql for compiling PHP, we will first install MySQL server before PHP compilation.

tar zxvf mysql-5.6.14.tar.gz 
cd mysql-5.6.14
groupadd mysql
useradd -g mysql mysql
cmake .  -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock
make install

If you encounter problems while running cmake, you have to delete CmakeCache.txt before re-compiling with cmake

#log in to newly created mysql dir
cd /usr/local/mysql/
#change owner and group
chown -R mysql:mysql .
scripts/mysql_install_db --user=mysql --datadir=/var/lib/mysql
#add service command
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
#start mysql server
service mysqld start

change your mysql password by typing:

./bin/mysqladmin -u root password 'new-password' 
./bin/mysqladmin -u root -h change.this.hostname password 'new-password'

Build libmcrypt from the source

libmcypt repo is not included in the main yum repo, so better install it from the source:

tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
make install

Building PHP-5.5.5 from the source

PHP configuration is also given with the mostly used modules & functionality, download unpack & configure as stated below:

tar zxvf php-5.5.5.tar.gz
cd php-5.5.5
./configure \
        --with-apxs2 \
        --with-curl=/usr \
        --with-gd \
        --with-gettext \
        --with-jpeg-dir=/usr \
        --with-freetype-dir=/usr \
        --with-kerberos \
        --with-openssl \
        --with-mcrypt=/usr/local/lib \
        --with-mhash \
        --with-mysql=mysqlnd \
        --with-mysqli=mysqlnd \
        --with-pcre-regex \
        --with-pear \
        --with-png-dir=/usr \
        --with-xsl \
        --with-zlib \
        --with-zlib-dir=/usr \
        --with-iconv \
        --enable-bcmath \
        --enable-calendar \
        --enable-exif \
        --enable-ftp \
        --enable-gd-native-ttf \
        --enable-soap \
        --enable-sockets \
        --enable-mbstring \
        --enable-zip \
make install
libtool --finish /root/php-5.5.5/libs
cp php.ini-production /usr/local/lib/php.ini
sed -i 's/;date.timezone =.*/  date.timezone \= "Europe\/Istanbul"/' /usr/local/lib/php.ini

Download phpMyAdmin and install it to webroot:

tar zxvf phpMyAdmin-4.0.8-all-languages.tar.gz 
mv phpMyAdmin-4.0.8-all-languages /var/www/
mv /var/www/phpMyAdmin-4.0.8-all-languages/ /var/www/phpMyAdmin

create a test page to see if everything went well:

echo "<?PHP phpInfo();?>" > /var/www/index.php

If you cannot see a PHP info page, you need to add httpd directives to your httpd.conf:

echo "AddType application/x-httpd-php .php" >> /etc/httpd/conf/extra/httpd-php.conf
echo "AddType application/x-httpd-php-source .phps" >> /etc/httpd/conf/extra/httpd-php.conf

echo "Include conf/extra/httpd-php.conf" >> /etc/httpd/conf/httpd.conf

restart apache by typing: apachectl restart

2 Responses to Compile and build Apache + MySQL + PHP from the source
  1. To have the LDAP module built-in and avoid errors on util_ldap.c when compiling Apache, I’ve had to add “–enable-ldap” “–enable-auth-ldap” “–with-ldap”.

  2. ln -s /usr/local/mysql/bin/mysql /usr/bin
    ln -s /usr/local/mysql/bin/mysqladmin /usr/bin

    I think this will be more better when we install mysql.
    BTW, thank you, I can install lamp success.


Leave a Reply

Your email address will not be published. Required fields are marked *