Setting up Apache 2.2, MySQL 5.5 + Sphinx 2.0, PHP 5.3, a Scripted Guide

Similar to the previous scripted guide, this script will download the source for Apache, MySQL (and optionally with Sphinx, steps denoted in red font), and PHP and compile it under CentOS 5 and 6 on a x86-64 platform.

I’ve had this type of script for a few years now due to the amount of times I’ve had to provision a VPS from scratch. I simply copy/paste the script onto a clean VPS and away it goes setting up a LAMP server from source. This script should not require any existing requisites and should work out-of-the-box on a clean installation of CentOS 6.

# We need a few packages in order to compile apache, mysql and PHP from rpmforge.
# Import the key and install the repo.

rpm --import
rpm -K rpmforge-release-0.5.2-2.el6.rf.*.rpm
rpm -i rpmforge-release-0.5.2-2.el6.rf.*.rpm

# Install all prerequisites.
yum -y install make autoconf g++ gcc-c++ libtermcap-devel libgcc-c++ libtool gcc libpng-devel libjpeg-devel libxml1-devel libxml2-devel curl curl-devel libmcrypt libmcrypt-devel libtool-ltdl-devel libxml2.x86_64 libxml2-devel.x86_64 curl-devel.x86_64 openssl-devel

# Download the source files. Sphinx is optional.
mkdir src
cd ~/src

# Extract all archives
for f in `ls *.tar.gz` ; do tar -xzf $f ; done

# Setting up apache into /opt/apache

cd /root/src/http*/
./configure --prefix=/opt/apache --enable-so --enable-rewrite --enable-ssl --enable-setenvif
make install

# Setting up MySQL into /opt/mysql.
# Note: MySQL 5.5 and above will require cmake.

yum -y install cmake
cd /root/src/mysql*/

# If you wish to compile MySQL with Sphinx, run the following:
cp -R ../sphinx-*/mysqlse/ storage/sphinx
./configure --prefix=/opt/mysql --with-plugins=sphinx --with-unix-socket-path=/opt/mysql/mysql.sock --without-man --enable-shared --without-debug --enable-assembler --with-ssl CFLAGS=-O3 'CXXFLAGS=-O3 -fno-exceptions -felide-constructors -fno-rtti' CXX=gcc

# Otherwise, to compile MySQL without Sphinx run:
./configure --prefix=/opt/mysql --with-unix-socket-path=/opt/mysql/mysql.sock --without-man --enable-shared --without-debug --enable-assembler --with-ssl CFLAGS=-O3 'CXXFLAGS=-O3 -fno-exceptions -felide-constructors -fno-rtti' CXX=gcc

make install

# Setup the init scripts
/bin/cp support-files/mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
ln -s /etc/init.d/mysql /etc/rc3.d/S40mysql

# Copy the default configuration
/bin/cp support-files/my-medium.cnf /etc/my.cnf

# Setup the mysql system account
/usr/sbin/useradd -r mysql

# Update the MySQL permissions
cd /opt/mysql
chown -R mysql .
chgrp -R mysql .

# When setting up the initial database on MySQL 5.4 or earlier, run:
# /opt/mysql/bin/mysql_install_db --user=mysql
# On MySql 5.5 or later, run:

/opt/mysql/scripts/mysql_install_db --user=mysql --basedir=/opt/mysql

# Ensure the new database files created from the previous step is owned by mysql
chown -R mysql /opt/mysql

# Start MySQL manually:
/opt/mysql/bin/mysqld_safe --user=mysql &

# MySQL should now be running. You can verify this by running:
# ps -A|grep mysql

# Set the lib paths of mysql so the or w/e can be found

echo "/opt/mysql/lib/mysql" > /etc/

# Setting up Sphinx
# NOTE: You must have sphinx compiled with mysql from the previous step.
# You may skip this step if you do not wish to have Sphinx and continue to PHP.

cd /root/src/sphinx*
./configure --prefix=/opt/sphinx --with-mysql
make install

# The init script used by Sphinx requires sudo.
yum -y install sudo

# Setup the default config
/bin/cp /root/sphinx.conf /opt/sphinx/etc/sphinx.conf

# Setup the init scripts
cp contrib/scripts/searchd /etc/init.d/
chmod 777 /etc/init.d/searchd
ln -s /etc/init.d/searchd /etc/init.d/S55searchd

# Create the sphinx system account and ensure everything under /opt/sphinx/var is owned by sphinx.
useradd -r searchd
cd /opt/sphinx
chown -R searchd:searchd var

# Setup PHP as a module for apache:

cd /root/src/php*/
./configure --prefix=/opt/php5 --with-apxs2=/opt/apache/bin/apxs --with-config-file-path=/etc/ --with-gd --enable-shmop --enable-track-vars --enable-ftp --enable-sockets --enable-exif --enable-zip --enable-sysvsem --with-zlib --enable-sysvshm --enable-magic-quotes --with-jpeg-dir --with-png-dir --enable-mbstring --enable-embedded-mysqli=shared --with-curl --with-mcrypt --with-mysql=/opt/mysql --with-mysqli=/opt/mysql/bin/mysql_config
# If you want imap support: use options --with-imap --with-imap-ssl=/usr/include/openssl --with-kerberos
make install

# At this stage, apache should have the PHP module installed.
# NOTE: Since apache does not come with an init script, you must install
# this manually. Refer to for the complete
# script. Ensure to change the path (in red) to the correct path to httpd.
# In this case, /opt/apache/bin/httpd

Leave a Reply

Your email address will not be published.