Apache and PHP are very popular tools used to publish and serve web pages. These web pages can be a simple website, a WordPress installation or a complex web application. In this tutorial, we will learn how to install and use Apache and PHP tools for rpm based distributions like Fedora, CentOS, RedHat.
Update Current Repository and Package Information
Before installing the Apache and PHP tools we need to update current repository information for the latest version information. This will also update the currently installed packages if there are some updates about them. We will provide the
sudo command for the root privileges as the package installation requires this.
$ sudo yum update
Install Apache or Httpd 2.4
Apache is the well-known name of the
httpd which is one of the most popular web server software. In rpm based distributions Apache is named as
httpd and the package is also named as
$ sudo yum install -y httpd httpd-tools mod_ssl
Check Apache Service Status
Apache is a web service and works as a daemon or service. We can star, stop, restart the service. We can also check the Apache service with the
systemctl command like below.
$ systemctl status httpd
We can see from the screenshot that the service is stopped currently and not working.
Start Apache Service
We can start the Apache service with the
systemctl start command by providing the
httpd service name. As this is an administrative task we need to provide the root privileges with the
sudo command. Then we will check service status if it is started properly.
$ sudo systemctl start httpd
We can see from the
httpd status that it started properly without a problem.
Stop Apache Service
If its require we can stop the service with the following
systemctl stop command. This command also requires the root privileges with the
$ sudo systemctl stop httpd
Install PHP 7.3
PHP is popular programming language which is named as
php package in Fedora, CentOS, RedHat. We will also provide some usefull PHP modules like
$ sudo yum install -y php php-devel php-pdo php-mbstring php-gd php-xml php-xmlrpc php-mcrypt php-pear
Test Default Web Page
If the Apache web server is started properly and everything is working correctly we can navigate to the default web page just using
127.0.0.1 like below.
Test PHP with phpinfo()
PHP provides the
phpinfo() function which will provide information about the current PHP installation and details. This information can be API level, Build Date, Debug status, enabled extensions, System information, etc. As the default web page is located at the
/var/www/html/index.html we will change its content to the following.
<?php phpinfo(); ?>