I have seen people installing Apache, PHP and MySQL from source code on a production server. You should NEVER, NEVER, NEVER install these packages from source on an RPM or DEB based Linux distributions. Did I say “NEVER” enough times to make your realize that it is not a good practice?
Installing from source is bad idea; there are many reasons for this but the major one is that you will be spending a lot of time keeping the system updated. If you love installing from source then I would suggest using a different distribution e.g. Gentoo.
You can build from source if the package is not available in yum but still, try to use “yum” (or “apt-get” on Ubuntu) because it will save a lot of your time when upgrading your packages.
So here is the procedure to Install Apache, PHP and MySQL on a CentOS box.
First of all edit the following file using “vi” or any other editor you prefer (I prefer nano)
Find the line under [centosplus] that reads something like this
enabled = 0
Change it to
enabled = 1
yum install httpd php mysql-server php-mysql php-gd
This will install Apache, PHP, MySQL and many other common packages
All you need now is to start Apache (httpd) and MySQL (mysqld)
/etc/init.d/httpd start /etc/init.d/mysqld start
Wow, that was easy, so you got Apache, PHP and MySQL running on your system but still needs to be configured to auto-run on server boot (or reboot). Just punch in the following command and it will be done for both Apache and MySQL (you don’t need to do this for PHP since it is already bind to Apache)
/sbin/chkconfig httpd --level 345 on /sbin/chkconfig mysqld --level 345 on
345 are basically run level 3, 4 and 5. If you want to study more about Run Levels please consult this article.
That’s it, these simple steps will give install Apache, PHP, MySQL and all the common packages that you will require. Most importantly, you can update these packages with just
(You may try this command right now but it will not work since you already got all the updated stuff installed)
Updating your system is a breeze now 🙂
Note 1: Please change the password for “root” user in MySQL.
Note 2: Your “DocumentRoot” is /var/www/html.
Update: Added instructions to auto-start Apache and MySQL when system starts / restarts.