Installing Apache and PHP on Fedora/CentOS Systems

Before we begin this tutorial, we first note that newer Fedora releases have now adopted dnf (Dandified Yum) as the default package manager in place of yum.

1) Install the Apache HTTP Server

Login as root

					
						su -
					
				

We first fetch the system's packages and update them to their newer versions

					
						dnf update
					
				

In Fedora/CentOS systems, the Apache web server can be installed by typing the below command at the terminal

					
						dnf install httpd
					
				

Check the version number to verify if it is installed properly

					
						httpd -v
					
				
php httpd version

2) Start Apache

The Apache web server can be started by typing the below command into the terminal

					
						service httpd start
					
				
php service httpd start

But as we see the redirect to /bin/systemctl, we can also start by running

					
						systemctl start httpd
					
				

After starting the server, type http://localhost in the URL bar of your web browser. It should display the Apache Test Page on Fedora shown below

php test page in fedora
Fedora Test Page

The command for restarting Apache is similar to starting it. Just run the command

					
						systemctl restart httpd
					
				

and for stopping, run

					
						systemctl stop httpd
					
				

3) Install PHP

To install PHP, we run the command

					
						dnf install php
					
				

We also install the php-common package, which contains files used by both the php and the php-cli packages.

					
						dnf install php-common 
					
				

Verify the installation by checking the PHP version

					
						php -v