One of the most common uses for any Linux system is as a web server. By far the most prevalent and famous web server is Apache. Apache is readily available in Fedora in pre-packaged form. You can use it to host content and applications for free anywhere you have a server.
Installing Apache
First, install the software packages for the Apache server, using the sudo command. The recommended way to install the server is in a group of related packages.
sudo dnf group install "Web Server"
This command installs the entire Web Server package group. The group includes other commonly used tools such as:
- PHP and Perl support
- The squid caching proxy
- Documentation
- Traffic analysis tools
If for some reason you don’t want these helpful packages, you can install the web server by itself. Use this command:
sudo dnf install httpd
The web server package, httpd, depends on some other packages. They must be installed for the web server to function. This command installs those dependencies.
Configuring the system
Next, you may need to configure the system so other computers can contact the web server. You can skip this step if you only want to test a web server on the same computer you’re on.
Fedora systems have a protective firewall by default. Therefore, you must open specific service ports in that firewall to let other computers connect. To open the specific firewall ports for the web server, run these commands:
sudo firewall-cmd --add-service=http --add-service=https --permanent sudo firewall-cmd --reload
The two service ports opened are:
- http — Port 80, used for standard, non-secure web communications
- https — Port 443, used for secure web communications
Also note the reload command makes these services active. Therefore, if you haven’t made other firewall changes permanent, those changes are lost when you reload. If you only want to open these services temporarily, use this command:
sudo firewall-cmd --add-service=http --add-service=https
Testing the web server
Open a web browser on your system. Go to http://localhost and a web page like this appears:
This page confirms your web server is running correctly.
Now what?
The next steps are entirely up to you. Here is one article with ideas for what to do with your new web server.
Image courtesy of Markus Spiske — originally posted to Unsplash.
Allen Halsey
Thanks, the article was helpful.
Curious if there’s a reason you favor
over sudo. With
you don’t need to add a layer of quoting around the commands and you get command completion.
Jonny Heggheim
One reason might be that sudo is not always installed by default, like for the standard lxc-template.
Paul W. Frields
@Jonny: Not just that, but also some system owners forget to make their user accounts admins (so they can easily use sudo after installing). Yes, it’s trivial to setup, but it adds steps to every single tutorial too. So really, no reason to favor one over the other, just universality. Agreed that sudo makes for nicer typing!
Mohammed Tayeh
Thanks, Good and helpful .
Mark
Thank you! Makes it so quick and simple to get apache up and running on Fedora. Just wanted to add that I had to type this at the command line:
apachectl start
…before opening http://localhost
Antti Harittu
Nice article, shows how Linux was built for creation.
Neil Darlow
Do you also need to enable and start the httpd service in systemd before you can access web content?