In this tutorial, we will show you how to install LAMP Stack on CentOS 6. For those of you who didn’t know, LAMP represents a full-featured stack containing the most popular web server known as Apache, the most popular database server MySQL and the most popular open-source web programming language known as PHP. All components are free and open-source software, and the combination is suitable for building dynamic web pages.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple. I will show you the step-by-step installation of LAMP (Linux Apache, MySQL, and PHP) on the CentOS 6 server.
- A server running one of the following operating systems: CentOS 6.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
non-root sudo useror access to the
root user. We recommend acting as a
non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.
Install LAMP Stack on CentOS 6
Step 1. First of all, make sure that all packages are up to date.
yum -y update
Step 2. Installing Apache on CentOS 6.
We will be installing Apache with yum, which is the default package manager for CentOS 6:
yum install httpd
Start Apache and add it to automatically start on your system start-up using:
chkconfig --levels 235 httpd on service httpd start
You can verify that Apache is really running by opening your favorite web browser and entering the URL
http://your-server's-ip-address and you need to open port 80 to make your web server accessible:
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT /etc/rc.d/init.d/iptables save
Step 3. Installing MySQL on CentOS 6.
Install MySQL with the following command to begin the install:
yum install mysql-server
After that add it to your system startup and start the MySQL server using the following commands:
chkconfig --levels 235 mysqld on service mysqld start
By default, MySQL is not hardened. You can secure MySQL using the
mysql_secure_installation script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MySQL:
To log in to MySQL, use the following command (note that it’s the same command you would use to log into a MySQL database):
mysql -u root -p
Step 4. Installing PHP on CentOS 6.
Finally, run the commands below to install PHP along with other good-to-have modules:
yum install php php-mysql
You may want to install some other PHP extensions required by your applications. The following is a list of the available PHP modules:
php-bcmath => A module for PHP applications using the bcmath library php-cli => Command-line interface for PHP php-common => Common files for PHP php-dba => A database abstraction layer module for PHP applications php-devel => Files needed for building PHP extensions php-embedded => PHP library for embedding in applications php-enchant => Human Language and Character Encoding Support php-gd => A module for PHP applications using the gd graphics library php-imap => A module for PHP applications that use IMAP php-intl => Internationalization extension for PHP applications php-ldap => A module for PHP applications that use LDAP php-mbstring => A module for PHP applications which need multi-byte string handling php-mysql => A module for PHP applications that use MySQL databases php-odbc => A module for PHP applications that use ODBC databases php-pdo => A database access abstraction module for PHP applications php-pear.noarch => PHP Extension and Application Repository framework php-pecl-apc => APC cache optimizing PHP intermediate code php-pecl-memcache => Extension to work with the Memcached caching daemon php-pgsql => A PostgreSQL database module for PHP php-process => Modules for PHP scripts using system process interfaces php-pspell => A module for PHP applications using pspell interfaces php-recode => A module for PHP applications using the recode library php-snmp => A module for PHP applications that query SNMP-managed devices php-soap => A module for PHP applications that use the SOAP protocol php-tidy => Standard PHP module provides tidy library support php-xml => A module for PHP applications which use XML php-xmlrpc => A module for PHP applications which use the XML-RPC protocol php-zts => Thread-safe PHP interpreter for use with the Apache HTTP Server
Restart apache so all the changes take effect:
service httpd restart
To test PHP, create a test file named info.php with the content below. Save the file, then browse to it to see if PHP is working:
<?php phpinfo(); ?>
Congratulations! You have successfully installed LAMP. Thanks for using this tutorial for installing LAMP (Linux Apache, MySQL, and PHP) on CentOS 6 system. For additional help or useful information, we recommend you to check the official Apache, MySQL, and PHP web site.