In this guide we will go through the process of installing a Linux Apache Mysql PHP installation on a Centos 5 VPS server.
Want a CentOS VPS server to get your very own LAMP setup? Why not sign-up to our CentOS VPS packages today? Sign Up
To get started, you will need to grab a copy of PuTTY and have a fresh/clean installation of CentOS 5.x. This guide does not provide information on how to use PuTTY, so please consult the documentation available on the PuTTY site for how to configure and connect to your server through SSH.
Getting started
We first need to do some prep work for our YUM package manager to enable the RPMforge repository (which is needed for PHPMyAdmin).
Find out which architecture we are using:
[root@test ~]# uname -i i386
i386 means you are running a 32-bit installation of CentOS, x86_64 means you are running a 64-bit installation of CentOS.
Now let’s download the latest RPMforge package. You can find the latest RPMforge rpm download from the CentOS Wiki.
[root@test ~]# mkdir ~/downloads [root@test ~]# cd ~/downloads [root@test downloads]# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.[ARCH].rpm
Replacing [ARCH] with either i386 or x86_64 – depending on your installation.
Now we need to install RPMforge using rpm:
[root@test downloads]# rpm -ivh rpmforge-release-0.5.2-2.el5.rf.*.rpm
And now clean-up the RPM file:
[root@test downloads]# rm -rf rpmforge-release-0.5.2-2.el5.rf.*.rpm
Installing Apache
The next step is to install the Apache web server. YUM provides an easy means of installing Apache quickly and without requiring a lot of configuration changes and is a great way to get a basic installation on your CentOS VPS server.
So let’s get started and install Apache:
[root@test ~]# yum install httpd httpd-devel -y
You should see YUM go through lots of steps and finally a message indicating the installation was a success.
Now that apache has been successfully installed we need to start up the service:
[root@test ~]# service httpd start Starting httpd: [ OK ]
Now we’ll head over to our site to check that apache is up and running and serving the default CentOS 5.x apache test page.
You can do this by visiting http://[ipaddress], replacing [ipaddress] with the main IP address of your server. You should be presented with a default CentOS Apache welcome screen, similar to below:
Ok, so it looks as though apache is up and running on our server so back to our SSH terminal (via PuTTY) to install nano, a text editor that’s easy to use (compared to VI).
Installing Nano
Although not necessarily required to get your LAMP server up and running, Nano is a great text editor to have handy on your CentOS server; Nano is actually a derivative of Pico – and provides an easy to use (slightly more visual) means of editing files.
So let’s get started and install via YUM package manager:
[root@test ~]# yum install nano -y
That’s it! You should then see a message indicating whether the installation was a success or not.
Installing MySQL Database Server
MySQL is the world’s most popular open source database that is supported by a community of open source developers and enthusiasts. With close integration with PHP and Ruby on Rails development stacks, it is a must for web server.
We’ll be installing MySQL server via the YUM package manager and it couldn’t be easier than just one line:
[root@test ~]# yum install mysql mysql-server mysql-devel -y
We’ll then get MySQL started up:
[root@test ~]# service mysqld start Starting MySQL: [ OK ]
Ok, all is looking good so now we will connect to our MySQL server and set our root (admin) password:
[root@test ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.0.77 Source distribution Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> UPDATE user SET Password=PASSWORD('newpassword') WHERE user='root'; Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed: 3 Warnings: 0 mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> quit Bye
Replace ‘newpassword’ with the actual password you wish to use. Be sure to use a strong password (combination of alpha-numeric and UPPER and lower case) to make your installation more secure.
Now let’s re-connect to our MySQL server using our new root password:
[root@test ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.0.77 Source distribution Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> quit Bye
Congratulations, you now have a working installation of MySQL server and have configured your root account with a secure password.
Installing PHP
We will install PHP via the YUM package manager but we will also include the MySQL module, along with some common PHP modules which most installations use:
[root@test ~]# yum install php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml -y
Now that PHP and all of the modules have installed, we will restart the Apache web server so that it picks up the PHP installation:
[root@test ~]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ]
We will now create a PHP information (PHP Info) page to test our installation of PHP:
[root@test /]# nano /var/www/html/phpinfo.php
And enter the text, below:
<?php phpinfo(); ?>
To save, press the CTRL + X key and then press the Y key to save the file. We will now verify our PHP installation by visiting http://[ipaddress]/phpinfo.php. Replacing [ipaddress] with the main IP address of your server.
If your installation was successful, you you created your phpinfo.php file correctly, you should see a screen similar to below:
Now we’re happy with our installation of PHP, we’ll proceed with removing our phpinfo.php file (security through obscurity):
[root@test /]# rm -rf /var/www/html/phpinfo.php
Installing PHPMyAdmin
phpMyAdmin is a free open source project that handles administration of MySQL servers and databases over the web. It supports operations such as managing database, tables, fields, relations, indexes, users, permissions and much more. You can still execute SQL statements if you wish, with the convenience of a web interface.
Thanks to our RPMForge repository, we can install PHPMyAdmin directly through the YUM package manager:
[root@test ~]# yum install phpmyadmin
Now that PHPMyAdmin is installed, let’s configure the Apache configuration file so that it is visible from the web:
[root@test ~]# nano /etc/httpd/conf.d/phpmyadmin.conf
Comment out Deny from all line (the # symbol denotes a comment), see below:
# # Web application to manage MySQL # Order Deny,Allow # Deny from all Allow from 127.0.0.1 Alias /phpmyadmin /usr/share/phpmyadmin Alias /phpMyAdmin /usr/share/phpmyadmin Alias /mysqladmin /usr/share/phpmyadmin
To save the changes made, press CTRL + X on your keyboard, followed by the Y key to confirm changes.
Finally, we need to make some configuration updates for cookie based authentication to work:
[root@test ~]# nano /usr/share/phpmyadmin/config.inc.php
Find the line $cfg['blowfish_secret'] and replace the value:
$cfg['blowfish_secret'] = ''; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
Now that we’re done configuring PHPMyAdmin, we need to restart Apache to pick up the changes:
[root@test ~]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ]
Navigate to http://[ipaddress]/phpmyadmin, replacing [ipaddress] with the main IP address of your server. You should be produced with the PHPMyAdmin login screen (see below):
To test your installation works, simply enter the username ‘root’ (without quotes) and your root password (as set on your MySQL installation). You should then see the PHPMyAdmin home screen (see below):
Congratulations – you now have a complete LAMP set-up on your CentOS VPS server. In the next step we will go through the process of installing Webmin, which is a great web user interface for administering your server. This step is optional, but recommended for those who wish to control most aspects of their server over the web.
Installing Webmin
Webmin provides a web-based user interface for system administration for Linux/Unix machines. Using your web browser you can control the setup of new user accounts, configuration of Apache and DNS servers, file sharing and much more. Webmin is great for those who don’t know how to manually configure certain services of configuration files, and lets you manage a system from the console or remotely with ease.
So to get started, we will need to download the latest RPM of Webmin. You can find the latest download by visiting http://www.webmin.com/index.html.
[root@test ~]# cd /root/downloads [root@test downloads]# wget http://sourceforge.net/projects/webadmin/files/webmin/1.530/webmin-1.530-1.noarch.rpm/download
Now that we have downloaded the RPM file, we need to run the installation:
[root@test downloads]# rpm -ivh webmin-*.rpm warning: webmin-1.530-1.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 11f63c51 Preparing... ########################################### [100%] Operating system is CentOS Linux 1:webmin ########################################### [100%] Webmin install complete. You can now login to http://test:10000/ as root with your root password.
As the installation output reveals, you need to visit http://test:10000/ through your web browser to access Webmin. Remember to replace test with your machines IP address. You should then see a Webmin login screen (see below):
To login to Webmin, enter the user name ’root’ (without quotes) along with your root password (for console, not MySQL root password). You should then be redirected to the Webmin administration homepage (see below):
Now to quickly switch back to our SSH terminal, and do some clean-up:
[root@test downloads]# rm -rf webmin-*.rpm
We’re all done! We now have a working installation of Webmin so we can easily administer our CentOS VPS server from the web.
Final steps
Finally, to finish off this tutorial we need to ensure that Apache and MySQL server automatically start each time our server reboots or is booted back up. To do this, simply execute the two commands below:
[root@test downloads]# chkconfig httpd on [root@test downloads]# chkconfig mysqld on
Want a CentOS VPS server to get your very own LAMP setup? Why not sign-up to our CentOS VPS packages today? Sign Up






