How to Install a LAMP (Apache, MySQL, PHP) stack on CentOS 6.7
In this How-To, we will walk you through the installation of a LAMP stack on a CentOS 6.7 based server. Although we are writing this article in the context of CentOS 6.7, a Linux, Apache, Mysql, PHP(LAMP) server is a common installation stack capable of being hosted on many different Operating Systems. Examples of such are Debian and Debian based distributions like Ubuntu, or RHEL and RHEL based distributions such as Fedora or Scientific Linux. You’ll see these installations occurring on a variety of hosting platforms such as shared web hosting, VPS hosting, dedicated hosting and cloud hosting.
In the case of this article, we’ll be utilizing the YUM package manager associated with the RHEL distribution CentOS.
Prerequisites
A server with CentOS 6.7 installed will take care of the Linux aspect of the LAMP stack install.
Installing Apache on CentOS 6.7
Install Apache with the following command to begin the install:
sudo yum install httpd
Start Apache with the following command:
sudo service httpd start
We can now verify Apache is working by opening your browser and entering the URL
http://your-server's-address
. you should get a blue Apache 2 test page similar to the image below.Note: If you do not know your IP address, run the following command:ip addr show eth0In our example we would puthttp://192.168.100.10
into our browser’s address bar.
Installing MySQL on CentOS 6.7
Install MySQL with the following command to begin the install:
sudo yum install mysql-server
Start the service with the following command
sudo service mysqld start
Set root MySQL password with the following command:
/usr/bin/mysql_secure_installation
Note: You will be prompted with a series of questions. Simply type Y for yes on all of them, see the screen shot below:
Installing PHP on CentOS 6.7
Install PHP with the following command to begin the install:
sudo yum install php php-mysql
Create a test PHP file in the following directory with the following command:
sudo vi /var/www/html/info.php
Insert the following code in the empty space then save and exit:
<?php phpinfo(); ?>
Restart apache so all the changes take effect:
sudo service httpd restart
Test your page in your browser with the following hyperlink changed with your IP address:
http://YOUR.IP.ADD.RESS/info.php
http://YOUR.IP.ADD.RESS/info.php
It is a good idea to remove your php.info file as it can be used to aid an attacker to compromise your server. You can do that with the following command:
sudo rm /var/www/html/info.php
If you would like Apache and MySQL to start on boot, run the following commands:
sudo chkconfig httpd on
sudo chkconfig mysqld on
Congratulations! You have just installed a LAMP stack on your CentOS 6.7 Server. Thank you for following along in this How-To and check back with us for any new updates.
No comments:
Post a Comment