Setting up a web server on Fedora using Apache can seem daunting at first, but with a few simple steps, you can have your web server up and running in no time. In this tutorial, we will guide you through the process How to set up a web server on Fedora using Apache
Step 1: Update your system
Before installing Apache, it is important to make sure that your system is up to date. You can do this by running the following command:
sudo dnf update
This will update all the packages on your system to their latest versions.
Step 2: Install Apache
Once your system is up to date, you can proceed to install Apache by running the following command:
sudo dnf install httpd
This command will install Apache along with any necessary dependencies.
Step 3: Start Apache
After installing Apache, you need to start the Apache service by running the following command:
sudo systemctl start httpd
This command will start the Apache service and enable it to start automatically on boot.
Step 4: Configure Apache
The default Apache configuration file is located at /etc/httpd/conf/httpd.conf
. You can open this file using a text editor and make any necessary changes to the configuration.
For example, you can change the default document root directory from /var/www/html
to a different location by editing the following line:
DocumentRoot "/var/www/html"
You can also create a new virtual host by adding the following code to the configuration file:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_html
ErrorLog /var/www/example.com/error.log
CustomLog /var/www/example.com/access.log combined
</VirtualHost>
This code defines a new virtual host for the domain example.com
. You will need to replace example.com
with your own domain name and update the DocumentRoot
, ErrorLog
, and CustomLog
paths to match your own file system.
Step 5: Test your web server
After configuring Apache, you can test your web server by opening a web browser and navigating to http://localhost/
. This should display the default Apache welcome page.
If you configured a new virtual host, you can test it by adding an entry to your /etc/hosts
file to map your domain name to your local IP address. For example:
127.0.0.1 example.com
After adding this entry, you can navigate to http://example.com/
in your web browser to test your new virtual host.
Step 6: Enable Firewall
To allow access to the web server, you need to open the firewall ports for HTTP and HTTPS protocols. You can do this by running the following commands:
sudo firewall-cmd --zone=public --add-service=http --permanent
sudo firewall-cmd --zone=public --add-service=https --permanent
sudo firewall-cmd --reload
This will open the firewall ports for HTTP and HTTPS, and the changes will persist across system reboots.
Conclusion
Setting up a web server on Fedora using Apache is a straightforward process, and by following the steps outlined in this tutorial, Apache is a powerful and flexible web server that can be configured to meet a wide range of needs, so take the time to explore its many features and capabilities.