Complete Guide: Initial Server Setup with AlmaLinux 8, Including PHPMyAdmin, MySQL, SSL Apache, and PHP Configuration


Setting up a new server can be a daunting task, especially if you’re new to server administration. AlmaLinux 8, a robust and open-source Linux distribution, provides a reliable platform for hosting websites and web applications. In this comprehensive guide, we will walk you through the process of setting up your AlmaLinux 8 server from scratch. We will cover essential steps such as server provisioning, user management, securing your server with SSL, configuring the Apache web server, installing and configuring MySQL for databases, and setting up PHP and PHPMyAdmin for web development.

1. Server Provisioning

Before you can begin setting up your AlmaLinux 8 server, you need to provision a virtual machine or a physical server. You can choose a hosting provider like Amazon Web Services (AWS), DigitalOcean, or any other provider that suits your needs. Ensure you have the necessary access credentials to connect to your server.

2. Connecting to Your Server via SSH

Once your server is provisioned, you can connect to it via Secure Shell (SSH). SSH allows you to access your server remotely and execute commands securely. You’ll need an SSH client like OpenSSH installed on your local machine. To connect to your server, use the following command, replacing your_server_ip with your server’s IP address:

ssh your_username@your_server_ip

3. Updating the System

After connecting to your server, it’s essential to update the system packages to ensure you have the latest security patches and updates. Use the following command to update your AlmaLinux 8 system:

sudo dnf update

4. Creating a New User

For security reasons, it’s recommended to create a new user with administrative privileges and use that user for day-to-day operations instead of the root user. To create a new user, replace new_username with your desired username:

sudo useradd new_username

5. Granting Administrative Privileges

To grant administrative privileges to the new user, you need to add the user to the “wheel” group. The “wheel” group allows users to run commands with sudo, which is necessary for administrative tasks:

sudo usermod -aG wheel new_username

6. Setting Up SSH Key Authentication

Using SSH keys for authentication is a more secure method than relying solely on passwords. To set up SSH key authentication, generate an SSH key pair on your local machine using the following command:


Follow the prompts, and you’ll have a public key (typically found in ~/.ssh/ and a private key (typically found in ~/.ssh/id_rsa).

Next, copy your public key to the server. You can use the following command, replacing new_username with the username you created:

ssh-copy-id new_username@your_server_ip

You’ll be prompted to enter your user’s password on the server. Afterward, you should be able to SSH into your server without a password, using your SSH key for authentication.

7. Securing SSH Configuration

For added security, you can modify the SSH configuration to further enhance the security of your server. Open the SSH configuration file with a text editor:

sudo nano /etc/ssh/sshd_config

Make the following changes:

  • Disable root login: Set PermitRootLogin to no.
  • Change the default SSH port (optional but recommended).
  • Disable password authentication: Set PasswordAuthentication to no to enforce key-based authentication.
  • Limit SSH access to specific users: Use the AllowUsers directive to specify the users allowed to SSH into the server.

After making these changes, save the file and restart the SSH service:

sudo systemctl restart sshd

8. Installing Apache Web Server

Apache is a popular web server that can host websites and web applications. To install Apache on AlmaLinux 8, use the following command:

sudo dnf install httpd

After installation, start the Apache service and enable it to start on boot:

sudo systemctl start httpd
sudo systemctl enable httpd

You can verify that Apache is running by accessing your server’s IP address or domain name in a web browser. You should see the default Apache welcome page.

9. Configuring Apache for Virtual Hosts

Apache uses virtual hosts to host multiple websites on a single server. You can create virtual host configurations for your websites in separate files under the /etc/httpd/conf.d/ directory. Here’s a basic example of creating a virtual host configuration file for a website:

sudo nano /etc/httpd/conf.d/mywebsite.conf

Add the following content to the configuration file,

replacing mywebsite with your domain or website name:

<VirtualHost *:80>
    DocumentRoot /var/www/mywebsite

Save the file and create the document root directory:

sudo mkdir -p /var/www/mywebsite

Set the appropriate permissions:

sudo chown -R apache:apache /var/www/mywebsite

Finally, restart Apache to apply the changes:

sudo systemctl restart httpd

10. Installing PHP and PHP Modules

PHP is a server-side scripting language commonly used for web development. To install PHP and some essential PHP modules, use the following command:

sudo dnf install php php-mysqlnd php-json php-xml php-mbstring

After installing PHP, restart Apache to enable PHP support:

sudo systemctl restart httpd

You can test if PHP is working by creating a PHP info page. Create a new file in your website’s document root directory:

sudo nano /var/www/mywebsite/index.php

Add the following content to the file:


Save the file and access it through your web browser by visiting http://your_server_ip/index.php. You should see the PHP information page.

11. Installing and Configuring MySQL

MySQL is a popular relational database management system used for storing and managing data for web applications. To install MySQL on AlmaLinux 8, use the following command:

sudo dnf install mysql-server

After installation, start the MySQL service and enable it to start on boot:

sudo systemctl start mysqld
sudo systemctl enable mysqld

Run the MySQL secure installation script to configure MySQL and set a root password:

sudo mysql_secure_installation

Follow the prompts to secure your MySQL installation.

12. Installing PHPMyAdmin

PHPMyAdmin is a web-based graphical user interface for managing MySQL databases. To install PHPMyAdmin on AlmaLinux 8, use the following command:

sudo dnf install phpmyadmin

During the installation process, you’ll be prompted to configure PHPMyAdmin. Choose to configure it for Apache by selecting “apache” and confirm the installation.

Next, create a symbolic link to the PHPMyAdmin directory within your website’s document root:

sudo ln -s /usr/share/phpmyadmin /var/www/mywebsite/phpmyadmin

You can now access PHPMyAdmin by visiting http://your_server_ip/phpmyadmin in your web browser. Log in using your MySQL credentials.

13. Securing Your Server with SSL/TLS

Securing your server with SSL/TLS is crucial for protecting data transmission between the server and clients. You can obtain a free SSL certificate from Let’s Encrypt. To install the Let’s Encrypt client (Certbot) and obtain an SSL certificate, use the following commands:

sudo dnf install certbot python3-certbot-apache

Next, use Certbot to obtain an SSL certificate for your domain:

sudo certbot --apache

Follow the prompts to configure your SSL certificate. Certbot will automatically configure Apache to use SSL.

14. Conclusion

In conclusion, this comprehensive guide has walked you through the process of setting up an AlmaLinux 8 server from scratch, covering essential steps such as server provisioning, user management, securing your server with SSL, configuring the Apache web server, installing and configuring MySQL for databases, and setting up PHP and PHPMyAdmin for web development.

By following these steps, you’ve laid a solid foundation for hosting websites and web applications on your AlmaLinux 8 server. Whether you’re a beginner or an experienced user, mastering the initial server setup process is crucial for a secure and efficient server environment. Happy server administration!

Leave a Comment