Lamp

How to Install the LAMP Stack on Arch Linux

If you’re looking to set up a web server on your Arch Linux machine, a LAMP stack (Linux, Apache, MySQL, PHP) provides a powerful and flexible platform for developing and hosting web applications. In this post, we will walk you through the installation process of each component of the LAMP stack on Arch Linux.

Prerequisites

Before we start, ensure you have the following:

  • A clean installation of Arch Linux.
  • Administrative (root) access to your system.
  • An internet connection to download the required packages.

Let’s dive into the installation process!

Step 1: Update Your System

Always start by updating your package database and upgrading the installed packages on your Arch system. Open your terminal and run:

sudo pacman -Syu

Step 2: Install Apache

Apache is a widely-used web server that acts as the foundation of our LAMP stack.

  1. Install Apache: Use the following command to install the Apache web server:
   sudo pacman -S apache
  1. Start and Enable Apache: To start and enable Apache to run at boot, execute:
   sudo systemctl start httpd
   sudo systemctl enable httpd
  1. Test Apache: Open your web browser and navigate to http://localhost/. You should see the Apache default welcome page, which indicates that Apache is installed and running successfully.

Step 3: Install MySQL (MariaDB)

MariaDB is a community-developed fork of MySQL that you can use to manage your databases.

  1. Install MariaDB: Execute the following command to install MariaDB:
   sudo pacman -S mariadb
  1. Initialize the Database: Once the installation is complete, you need to initialize the database:
   sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
  1. Start and Enable MariaDB: Start the MariaDB service and enable it to run on startup:
   sudo systemctl start mariadb
   sudo systemctl enable mariadb
  1. Secure Your Installation: Run the following command to improve the security of your MariaDB installation:
   sudo mysql_secure_installation

This will guide you through setting up a root password and removing insecure default settings.

Step 4: Install PHP

PHP is the scripting language that powers dynamic web content.

  1. Install PHP and Required Extensions: Use the following command to install PHP along with some common extensions used in web applications:
   sudo pacman -S php php-apache php-mysql
  1. Configure Apache to Work with PHP: Open the Apache configuration file located at /etc/httpd/conf/httpd.conf in your favorite text editor:
   sudo nano /etc/httpd/conf/httpd.conf

Find the section that says:

   #LoadModule php_module modules/libphp.so

Remove the # in front of this line to uncomment it. Additionally, add the following line to the configuration file to ensure that Apache recognizes .php files:

   AddHandler php-script .php

Save the file and exit.

  1. Restart Apache: After editing the configuration file, restart Apache for the changes to take effect:
   sudo systemctl restart httpd

Step 5: Test You Your PHP Installation

Create a test PHP file in the root directory of your web server:

sudo nano /srv/http/info.php

Add the following code to the file:

<?php
phpinfo();
?>

Save and exit the editor. Now open your web browser and go to http://localhost/info.php. You should see a page displaying information about your PHP installation.

Conclusion

Congratulations! You have successfully installed the LAMP stack on your Arch Linux system. This powerful combination of software will allow you to develop and host a wide variety of web applications. With the basics in place, you can now explore setting up frameworks like Laravel or CodeIgniter or dive into developing with CMS platforms like WordPress or Joomla.