Build a LAMP stack (Linux, Apache, MySQL, PHP) - CentOS 6
Time: 20 minutes
To build a dynamic web application, you need what has been coined a “stack” - which is developer lingo for an integrated set of software that has all of the components your application needs.
Most stacks have the same types of components and differ mainly in which pieces of software they use for those components. For example, we’ll look at LAMP (which this article covers):
|Operating system||Linux (e.g. CentOS)|
If you're astute, maybe you noticed that LAMP is just an acronym for the software the stack uses.
In this guide, we'll walk you through installing all of these components (except for Linux, which is already installed as your OS when you create the server).
- Before you begin any installation, make sure that your software is up to date:
sudo yum update
- Install Apache:
sudo yum install httpd
- Start Apache:
sudo service httpd start
- Set Apache to start on server boot:
sudo chkconfig httpd on
- Verify that Apache is installed by going to:
http://your server's IP address.
If Apache is installed, the Apache Test Page displays.
GoDaddy Cloud Server customers can use Find your server's IP.
- Install MySQL:
sudo yum install mysql mysql-server
- After the installation is complete, start the service:
sudo service mysqld start
- Set MySQL to start on server boot:
sudo chkconfig mysqld on
- Run this command to finish setting up the installation:
- You will be asked for the root password. Because you didn't set it earlier, press Enter to set a password now.
- Type "Y" to set the root password.
- Enter and confirm the new password.
- You will be asked more questions as part of security configuration. It is a best practice to respond "Y" to these system prompts.
- Install PHP
sudo yum install php php-mysql
- Enter "Y" to install.
- Restart Apache:
sudo service httpd restart
Install PHP modules
If your applications requires any PHP modules, you can install them now.
- View available PHP modules:
yum search php-
- The list displays the available PHP modules. If you want to get more information on a specific package, you can display the description by typing:
yum info name of package you want to install
- Install the package you want:
sudo yum install the name of the package you want to use
Test PHP processing on Apache
- Create a new PHP file under the
/var/www/htmldirectory:sudo vim /var/www/html/info.php
- When the file opens, type in the following code:
<?php phpinfo(); ?>
- Save and close the file:
- To verify that it works, type this URL in your browser:
http://your server's IP address/info.php
A page displays with the PHP version, extensions, build date, and other information.
Now that you have a LAMP stack, we recommend setting up Apache Virtual Hosts for your websites: