Site icon CentLinux

How to Install LAMP Stack on Arch Linux

Share on Social Media

Learn how to install LAMP Stack on Arch Linux with this step-by-step guide. Set up Apache, MySQL, and PHP to create a powerful web server environment. #centlinux #lampserver #archlinux



What is LAMP Stack?

The LAMP stack is a popular open-source software bundle used for developing and deploying web applications. The acronym LAMP stands for:

The LAMP server provides a robust, scalable, and cost-effective solution for hosting websites and applications, making it a staple in web development.

How to install LAMP Stack on Arch Linux

Why Choose Arch Linux for LAMP Stack?

Choosing Arch Linux for setting up a LAMP stack offers distinct advantages for users who value customization, performance, and control. Here’s why Arch Linux is a great choice for deploying a LAMP stack:

1. Minimal Installation

Arch Linux starts with a bare-bones setup, allowing you to install only the necessary components for your LAMP stack. This results in a lightweight and efficient environment without unnecessary bloat.

2. Cutting-Edge Software

Arch Linux’s rolling release model ensures that you get the latest versions of Apache, MySQL/MariaDB, and PHP, enabling you to leverage the newest features and updates.

3. Customization

With Arch Linux, you have full control over how your LAMP stack is configured. This flexibility allows for precise tuning and optimization to meet the specific needs of your web applications.

4. AUR (Arch User Repository)

The Arch User Repository provides access to a wide range of additional tools and packages that can complement your LAMP stack, making it easy to extend functionality as needed.

5. Performance Optimization

Arch Linux’s lightweight and modular design makes it highly suitable for performance-critical applications, ensuring efficient resource utilization for your LAMP stack.

6. Extensive Documentation

The Arch Wiki offers comprehensive, step-by-step guides for installing and configuring each component of the LAMP stack, making the process straightforward even for those new to Arch.

7. Community Support

Arch Linux’s active community provides robust support, ensuring you can find help and solutions for any challenges you encounter while setting up and managing your LAMP stack.

Arch Linux’s flexibility and modern approach make it an excellent choice for developers and administrators looking to build a reliable, high-performance web server environment.


Prerequisites

Before diving into the installation, ensure you meet the following prerequisites:

Start by updating your system to ensure all packages are current:

sudo pacman -Syu

This command synchronizes your system with the latest updates and patches.


Step 1: Installing Apache on Arch Linux

Apache is one of the most reliable web servers available, providing robust features to serve dynamic web pages.

Use the following command to install Apache on your Arch Linux system:

sudo pacman -S apache

Ensure Apache starts at boot and runs continuously:

sudo systemctl start httpd
sudo systemctl enable httpd

Open your browser and navigate to http://localhost. You should see the Apache default page.

Modify /etc/httpd/conf/httpd.conf to adjust server settings like the document root or enable modules.

Read Also: How to install LAMP Stack on Docker


Step 2: Installing MariaDB on Arch Linux

MariaDB is a fast and secure relational database, a fork of MySQL.

sudo pacman -S mariadb

Before starting MariaDB, initialize the database using:

sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

Start and Enable MariaDB by executing following Linux command.

sudo systemctl enable --now mariadb

Run the security script to set a root password and remove unnecessary test databases:

sudo mysql_secure_installation

Follow the prompts to enhance security.

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] Y
Enabled successfully!
Reloading privilege tables..
 ... Success!


You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Verify MariaDB installation login to database server.

$ mariadb -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 11.6.2-MariaDB Arch Linux

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.001 sec)

MariaDB [(none)]> quit
Bye

Step 3: Installing PHP

PHP is the programming language that allows your server to execute dynamic content.

1. Install PHP:

sudo pacman -S php php-apache

2. Configure Apache for PHP:

Edit the Apache configuration file to include PHP support:

sudo nano /etc/httpd/conf/httpd.conf

Comment and Uncomment the following lines to load PHP modules:

#LoadModule mpm_event_module modules/mod_mpm_event.so
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

Additionally add following lines at the end of httpd.conf file.

LoadModule php_module modules/libphp.so
AddHandler php-script .php
Include conf/extra/php_module.conf

Restart Apache service to apply changes.

sudo systemctl restart httpd

Create a index.php file in the Apache root directory:

echo "<?php phpinfo(); ?>" | sudo tee /srv/http/index.php

Visit http://<Server-IP>/index.php to verify the installation.

PHPInfo Output

Step 4: Configuring the LAMP Server

To make the stack work seamlessly, integrate and test all components.

1. Verify Integration:

Run PHP scripts that connect to the MariaDB database to ensure everything is set up.

2. Configure Virtual Hosts:

Create virtual hosts for serving multiple websites. Edit /etc/httpd/conf/extra/httpd-vhosts.conf and define domains or subdomains.

3. Enable Services:

Ensure Apache and MariaDB services are active on reboot:

sudo systemctl enable httpd mariadb

Read Also: How to install phpMyAdmin on CentOS 8


Step 5: Additional Configuration and Optimization

For advanced features and user-friendly management:

1. Install PHPMyAdmin:

PHPMyAdmin simplifies database management. Install it using:

sudo pacman -S phpmyadmin

Configure PHPMyAdmin in /etc/httpd/conf/extra/phpmyadmin.conf and include it in Apache.

2. Secure Your Server:

3. Performance Tuning:

Use caching tools like memcached or fine-tune database settings for high traffic.


Troubleshooting Common Issues


Conclusion

Installing the LAMP stack on Arch Linux is a straightforward yet rewarding process. This guide equips you with the steps to set up and configure your development environment or live server. Dive deeper into customization to make the most out of this powerful combination.

If you are Looking for a reliable Linux system admin? I offer expert management, optimization, and support for all your Linux server needs, ensuring smooth and secure operations. Have a look at my Fiverr Profile.


FAQs

  1. Why choose Arch Linux for LAMP?
    Arch’s rolling release ensures you always have the latest software versions.
  2. Can I install MySQL instead of MariaDB?
    Yes, but MariaDB is the default choice for Arch due to its performance and compatibility.
  3. How to update LAMP components?
    Use sudo pacman -Syu to keep everything up-to-date.
  4. Is LAMP secure for production?
    With proper configuration and regular updates, LAMP is secure for production use.
  5. What are alternatives to LAMP?
    Alternatives include MEAN (MongoDB, Express, Angular, Node.js) or LEMP (Linux, Nginx, MariaDB, PHP).
Exit mobile version