Install Apache, MySQL 8 or MariaDB 10 and PHP 7 on CentOS 7
This how-to guide explains how to install the latest version of the Apache, MySQL 8 or MariaDB 10 and PHP 7 along with the required PHP modules on RHEL / CentOS 7/6 and Fedora 24-29.
This combination of the operating system (Linux) with the web server (Apache), database server (MariaDB/MySQL) and server-side scripting language (PHP) is known as the LAMP stack.
Don’t Miss: How to Install Nginx 1.15, MariaDB 10 and PHP 7 on CentOS 7
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 a 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 |
---|---|---|
7.3 | 5.4 | 5.3 |
To do this, we will enable the EPEL and Remi repository and use yum and dnf (the new package management tool available in Fedora).
Step 1: Installing EPEL and Remi Repository
EPEL (Extra Packages for Enterprise Linux) is a community based repository offers add-on software packages for RHEL-based Linux distributions.
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
On RHEL/CentOS 6
On Fedora 24-29
Step 2: Installing Apache Web Server
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.
To install Apache web server, first update the system software packages and install it using following commands.
Once Apache web server installed, you can start enable it to auto start at system boot.
If you are running firewalld, make sure to allow Apache traffic on the firewall.
Step 3: Installing PHP Using Remi Repository
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.
To install PHP, first you need to enable Remi repository by installing yum-utils
, a collection of useful programs for managing yum repositories and packages.
Once installed, you can use yum-config-manager provided by yum-utils
to enable Remi repository as the default repository for installing different PHP versions as shown.
For example, to install PHP 7.x version, use the following command.
Next, 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:
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 these following necessary PHP modules with the command below.
Step 4: Installing MySQL or MariaDB Database
In this section, we will show you installation of both databases MySQL and MariaDB, so its up-to you what to choose based on your requirements.
Installing MySQL 8 Database Server
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.
To install latest MySQL 8.0 version, we will install and enable official MySQL Yum software repository using the following commands.
After installing the MySQL Yum software repository for your Linux platform, now install the latest version of MySQL (currently 8.0) using the following command.
After successful installation of MySQL, it’s time to start the MySQL server with the following command.
Check out our article on how to secure MySQL 8 database installation.
Installing MariaDB 10 Database Server
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.
In latest RHEL/CentOS 7 distribution, MariaDB is a drop-in replacement for MySQL and in RHEL/CentOS 6 MySQL 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.
To enable the MariaDB repository on RHEL/CentOS 7 distributions, create a file named /etc/yum.repos.d/mariadb.repo
with the following contents:
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:
Step 5: Enable/Start Apache and MySQL/MariaDB
On SystemD
On SysVinit
Step 6: Verifying PHP Instalation
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.
The phpinfo()
function shows a great deal of information about the current PHP installation:
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:
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.
Note: you can also install MariaDB in other distributions by creating a custom repository following the instructions provided here.
Tidak ada komentar:
Posting Komentar