This is a short guide that will show you how to install Apache, PHP, MySQL, and MSSQL Extensions on a CentOS5 Server or VPS. All “quote” blocks are to be executed in SSH (shell) as root.
Getting the server ready to build applications from source:
Check for any RPM installations of the applications.
rpm -qa | grep -i apache rpm -qa | grep -i httpd rpm -qa | grep -i php rpm -qa | grep -i mysql
Remove any RPM installations found with the “rpm -e” command:
rpm -e application_name_here
Install some base requirements to compile and install the software.
yum -y install gcc gcc-c++ ncurses-devel libxml2-devel libpng-devel
Download the appropriate sources for Apache, PHP, and MySQL and decompress it.
cd /usr/src wget http://us3.php.net/get/php-5.2.11.tar.gz/from/us.php.net/mirror wget http://apache.inetbridge.net/httpd/httpd-2.2.14.tar.gz wget http://downloads.mysql.com/archives/mysql-5.0/mysql-5.0.87.tar.gz wget ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz tar xzf php-5.2.11.tar.gz tar xzf httpd-2.2.14.tar.gz tar xzf mysql-5.0.87.tar.gz tar xzf freetds-stable.tgz
Build and Install MySQL.
Add the MySQL User and Group
groupadd mysql useradd -g mysql -c "MySQL Server" mysql
Install MySQL.
cd mysql* chown -R root.root * make clean ./configure \ --prefix=/usr/local/mysql \ --localstatedir=/usr/local/mysql/data \ --disable-maintainer-mode \ --with-mysqld-user=mysql \ --with-unix-socket-path=/tmp/mysql.sock \ --without-comment \ --without-debug \ --without-bench make && make install
Configure MySQL.
/usr/local/mysql/bin/mysql_install_db chown -R root:mysql /usr/local/mysql chown -R mysql:mysql /usr/local/mysql/data cp support-files/my-medium.cnf /etc/my.cnf chown root:sys /etc/my.cnf chmod 644 /etc/my.cnf
Set MySQL to start on boot
echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf ldconfig cp ./support-files/mysql.server /etc/rc.d/init.d/mysql chmod +x /etc/rc.d/init.d/mysql /sbin/chkconfig --level 3 mysql on service mysql start
This sets up symlinks for all MySQL binaries so that they can be run from anywhere.
cd /usr/local/mysql/bin for file in *; do ln -s /usr/local/mysql/bin/$file /usr/bin/$file; done
Set a MySQL Root Password for security (obviously use something other than “new-password-here”.
mysqladmin -u root password new-password-here
Test the Password:
mysql -u root -p
While logged into MySQL delete the test database.
drop database test; use mysql; delete from db; delete from user where not (host="localhost" and user="root"); flush privileges;
Building Apache
cd /usr/src/httpd* make clean ./configure \ --prefix=/usr/local/apache \ --enable-shared=max \ --enable-module=rewrite \ --enable-module=so make && make install
Build and Install FreeTDS for MSSQL Extension Support.
cd /usr/src/freetds* ./configure make && make install
Build and Install PHP
cd /usr/src/php* ./configure \ --with-apxs2=/usr/local/apache/bin/apxs \ --disable-debug \ --enable-ftp \ --enable-inline-optimization \ --enable-magic-quotes \ --enable-mbstring \ --enable-mm=shared \ --enable-safe-mode \ --enable-track-vars \ --enable-trans-sid \ --enable-wddx=shared \ --enable-xml \ --with-dom \ --with-gd \ --with-gettext \ --with-mysql=/usr/local/mysql \ --with-regex=system \ --with-xml \ --with-zlib-dir=/usr/lib \ --with-mssql=/usr/local/ make && make install cp php.ini-dist /usr/local/lib/php.ini
I prefer to symlink configuration files to /etc so that they are easy to find and edit.
ln -s /usr/local/lib/php.ini /etc/php.ini ln -s /usr/local/apache/conf/httpd.conf /etc/httpd.conf
Edit the Apache Configuration File – I prefer nano.
nano /etc/httpd.conf
Uncomment the following lines or add them (uncommented) if they do not exist after “AddType application/x-tar .tgz”
#AddType application/x-httpd-php .php #AddType application/x-httpd-php-source .phps
Find the DirectoryIndex (CTRL+W in Nano) and add index.php to the beginning.
DirectoryIndex
Set Apache to start on boot and start it for the first time.
ln -s /usr/local/apache/bin/apachectl /etc/rc.d/init.d/apache ln -s /etc/rc.d/init.d/apache /etc/rc.d/rc3.d/S90apache /etc/rc.d/init.d/apache start
Then, you must configure FreeTDS to point to your MSSQL DB server. To do so, edit (or create) the /usr/local/etc/freetds.conf file and put in there exclusively these lines:
[global] host = xxx.xxx.xxx.xxx (ip of the MSSQL server) port = 1433 client charset = UTF-8 tds version = 7.0 (or 8.0 if using FreeTDS 0.82 or later) text size = 20971520
This is what i’ve been searching for…
Good post Mike …
I want to update my apache to a new realease one… and got stuck on its…
But after i follow all the step in your site i finally get my server run again…
Thanks for Your great share…
I already bookmark this site ^^
Thanks in advance…
Glad I could help 🙂
Hello Mike,
Thanks for the article. It’s really helpful.
But I came across a problem.
I connected to MSSQL server from a php applcation hosted in Windows. It was successful.
But when i tried to do the same hosted in a Linux platform with the installation as per your tutorial i wasn’t able to connect to MSSQL server.
It results the following error,
I tried PING, TELNET with 1433 port. Everything works fine.
Then i tried “tsql” command and it resulted the following error,
“Adaptive Server Connection Failed”
Is it a problem of FreeTDS or something else. I couldn’t figure it out. Could you please help me figure out what’s the problem in my case.
Your help would be highly appreciated.
@Gaurav
I haven’t actually used it myself – I just compiled the guide for a friend who needed to know how to do it and then made it available. I have obviously used LAMP but I’ve not used the MSSQL portion personally and I usually leave it out when I’m building something custom unless the customer asks for it specifically.
Thanks a lot Mike. It was a good tutorial. I managed to install Apache,PHP,Mysql and FreeTDS. Its working…
Good Job Mike