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.
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.
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.
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.
Once the machine starts and the desktop is loaded, click Install to Hard Drive to install CentOS to the VM hard disk.
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.
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.
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.
We can finally login to CentOS to build our 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.
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.
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
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
To start Apache and MySQL, enter these commands:
service httpd start
service mysqld start
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.
Once entered, mysql will load with a series of prompts. Answer Y to all questions and enter the root password.
Now we can create a new database. To do that, login to MySQL server by typing:
mysql -u root -p
To create a new database:
CREATE DATABASE newdatabase;
CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';
GRANT ALL ON newdatabase.* to 'user'@'localhost';
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:
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
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:
mv html/wordpress/* html/
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!