Build a LAMP stack (Linux, Apache, MySQL, PHP) - CentOS 7
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 systemctl start httpd.service
- Set Apache to start on server boot:
sudo systemctl enable httpd.service
- Verify that Apache is installed by going to:
http://your server's IP address.
If Apache is installed, the Apache Test Page displays.
Note: GoDaddy Cloud Server customers can use Find your server's IP.
- Install MariaDB, which is a community-developed fork of MySQL:
sudo yum install mariadb-server mariadb
- Start the service:
sudo systemctl start mariadb
- Set MySQL to start on server boot:
sudo systemctl enable mariadb.service
- 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 the security configuration. It is a best practice to respond "Y" to these system prompts
- Install PHP:
sudo yum install php php-mysqlEnter "Y" to install.
- Restart Apache:
sudo systemctl restart httpd.service
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. To view the description of a specific package, use the following command:
yum info the name of the package you want to use
- 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 it worked, 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.