Build a LAMP stack (Linux, Apache, MySQL, PHP) - CentOS 7

Difficulty: 3
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):

Component LAMP Software
Operating system Linux (e.g. CentOS)
Web server Apache
Database MySQL
Programming language PHP

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).

Install Apache

  1. Before you begin any installation, make sure that your software is up to date:
    sudo yum update
  2. Install Apache:
    sudo yum install httpd
  3. Start Apache:
    sudo systemctl start httpd.service
  4. Set Apache to start on server boot:
    sudo systemctl enable httpd.service
  5. 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 MySQL

  1. Install MariaDB, which is a community-developed fork of MySQL:
    sudo yum install mariadb-server mariadb
  2. Start the service:
    sudo systemctl start mariadb
  3. Set MySQL to start on server boot:
    sudo systemctl enable mariadb.service
  4. Run this command to finish setting up the installation:
    sudo mysql_secure_installation
  5. You will be asked for the root password. Because you didn't set it earlier, press Enter to set a password now.
  6. Type "Y" to set the root password.
  7. Enter and confirm the new password.
  8. 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

  1. Install PHP:
    sudo yum install php php-mysql
    Enter "Y" to install.
  2. Restart Apache:
    sudo systemctl restart httpd.service

Install PHP modules

If your applications requires any PHP modules, you can install them now.

  1. View available PHP modules:
    yum search php-
  2. 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
  3. Install the package you want:
    sudo yum install the name of the package you want to use

Test PHP processing on Apache

  1. Create a new PHP file under the /var/www/html directory:
    sudo vim /var/www/html/info.php
  2. When the file opens, type in the following code:
    <?php
    phpinfo();
    ?>
  3. Save and close the file:
    :wq!
  4. 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.

Next steps

Now that you have a LAMP stack, we recommend setting up Apache Virtual Hosts for your websites.


Czy ten artykuł był pomocny?
Thanks for your feedback. To speak with a customer service representative, please use the support phone number or chat option above.
Cieszymy się, że udało się nam pomóc! Czy coś jeszcze możemy dla Ciebie zrobić?
Przykro nam z tego powodu. Tell us what was confusing or why the solution didn’t solve your problem.