Introduction
Apache is one of the most widely used open-source web servers for hosting websites and web applications. PHP is a popular server-side scripting language, while MySQL is a commonly used relational database management system.
In this article, we will explain how to install and configure Apache, PHP 7, and MySQL on a Red Hat Enterprise Linux 7 (RHEL 7) server. We will also create a simple PHP information page to verify that PHP is working correctly with Apache.
Prerequisites
Before proceeding with the installation, make sure you have the following:
- A server running Red Hat Enterprise Linux 7.
- Root or sudo access to the server.
- An active internet connection to download the required packages.
- A valid IP address or domain name to access the web server.
Implementation
Step 1: Install Apache
Log in to the server and install the Apache HTTP server using the following command:
yum install httpd
This will install Apache HTTP Server 2.4 on the Red Hat 7 server.
Enable Apache to start automatically during system boot:
systemctl enable httpd.service
Start the Apache service:
systemctl start httpd.service
You can verify the Apache service status using:
systemctl status httpd.service
The default Apache document root is:
/var/www/html
Step 2: Enable the EPEL Repository
Install the EPEL repository using:
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Then install the Webtatic repository:
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
Step 3: Install PHP
Install PHP 7 and the required PHP extensions:
yum install php70w php70w-mysql php70w-gd php70w-pear php70w-xml php70w-soap php70w-xmlrpc php70w-mbstring php70w-json php70w-mcrypt
After installing PHP, restart Apache:
systemctl restart httpd.service
You can verify the installed PHP version using:
php -v
Step 4: Create a PHP Information Page
Create a PHP test file inside the Apache document root:
vi /var/www/html/info.php
Add the following content:
<?php
phpinfo();
?>
Save the file and access it from a web browser using the server’s IP address or domain name:
http://IPaddress/info.php
If PHP is installed and configured correctly, the PHP information page will be displayed.
Step 5: Install MySQL
Install MySQL using:
yum install mysql mysql-server
Enable MySQL to start automatically after a system reboot:
systemctl enable mysql.service
Start the MySQL service:
systemctl start mysql.service
Check the MySQL service status:
systemctl status mysql.service
You can also verify the MySQL installation using:
mysql --version
Conclusion
In this article, we covered the basic installation of Apache, PHP, and MySQL on a Red Hat 7 server. We installed Apache and PHP, configured the required PHP extensions, installed MySQL, and created a PHP information page to verify the PHP installation.
This setup provides the basic LAMP stack environment required for hosting many PHP-based websites and applications.
Note: RHEL 7 and several repositories/packages referenced in this procedure are now outdated. For a new production server, it is recommended to use a currently supported RHEL version and supported PHP/MySQL packages.
FAQs
1. What is Apache?
Apache is an open-source web server used to host and serve websites and web applications over HTTP and HTTPS.
2. What is the default Apache document root on Red Hat 7?
The default Apache document root is:
/var/www/html
3. How can I check whether Apache is running?
Use:
systemctl status httpd
4. How can I start Apache?
Use:
systemctl start httpd
5. How can I enable Apache at system boot?
Use:
systemctl enable httpd
6. How can I check the PHP version?
Use:
php -v
Related Articles:
How to Change MySQL User Authentication Plugin for Password? – Pheonix Solutions
How To Move a MySQL Data Directory to a New Location on Ubuntu 20.04? – Pheonix Solutions
Talk to our experts:
Looking for the right technology solution for your business?. Our experts can help with web hosting, domain registration, DevOps and cloud, software development, web applications, mobile applications, and enterprise solutions. Get in touch with our team here.