CentOS 6 - LAMP Setup (Apache, MySQL, PhpMyAdmin) Print

  • 20

This is a brief guide to help you setup a CentOS dedicated server to be ready to use for web and MySQL. This will give you a basic LAMP (Apache, MySQL, & PhpMyAdmin) setup.

---
LAMP Installation (Linux, Apache, MySQL, PhpMyAdmin)
---

Before we get started, lets update all of the currently installed server software by running a yum update with the following command below.

yum update -y

Also we recommend installing nano, which is a user friendly SSH text editor:

yum install nano -y

It may take a minute or two to complete, once done it will say "Completed!". Now we can move on to the main steps, which is installing the LAMP stack. First we'll need to install Apache (httpd). We can do this by running:

yum install httpd -y

Once completed start the apache service by running the folllowing command:

service httpd start

Now lets install the MySQL server, we can do this by running the following command:

yum install mysql-server -y

Once completed, start the MySQL server with:

service mysqld start

Now Apache and MySQL are installed. We can run the MySQL server installer now to set a root MySQL password, run the following command:

sudo /usr/bin/mysql_secure_installation

This will bring up the MySQL secure installation script which will look something like this: <image>
1.) It will ask for the current root password for MySQL, by default there is none, so just press Enter for none.
2.) Next it'll ask if you would like to set a root password, type Y for Yes and press Enter. Now it'll ask for you to enter a new MySQL root password, you can enter a password here, usually your servers root password is the easiest option to use. Note: You won't be able to see what you type, so make sure you've entered it correctly.
3.) Once you've entered a new MySQL root password it will ask if you would like to remove anonymous users, it's best to select yes for this, so type Y and press enter.
4.) Next it'll ask if you'd like to disallow root login remotely. By default it's good to disable this, unless you plan to connect to MySQL remotly from another computer using the root user. Press Y for yes and press Enter.
5.) Next it'll ask to remove the test databases, and if you'd like to reload the privileges tables. Press Y for yes and press Enter.

Here is a screenshot of what we've just done and how it should look on your SSH screen: <image>

Now we can proceed to install PHP. We can do this by running the following command:

yum install php php-mysql -y

Once that is completed, we'll need to set add some chkconfig entries to ensure that the installed software runs when your dedicated server is started or rebooted. Run the following commands in SSH:

chkconfig httpd on
chkconfig mysqld on

Next we'll need to change an httpd config option so PhpMyAdmin works correctly. We can do so by editing the httpd.conf file, run the command below:

nano /etc/httpd/conf/httpd.conf

This will open the file in the nano text editor. Find the <Directory "/var/www/html"> section, this is where we will need to edit the AllowOverride None option and change it to AllowOverride All.
View this screenshot if you need help <image>

Now we will need to restart apache by running:

service httpd restart

Now we can download and setup PhpMyAdmin onto your web server, this is a fairly simple task. First navigate to your public web directory by using the following command:

cd /var/www/html

Now we can download the PhpMyAdmin package by running the following command:

wget http://sourceforge.net/projects/phpmyadmin/files/phpMyAdmin/4.2.8.1/phpMyAdmin-4.2.8.1-english.zip/download

Now lets unzip the archive by running:

unzip download*

We can delete the archive that we downloaded, do this by running this command:

rm -rf download

Now lets rename the unzipped directory so it's easier to access in our browser:

mv phpMyAdmin* phpmyadmin

Now we'll need to make a simple change to the configuration file, first navigate into the phpmyadmin folder with:

cd phpmyadmin

Then move the config.sample.inc.php file to config.inc.php:

mv config.sample.inc.php config.inc.php

Now we are done! You now have a basic LAMP stack setup ready with Apache, MySQL and PhpMyAdmin. You can navigate to your PhpMyAdmin login by typing http://0.0.0.0/phpmyadmin (change 0.0.0.0 to your server IP). If it doesn't let you connect, the IPTables firewall might be blocking the connection. In this case we can allow all traffic through the firewall with the following command:

iptables -I INPUT -j ACCEPT
service iptables save

Typically it's not a good idea to allow all traffic through the firewall, so we would recommend only adding firewall access to certain ports, but for testing purposes or general private use this will work. Our network generally filters out bad traffic for you.

If you get a white screen on your PhpMyAdmin page, you'll need to install php-mbstring and restart apache. Do this with "yum install php-mbstring" then type "service httpd restart".

Have a server with us and need more help? Submit a technical support ticket in your client area and we can assist you.


Was this answer helpful?

« Back