Install MySQL, Apache and PHP from source on Linux

I’ve always wanted to have somewhere written down all the exact commands that will install a functional LAMP (Linux Apache MySQL PHP) server.

I wrote them in a text file an year ago, i found them couple of days ago and decided to try them on a fresh Slackware server.

bash-3.1# uname -a
Linux slackware #2 SMP Mon Aug 17 00:52:54 CDT 2009 i686 Pentium III (Katmai) GenuineIntel GNU/Linux

I thought there are other people like me who need these command so check them out. If you have anything to add please comment.

In your home root create a folder /kits/. Mine is /home/serban/kits.

1. Install MySQL

groupadd mysql
useradd -g mysql -c "MySQL Server" mysql

If you get any message like: groupadd: cannot lock /etc/group; try again later. this means you are not logged as root. Try ‘su‘ and enter password, or ‘sudo su‘ if you are at the console.

Browse to scroll and choose ‘Generic Linux (Architecture Independent), Compressed TAR Archive’ (around 22Mb) and download it.

tar -zxvf mysql-5.1.45.tar.gz
cd mysql-5.1.45
./configure --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data --with-mysqld-user=mysql --with-unix-socket-path=/tmp/mysql.sock --with-charset=utf8

If somewhere during config you get ‘checking for termcap functions library… configure: error: No curses/termcap library found‘, try this: locate libncurses , look for a path like /lib/, the add the line ‘–with-named-curses-libs=/lib/′ to your config and run again.

If you get ‘/bin/rm: cannot remove `libtoolT’: No such file or directory‘ at the end of the configure, this is actually not a MySQL bug, read: ; If you can’t fix it don’t worry about it.

make && make install
root@slack:/home/kit/mysql-5.1.22-rc# ./scripts/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
cp ./support-files/mysql.server /etc/rc.d/mysql
chmod +x /etc/rc.d/mysql

Test the MySQL server:

root@slackware:~/kits/mysql-5.1.45# /etc/rc.d/mysql start
root@slackware:~/kits/mysql-5.1.45# /etc/rc.d/mysql stop
Shutting down MySQL SUCCESS!

 2. Installing Apache

 Browse to and download the Unix Source .tar.gz file

tar -zxvf httpd-2.2.6.tar.gz
cd httpd-2.2.6
./configure --prefix=/usr/local/apache2 --enable-shared=max --enable-rewrite --enable-module=so --enable-ssl --enable-deflate --enable-vhost-alias
make && make install

3. Installing PHP

tar -zxvf php-5.2.4.tar.gz
cd php-5.2.4
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql --with-curl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-exif --with-zlib --with-gd
make && make install
cp php.ini-dist /usr/local/php/lib/php.ini
pico /usr/local/php/lib/php.ini

Notice that we have added cURL library to the PHP configuration. If that is not already installed on your Linux distro do this (the following applies to any additional module you need to PHP):

Browse to: ;

cd /home/kit/
tar -zxvf curl-7.17.0.tar.gz
cd curl-7.17.0
make && make install

4. Configuring Apache to work with PHP

pico httpd.conf

Find the ‘DirectoryIndex’ line and modify it like this:

<IfModule dir_module>
    DirectoryIndex index.html index.htm index.php

Find lines with ‘AddType’ (might be commented), add the following:

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Save the conf and let’s run a test:

/usr/local/apache2/bin/apachectl configtest

Should give you something like:

httpd: Could not reliably determine the server's fully qualified domain name, using for ServerName
Syntax OK

Now create a shortcut for apache daemon

source :

This entry was posted in ubuntu. Bookmark the permalink.

Leave a Reply

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


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>