Responsive Ads Here

Friday, 13 April 2018

How to Install LAMP on CentOS 6


Introduction

LAMP (Software Bundle) is an archetypal model of web service stacks, named as an acronym of the names of its original four open-source components: Linux operating system, Apache web sever, MySQL database, and PHP language.

In this tutorial, we assume that you have set up a CentOS 6 x64 VPS from scratch and have logged in as root. Non-root users will need to use the sudo command.

Okay, let's begin the tutorial!

Step One: Install Apache as Web Server

To install Apache, open your SSH terminal and input the following commands:
yum -y install httpd mod_ssl
service httpd start

Check if Apache is installed and running properly with:
service httpd status

After finish the installation, you can try it by visiting the IP address of your VPS server from your browser.

Note: If you can't visit the IP address of your VPS from your browser, it might the firewall block your visit by default.

To fix it, you need to open http port 80 and for additonal you can open https port 443 to make your web server accessible:
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/etc/rc.d/init.d/iptables save

/sbin/iptables -I INPUT -p tcp --dport 443 -j ACCEPT
/etc/rc.d/init.d/iptables save

Set Apache to start automatically when the server is rebooted, run the following command:
chkconfig httpd on

Step Two: Install MySQL as Database

To install and start MySQL, open your SSH terminal and input the following commands:
yum -y install mysql-server
service mysqld start

On production servers, you should secure MySQL with the following command:
/usr/bin/mysql_secure_installation

The command prompt will ask for your current MySQL root password. Leave it blank by pressing ENTER.

Then, answer the command prompt as specified below:
Set root password? [Y/n] Y
New password: YourDesiredPassword
Re-enter new password: YourDesiredPassword
Remove anonymous user? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Set MySQL to start automatically when the server is rebooted, run the following command:
chkconfig mysqld on

Step Three: Install PHP as Web Scripting Language

PHP is an open source web scripting language used to build dynamic web pages.

To install PHP on your VPS, open your SSH terminal and input the following command:
yum -y install php php-mysql php-devel php-gd php-pecl-memcache php-xmlrpc php-xml

Install other PHP Modules.
PHP also has a variety of useful libraries and modules that you can add onto your server. You can see the libraries that are available by typing:
yum search php-

Terminal then will display the list of possible modules.

After finishing all of the installation, Restart Apache web server to put all changes into effect by typing:
service httpd restart

Step Four: See PHP Version on your web server

To see PHP Version on your web server, first create a new file:
nano /var/www/html/phpinfo.php

Add this code in the following line:
<?php
phpinfo();
?>

Then Save and Exit and you can check your php info page (make sure you replace the correct one): http://123.45.67.89/phpinfo.php

That's it. You have installed a LAMP stack onto your VPS server.

No comments:

Post a Comment