Compile and build Apache + MySQL + PHP from the source [cite]

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
#   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
  • 117 کاربر این را مفید یافتند
آیا این پاسخ به شما کمک کرد؟

مقالات مربوطه

Using vi Editor

Vi is the one of the mostly used editor in Linux via terminal. In most cases where Linux is used...

Installing MS SQL Module to PHP on DirectAdmin [cite]

If you need to connect to an MS Sql Server remotely from your DirectAdmin server via php, you...

Firewall Settings With IpTables on CentOS and RedHat [cite]

Here on this article we’ll discuss some basic methods to quickly apply to the iptables...

PHP : Convert/Replace Short Open Tags

Using short open tags, such as <? on your PHP code is not so clever. Other than the debate...

How to grep Compressed Files?

Sometimes you need to search the contents of .gz files in your system. Unfortunately, grep...