CentOS Lamp Server

It doesn’t matter what operating system is installed on your computer, you can install a fully functional LAMP server for CentOS in the matter of minutes on your personal computer. This tutorial will show you how in the matter of minutes. In this tutorial, we will install CentOS on a virtual machine. We will also install Apache, MySQL server, and php. Finally, we will get WordPress ready for installation through the command line.

First of all, if you aren’t running CentOS on your computer, you will need to install VirtualBox by Oracle. You can download VirtualBox by clicking the link and downloading the proper version for your OS. Next you will need to download a CentOS live cd iso file from one of the mirrors.

If you already have CentOS installed, skip the next few paragraphs unless you want be real safe. If that’s the case, go ahead and install the VirtualBox app to your machine.

Once VirtualBox is installed, let’s create a new virtual machine.

New Virtual Machine - CentOS Lamp Server

Create a new virtual machine to install CentOS LAMP Server.

Give the VM a name and a hard disk. For this tutorial, I am going to leave my all settings at default. The hard disk drive will be 8GB by default.

Create a virtual hard disk - CentOS LAMP Server

Create a virtual hard drive for your CentOS LAMP server.

Our last step prior to launching our CentOS virtual box is to mount the live cd iso file that we have downloaded. To do this, right click the new VM and select settings. Click storage, choose IDE drive and click the small CD icon.

Choose Disk Image - CentOS LAMP Server

Select the downloaded iso disk image of CentOS to install.

After selecting the live cd image, the VM is now ready to start. To start the VM, double click the name on the left side or click start at the top.

Start the CentOS VM - CentOS LAMP Server

Click start to start the CentOS VM – CentOS LAMP Server

Once the machine starts and the desktop is loaded, click Install to Hard Drive to install CentOS to the VM hard disk.

Click Install to Hard Drive - CentOS LAMP Server

Click Install to Hard Drive – CentOS LAMP Server

You will be prompted to answer several questions. You can leave everything as default and enter the password for Root access. Be sure it is a password that you will remember or you may need to reinstall the VM.

Answer Questions to Install - CentOS LAMP Server

Answer Questions to Install – CentOS LAMP Server

Once complete, power off the virtual machine and go to the storage setting to remove the live cd.

Boot the machine to run for the first time.

Boot the VM - CentOS LAMP Server

Boot the VM CentOS LAMP Server

Whenever you run CentOS for the first time, there is an opportunity for you to create your new user account. You also must answer questions to finalize the installation.

Finalize Installation - CentOS LAMP Server

Finalize Installation – CentOS LAMP Server

We can finally login to CentOS to build our LAMP server.

Login CentOS - CentOS LAMP Server

Login CentOS – CentOS LAMP Server

To install LAMP on our CentOS installation, open Terminal. By the way, the next few commands are exactly the same commands that we will enter into our SSH client to install Apache, php, and MySQL on our production servers.

Open Terminal - CentOS LAMP Server

Open Terminal – CentOS LAMP Server

Everything that we do in terminal needs to be done from root access. When configuring a VPS or Dedicated Server powered by CentOS or RedHat, you will also need root access. Most hosting providers will email you your root access login whenever signing up but some require SSH keys to access the server. For example, Amazon AWS will give you SSH keys to login with while OVH simply emails you the ip address to your VPS along with your root username and password. Type su in Terminal to achieve root access on this CentOS installation.

root access - CentOS LAMP Server

Type su to get root access – CentOS Lamp Server

The following command will install everything needed for a functional LAMP Server.

yum install httpd php php-mysql mysql mysql-server wget zip unzip -y

Install Apache, MySQL, php - CentOS LAMP Server

Install Apache, MySQL, php – CentOS LAMP Server

That command will install apache, php, mysql server, wget, zip, and unzip. This step may take a few minutes depending on the speed of your internet connection.

To configure our LAMP Server to automatically start apache and mysql whenever the machine reboots, enter following commands.

chkconfig --levels 235 httpd on

chkconfig --levels 235 mysqld on

Configure Apache and MySQL for reboot - CentOS LAMP Server

Configure Apache and MySQL for reboot – CentOS LAMP Server

To start Apache and MySQL, enter these commands:

service httpd start

service mysqld start

Start Apache and MySQL - CentOS LAMP Server

Start Apache and MySQL – CentOS LAMP Server

The next step is to configure the database so that our server will be able to host dynamic scripts. To configure MySQL, enter this command.

mysql_secure_installation

Once entered, mysql will load with a series of prompts. Answer Y to all questions and enter the root password.

MySQL Secure Installation - CentOS LAMP Server

MySQL Secure Installation – CentOS LAMP Server

Now we can create a new database. To do that, login to MySQL server by typing:

mysql -u root -p

Create New Database - CentOS LAMP Server

Create New Database – CentOS LAMP Server

To create a new database:

CREATE DATABASE newdatabase;

CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';

GRANT ALL ON newdatabase.* to 'user'@'localhost';

FLUSH PRIVILEGES;

EXIT;

Create database - CentOS LAMP Server

Create database and user – CentOS LAMP Server

Finally we have a functional LAMP Server. If you want to learn how to install WordPress, continue reading.

To install WordPress, let’s change directories and grab the WordPress latest build by entering:

cd /var/www/html

wget http://wordpress.org/latest.tar.gz

Install WordPress - CentOS LAMP Server

Install WordPress – CentOS LAMP Server

This will download the tarball to /var/www/html. To install WordPress, the file must be extracted. In addition, once the files are extracted, this tarball can be deleted. To do this, enter:

tar -xvzf latest.tar.gz

rm -rf latest.tar.gz

Extract WordPress tarball - CentOS LAMP Server

Extract WordPress tarball – CentOS LAMP Server

Delete WordPress tarball - CentOS LAMP Server

Delete WordPress tarball – CentOS LAMP Server

To use the WordPress script, one of two things must happen. We can move the files from the WordPress directory back to the root html directory OR we can modify the httpd.conf file. To keep this simple, we will move the files from WordPress to html directories. This can be done by entering the following:

cd ..

mv html/wordpress/* html/

Move WordPress to html directory - CentOS LAMP Server

Move WordPress to html directory – CentOS LAMP Server

That’s it. WordPress is ready for you to run the configuration in the browser by visiting localhost.

In conclusion, if you are considering a VPS for your website then CentOS is very straightforward to use. One thing to keep in mind is that the iptables may need new rules entered for the VPS. I will post about that in the near future.

Until next time, happy computing!

Comments

comments

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.