Setting Up a LAMP Stack on Fedora 41 & Installing WordPress

In this tutorial, we’ll walk you through the process of setting up a LAMP stack (Linux, Apache, MySQL/MariaDB, PHP) on Fedora 41, configuring the necessary firewall and SELinux settings, and installing a WordPress site called “Local Press”. By the end of this guide, you’ll have a lean, fast, and efficient local web development setup.

1. Install Apache (Web Server)

Apache is the most popular web server. Start by installing it with:

sudo dnf install httpd
sudo systemctl enable --now httpd

2. Install MariaDB (Database Server)

MariaDB is a powerful and secure drop-in replacement for MySQL. Install it using:

sudo dnf install mariadb-server
sudo systemctl enable --now mariadb

3. Install PHP (Scripting Language)

WordPress requires PHP, so install the necessary PHP packages along with some common extensions:

sudo dnf install php php-mysqlnd php-fpm php-cli php-common php-json
sudo systemctl restart httpd

4. Firewall Configuration

To allow HTTP and HTTPS traffic through your firewall, run:

sudo firewall-cmd --zone=public --add-service=http --permanent
sudo firewall-cmd --zone=public --add-service=https --permanent
sudo firewall-cmd --reload

5. SELinux Configuration

Why This Matters: SELinux is a security feature that restricts Apache’s access to certain resources. These commands ensure Apache can connect to the database and network without compromising security.

sudo setsebool -P httpd_can_network_connect 1
sudo setsebool -P httpd_can_network_connect_db 1

6. Create a MySQL Database and User

Now that Apache and MariaDB are set up, we’ll create a database for WordPress.

  • Log into MariaDB as the root user:
    sudo mysql -u root -p
  • Create a new database for WordPress:
    CREATE DATABASE localpress;
  • Create a new user with the username localpress and password changemeplease:
    CREATE USER 'localpress'@'localhost' IDENTIFIED BY 'changemeplease';
  • Grant privileges to the user:
    GRANT ALL PRIVILEGES ON localpress.* TO 'localpress'@'localhost';
  • Apply the changes:
    FLUSH PRIVILEGES;
    EXIT;

7. Download and Install WordPress

Now let’s download WordPress and set it up.

sudo mkdir -p /tmp/wordpress
cd /tmp/wordpress
sudo wget https://wordpress.org/latest.tar.gz
sudo tar -xzvf latest.tar.gz
sudo mv wordpress/* /var/www/html/localpress/
sudo rm -rf /tmp/wordpress

8. Configure WordPress to Connect to the Database

  • Copy the sample WordPress configuration file:
    cd /var/www/html/localpress
    sudo cp wp-config-sample.php wp-config.php
  • Edit the wp-config.php file to configure the database details:
    sudo nano wp-config.php

    Update the following lines with your database information:
    define('DB_NAME', 'localpress');
    define('DB_USER', 'localpress');
    define('DB_PASSWORD', 'changemeplease');
    define('DB_HOST', 'localhost');

    Save and exit the file (Ctrl + OEnterCtrl + X).

9. Set Permissions

Set the correct ownership and permissions so Apache can access the WordPress files:

sudo chown -R apache:apache /var/www/html/localpress
sudo chmod -R 755 /var/www/html/localpress

10. Restart Apache

Restart Apache to ensure everything is working properly:
sudo systemctl restart httpd

11. Complete WordPress Installation

  • Open your browser and visit http://localhost/localpress
  • Select your language and fill in the site information:
    • Site Name: Local Press
    • Username: localpress
    • Password: Set a secure password
    • Email: Your email address
  • Click Install WordPress.

Log in with your admin username and password, and you’re ready to start managing your new WordPress site!

Conclusion

You’ve successfully set up a LAMP stack on Fedora 41, configured the firewall and SELinux, and installed a fully functioning WordPress site named Local Press. With a minimal and efficient LAMP setup, you have complete control over your development environment, and the fast performance of this setup makes it a great choice for both local and production use.

You can now start adding content, installing plugins, and developing your site without the extra overhead of unnecessary bloat. Enjoy building with your new local web server running on Fedora 41!


Attendum: Configuring the Firewall for Local Network Access

If you want to view or work on your WordPress site from other devices on the same local network (instead of just the host machine), you’ll need to adjust your firewall settings. By default, Fedora’s firewalld may block access from external devices.

Allow HTTP and HTTPS Traffic

You need to explicitly allow traffic on HTTP (port 80) and HTTPS (port 443) so that web traffic can reach the Apache server. Use the following commands:

sudo firewall-cmd --zone=FedoraWorkstation --add-service=http --permanent
sudo firewall-cmd --zone=FedoraWorkstation --add-service=https --permanent

This ensures that your server can accept HTTP and HTTPS requests.

Allow Access from the Local Network

To make the site available from other devices on your local network, you’ll need to configure firewalld to allow traffic from your local subnet (e.g., 192.168.1.0/24). Run the following command:

sudo firewall-cmd --zone=FedoraWorkstation --add-source=192.168.1.0/24 --permanent

Note: Replace 192.168.1.0/24 with the correct subnet for your network if it’s different.

Apply Changes

After modifying the firewall settings, reload the configuration to apply the changes:

sudo firewall-cmd --reload

Verify the Firewall Settings

Finally, to ensure everything is configured correctly, check the firewall settings:

sudo firewall-cmd --list-all

You should see http and https listed under the services section, and your local network range listed under sources.

Lastly, let’s make sure that the new website displays properly on all devices on the local nework:
sudo nano /var/www/html/localpress/wp-config.php (insert the following two lines after “Happy blogging”). Again, you must use your computer’s IP address and not the placeholder I’ve provided:

define('WP_HOME', 'http://192.168.1.100/localpress'); 
define('WP_SITEURL', 'http://192.168.1.100/localpress');

These changes will allow you to access your WordPress site from any computer on your local network by navigating to the IP address of your Fedora server (e.g., http://192.168.1.100/localpress).

With these firewall adjustments, your site is now open for local network access!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.