- What is Apache?
- What is MariaDB?
- What is MySQL?
- What is PHP?
- List of PHP modules
Step 1: Installing Remi Repository
- On RHEL/CentOS 7
- On RHEL/CentOS 6
- On Fedora 24-22
- On Fedora 21-18
- Step 2: Enabling the Remi Repository
- Step 3: Installing Apache, MariaDB/MySQL, and PHP
This how-to guide explains how to install the latest version of the Apache 2.4, MariaDB/MySQL 5.5, and PHP 5.5/PHP 5.6 along with the required PHP modules on RHEL / CentOS 7/6 and Fedora 18-24.
Install Apache, MySQL/MariaDB and PHP on CentOS/RHEL/Fedora
This combination of operating system (Linux) with web server (Apache), database server (MariaDB/MySQL) and server-side scripting language (PHP) is known as LAMP stack.
Since September 2015, PHP 5.4 is no longer supported by PHP team and it’s reached to end-of-life, still PHP 5.4 ships with RHEL/CentOS 7/6 with minor version change and Red Hat supports it, so upgrading to higher version not required. However, it is highly recommended to upgrade your PHP 5.4 to PHP 5.5+ for greater security and performance.
Here is what your current Linux distribution ships with:
|PHP Current Version||RHEL/CentOS 7||RHEL/CentOS 6|
To do this, we will enable the Remi repository and use yum and dnf (the new package management tool available in Fedora 22-24).
What is Apache?
Apache is a Free and Open Source HTTP web server that runs on most UNIX-based operating systems as well as on Windows. As such, it can be used to serve static web pages and handle dynamic content. Recent reports show that Apache is the number one server used in websites and Internet-facing computers.
What is MariaDB?
MariaDB is a fork of the well-known MySQL, one of the world’s most popular Relational Database Management System (RDBMS). It is entirely developed by the community and as such it is intended to remain FOSS and compatible with the GPL. If you are, or have been, a MySQL user, migrating to MariaDB will be a very straightforward process: the popular commands to connect to, backup and restore, and manage databases are identical in both RDBMSs.
What is MySQL?
MySQL is one of the world’s most popular open source relational database management system (RDBMS) that runs any server by providing multi-user access to multiple databases. MySQL runs with Apache.
What is PHP?
PHP (Hypertext Preprocessor) is a Free and Open Source server-side scripting language that is best suited for web development. It can be used to produce dynamic web pages for a website and is most frequently found in *nix servers. One of the advantages of PHP is that it is easily extensible through the use of a wide variety of modules.
List of PHP modules
We are going to install all these following PHP modules in this article. You can search for more PHP-related modules (perhaps to integrate a specific functionality that your web applications need) with the following command:
------ RHEL/CentOS 7/6 and Fedora 18-21 ------ # yum search all php ------ Fedora 22-24 ------ # dnf search all php
Regardless of the distribution, the above commands return the list of packages in the currently enabled repositories that include the word
php in the package name and / or the description.
Here are the packages that we will install. Please keep in mind that MySQL connectors (PHP, Perl, Python, Java, etc.) will work unchanged with MariaDB as both systems use the same client protocol and the client libraries are binary compatible.
- MariaDB/MySQL (php-mysql) – a dynamic shared object that will add MariaDB support to PHP.
- PostgreSQL (php-pgsql) – PostgreSQL database support for PHP.
- MongoDB (php-pecl-mongo) – An interface for communicating with the MongoDB database in PHP.
- Generic (php-pdo) – A dynamic shared object that will add a database access abstraction layer to PHP.
- Memcache (php-pecl-memcache) – Memcached is a caching daemon designed especially for dynamic web applications to decrease database load by storing objects in memory.
- Memcached (php-pecl-memcached) – An extension that uses the libmemcached library to provide API for communicating with memcached servers.
- GD (php-gd) – A dynamic share object that adds support for using the gd graphics library to PHP.
- XML (php-xml) – A dynamic shared objects that adds support to PHP for manipulating XML documents.
- MBString (php-mbstring) – An extension to handle multi-byte string in PHP applications.
- MCrypt (php-mcrypt) – A Mcrypt library for PHP scripts.
- APC (php-pecl-apcu) – APC module used to optimize and cache PHP code.
- CLI (php-cli) – Command-line interface for PHP.
- PEAR (php-pear) – Application Repository framework for PHP.
Install Apache 2.4, MariaDB/MySQL 5.5 & PHP 5.5/5.6 on RHEL 7/6, CentOS 7/6 and Fedora 18-24
Step 1: Installing Remi Repository
Remi is a repository where you can find the latest versions of the PHP stack (full featured) for installation in the Fedora and Enterprise Linux distributions.
On RHEL/CentOS 7
# yum update && yum install epel-release # rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm ------ For RHEL 7 Only ------ # subscription-manager repos --enable=rhel-7-server-optional-rpms
On RHEL/CentOS 6
# yum update && yum install epel-release # rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm ------ For RHEL 6 Only ------ # subscription-manager repos --enable=rhel-6-server-optional-rpms
On Fedora 24-22
------ For Fedora 24 ------ # wget http://rpms.remirepo.net/fedora/remi-release-24.rpm # dnf install remi-release-24.rpm ------ For Fedora 23 ------ # wget http://rpms.remirepo.net/fedora/remi-release-23.rpm # dnf install remi-release-23.rpm ------ For Fedora 22 ------ # wget http://rpms.remirepo.net/fedora/remi-release-22.rpm # dnf install remi-release-22.rpm
On Fedora 21-18
Other Fedora versions (21 and below) are no longer being maintained or supported. You can, however, enable the repository by changing the version number in the command above. For example, to enable the Remi repository in a Fedora 20 server, do:
------ For Fedora 21 ------ wget http://rpms.remirepo.net/fedora/remi-release-21.rpm yum install remi-release-21.rpm ------ For Fedora 20 ------ wget http://rpms.remirepo.net/fedora/remi-release-20.rpm yum install remi-release-20.rpm ------ For Fedora 19 ------ wget http://rpms.remirepo.net/fedora/remi-release-19.rpm yum install remi-release-19.rpm ------ For Fedora 18 ------ wget http://rpms.remirepo.net/fedora/remi-release-18.rpm yum install remi-release-18.rpm
Step 2: Enabling the Remi Repository
Now you make sure that remi repository is enabled and all set to install chosen PHP version, to do this open
remi.repo file and make sure the line set to
enabled=1 as instructed below, in order to install PHP 5.5 or
[remi] name=Remi's RPM repository for Enterprise Linux 6 - $basearch #baseurl=http://rpms.remirepo.net/enterprise/6/remi/$basearch/ mirrorlist=http://rpms.remirepo.net/enterprise/6/remi/mirror enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Now if you want to install PHP 5.5 or PHP 5.6, just set the line enabled=1 in sections [remi-php55] and [remi-php56] to install as instructed below.
[remi-php55] name=Remi's PHP 5.5 RPM repository for Enterprise Linux 6 - $basearch #baseurl=http://rpms.remirepo.net/enterprise/6/php55/$basearch/ mirrorlist=http://rpms.remirepo.net/enterprise/6/php55/mirror # NOTICE: common dependencies are in "remi-safe" enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi [remi-php56] name=Remi's PHP 5.6 RPM repository for Enterprise Linux 6 - $basearch #baseurl=http://rpms.remirepo.net/enterprise/6/php56/$basearch/ mirrorlist=http://rpms.remirepo.net/enterprise/6/php56/mirror # NOTICE: common dependencies are in "remi-safe" enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Step 3: Installing Apache, MariaDB/MySQL, and PHP
In latest RHEL/CentOS 7 distribution, MariaDB is a drop-in replacement for MySQL and in RHEL/CentOS 6MySQL remains same and you’re not allowed to install MariaDB on RHEL/CentOS 6 from default repository, but you can install MariaDB using official MariaDB repository.
For MariaDB Installation on RHEL/CentOS 7 and Fedora 18-24
To enable the MariaDB repository on RHEL/CentOS 7 distributions, create a file named
/etc/yum.repos.d/mariadb.repo with the following contents:
[mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.1/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
Note: As i said above, you can also install MariaDB on RHEL/CentOS 6 using official MariaDB repository as stated above.
After enabling MariaDB repository, then do:
------ On RHEL/CentOS 7 ------ # yum --enablerepo=remi install httpd MariaDB-client MariaDB-server php php-common ------ On Fedora 22-24 ------ # dnf --enablerepo=remi install httpd MariaDB-client MariaDB-server php php-common ------ On 18-21 ------ # yum --enablerepo=remi install httpd MariaDB-client MariaDB-server php php-common
For MySQL Installation on RHEL/CentOS 6
# yum --enablerepo=remi install httpd mysql mysql-server php php-common
Step 4: Installing PHP Modules
------ On RHEL/CentOS 7/6 and Fedora 18-21 ------ # yum --enablerepo=remi install php-mysqlnd php-pgsql php-pecl-mongo php-pdo php-pecl-memcache php-pecl-memcached php-gd php-xml php-mbstring php-mcrypt php-pecl-apcu php-cli php-pear ------ On Fedora 24-22 ------ # dnf --enablerepo=remi install php-mysqlnd php-pgsql php-pecl-mongo php-pdo php-pecl-memcache php-pecl-memcached php-gd php-xml php-mbstring php-mcrypt php-pecl-apcu php-cli php-pear
Step 5: Enable/Start Apache and MySQL/MariaDB
On SystemD – RHEL/CentOS 7 and Fedora 24-18
------ Enable Apache and MariaDB on Boot ------ # systemctl enable httpd # systemctl enable mariadb ------ Start Apache and MariaDB ------ # systemctl start httpd # systemctl start mariadb
On SysVinit- RHEL/CentOS 6
------ Enable Apache and MySQL on Boot ------ # chkconfig --levels 235 httpd on # chkconfig --levels 235 mysqld on ------ Start Apache and MySQL ------ # /etc/init.d/httpd start # /etc/init.d/mysqld start
Step 6: Verifying PHP 5.5 or 5.6
Let’s stick with the classic way of testing PHP. Create a file called
test.php under /var/www/html and add the following lines of code to it.
phpinfo() function shows a great deal of information about the current PHP installation:
<?php phpinfo(); ?>
Now point your web browser to
http://[server]/test.php and check the presence of the installed modules and additional software by scrolling down the page (replace
[server] with your domain or the IP address of your server). Your output should be similar to:
PHP 5 5 Version on CentOS 6.6
Congratulations! You now have a latest working installation of a LAMP stack. If something did not go as expected, feel free to contact us using the form below. Questions and suggestions are also welcome.
- July 29, 2016 @ 15:06:30 [Current Revision] by admin
- July 29, 2016 @ 15:06:30 by admin