Setting Up a Web Server on Arch Linux

Avatar photo

Karoline

Arch Linux is known for its simplicity, flexibility, and user-centric approach. For developers and system administrators, it offers full control over system configuration, making it an excellent choice for setting up a web server. In this guide, we’ll walk through the process of setting up a web server on Arch Linux, covering installation, configuration, and essential security practices.

Why Choose Arch Linux for a Web Server?

Arch Linux follows a rolling-release model, ensuring access to the latest software packages. Unlike other distributions, it allows users to build their system from the ground up, installing only what is necessary.

Key advantages include:

  • Lightweight and minimal installation
  • Full control over configurations
  • Access to the Arch User Repository (AUR)
  • Up-to-date software packages

These features make Arch Linux ideal for customized and high-performance web server setups.

Prerequisites

Before setting up your web server, ensure you have:

  • A fresh installation of Arch Linux
  • Root or sudo privileges
  • Stable internet connection
  • Basic knowledge of Linux commands

Update your system to ensure all packages are current: sudo pacman -Syu

Step 1: Install a Web Server (Apache)

The most commonly used web server is Apache HTTP Server. To install it on Arch Linux, run:

sudo pacman -S apache

After installation, start and enable the service:

sudo systemctl start httpd
sudo systemctl enable httpd

You can verify if the server is running by opening your browser and navigating to:

http://localhost

If everything is set up correctly, you should see the Apache default welcome page.

Step 2: Configure Apache

The main configuration file for Apache is located at:

/etc/httpd/conf/httpd.conf

Open it using a text editor:

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

Key configurations:

  • ServerName: Uncomment and set it to your domain or IPServerName localhost
  • DocumentRoot: Default directory for web filesDocumentRoot "/srv/http"

Place your website files in /srv/http.

Restart Apache after making changes:

sudo systemctl restart httpd

Step 3: Install PHP (Optional)

If you want to run dynamic websites, you can install PHP:

sudo pacman -S php php-apache

Then edit the Apache configuration file to enable PHP support by adding:

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

Restart Apache:

sudo systemctl restart httpd

Create a test PHP file:

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

Visit http://localhost/info.php to confirm PHP is working.

Step 4: Install and Configure MySQL (MariaDB)

For database support, install MariaDB:

sudo pacman -S mariadb

Initialize the database:

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

Start and enable the service:

sudo systemctl start mariadb
sudo systemctl enable mariadb

Secure the installation:

sudo mysql_secure_installation

Step 5: Set Up Firewall

Security is critical for any web server. Install and configure a firewall such as UFW:

sudo pacman -S ufw
sudo systemctl enable ufw
sudo systemctl start ufw

Allow HTTP and HTTPS traffic:

sudo ufw allow 80
sudo ufw allow 443

Step 6: Test Your Web Server

Create a simple HTML file:

echo "<h1>My Arch Linux Web Server</h1>" | sudo tee /srv/http/index.html

Open your browser and go to:

http://localhost

If you see your message, your web server is successfully set up.

Optional: Using Nginx Instead of Apache

You can also use Nginx as an alternative:

sudo pacman -S nginx
sudo systemctl start nginx
sudo systemctl enable nginx

Nginx is known for its performance and is often preferred for high-traffic websites.

Best Practices for Maintenance

To keep your server running smoothly:

  • Regularly update your system
  • Monitor logs (/var/log/httpd/)
  • Use SSL certificates (e.g., Let’s Encrypt)
  • Backup your data frequently
  • Limit user permissions

Conclusion

Setting up a web server on Arch Linux provides flexibility, control, and performance. While it requires manual configuration, the process helps you understand the underlying system and tailor it to your needs.

By installing Apache (or Nginx), configuring PHP and MariaDB, and implementing security measures, you can build a fully functional and secure web hosting environment. With proper maintenance and updates, your Arch Linux server can handle both personal projects and production workloads efficiently.

FAQs

1. Is Arch Linux good for web servers?

Yes, Arch Linux is excellent for web servers due to its flexibility, minimalism, and access to the latest software.

2. Which web server is better: Apache or Nginx?

Apache is easier to configure, while Nginx offers better performance for high-traffic sites.

3. Do I need a database for a web server?

Not always. Static websites don’t require a database, but dynamic applications usually do.

Karoline

She is a creative and dedicated content writer who loves turning ideas into clear and engaging stories. She writes blog posts and articles that connect with readers. She ensures every piece of content is well-structured and easy to understand. Her writing helps our brand share useful information and build strong relationships with our audience.

Related Articles

Leave a Comment