Cloud Servers Help

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

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. Arch Linux)
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 we begin, use pacman to install any system updates:
    sudo pacman -Syu
  2. Install Apache:
    sudo pacman -S apache
  3. Set Apache to start on server boot:
    sudo systemctl enable httpd.service
  4. Create a test page in the Apache server's document root directory.
    sudo vim /srv/http/index.html
  5. Type or paste the following when the file opens:
    <html>
    <title> Welcome </title>
      <body>
        <h2>Welcome to the test page!</h2>
      </body>
    </html>
  6. Start Apache:
    sudo systemctl start httpd
  7. Verify that Apache is installed by going to:
    http://your server's IP address.
    If Apache is installed, your test page will display.

    GoDaddy Cloud Server customers can use Find your server's IP.

Install MySQL

  1. Install MySQL:
    sudo pacman -S mysql
  2. It presents you with two provider options. Choose 1 to install MariaDB. Type "Y" when prompted.
  3. After the installation is complete, install the data directory:
    sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
  4. Start MySQL:
    sudo systemctl start mysqld.service
  5. Set MySQL to start on server boot:
    sudo systemctl enable mysqld.service
  6. Run this command to finish setting up the installation:
    sudo mysql_secure_installation
  7. You will be asked for the root password. Since you haven't set it earlier, press Enter to set one now.
  8. Type "Y" when asked if you want to set root password.
  9. Enter and confirm the new password.
  10. 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

  1. Install PHP:
    sudo pacman -S php php-apache
    Enter "Y" to install.
  2. In order to configure the way Apache serves its files, you need to make some changes. Open the httpd.conf file:
    sudo vim /etc/httpd/conf/httpd.conf
  3. Under the Dynamic Shared Object (DSO) Support section, add the following line:
    LoadModule php7_module modules/libphp7.so
  4. In the same section, use a # to comment out the following line:
    LoadModule mpm_event_module modules/mod_mpm_event.so
  5. In the same section, remove the # to uncomment the following lines:
    LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
  6. In the DirectoryIndex section, add index.php to the available index files, which will look like this:
    DirectoryIndex index.php index.html
  7. Under the Supplemental configuration section, add the following lines:
    # PHP 7
    Include conf/extra/php7_module.conf
  8. Under the IfModule mime_module section, add the following lines:
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
  9. Save and close the file:
    :wq!
  10. Open your server php.ini file in a text editor.
    sudo vim /etc/php/php.ini
  11. Uncomment the following line to enable the mysqli extension for PHP.
    extension=mysqli.so
  12. Save and close the file.
    wq!
  13. Restart Apache:
    sudo systemctl restart httpd

Test PHP processing on Apache

  1. Create a new PHP file:
    sudo vim /srv/http/info.php
  2. When the file opens, type in the following code:
    <?php
    phpinfo();
    ?>
  3. Save and close the file:
    :wq!
  4. Restart Apache for the changes to take effect:
    sudo systemctl restart httpd
  5. To verify it works, in a browser type:
    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.


Was This Article Helpful?
Thank You For Your Feedback
Glad we helped! Anything more we can do for you?
Sorry about that. How can we be more helpful?