How To Install Apache, PHP 7.1 and MySQL On CentOS 7.4 (LAMP) Best
How To Install Apache, PHP 7.1 and MySQL On CentOS 7.4 (LAMP) Best
4 (LAMP)
Log in or Sign up
Search...
Tutorial search
Home How to install Apache, PHP 7.2 and MySQL on CentOS 7.4 (LAMP)
Ad Scan your Web-Server for Malware with ISPProtect now. Get Free Trial.
How to install Apache, PHP 7.2 and MySQL on CentOS 7.4 (LAMP)
This tutorial shows how to install an Apache web server on This tutorial exists for these OS versions
CentOS 7 server with PHP (mod_php) and MySQL database.
The acronym LAMP is short for Linux, Apache, MySQL, PHP. CentOS 7.4
CentOS 7.3
CentOS 7
This updated tutorial shows the installation of the latest PHP CentOS 6.5
versions (7.0, 7.1 and 7.2) on CentOS 7.4. CentOS 6.2
CentOS 6.1
1 Preliminary Note
In this tutorial, I use the hostname server1.example.com with 2 Installing MySQL / MariaDB
the IP p 192.168.1.100. These settings might differ for you, 3 Installing Apache
4 Installing PHP
https://www.howtoforge.com/tutorial/centos-lamp-server-apache-mysql-php/ 1/21
12.09.2018 How to install Apache, PHP 7.1 and MySQL on CentOS 7.4 (LAMP)
so you have to replace them where appropriate. 4.1 Install PHP 5.4
4.2 Install PHP 7.0
4.3 Install PHP 7.1
I will add the EPEL repo here to install latest phpMyAdmin as 4.4 Install PHP 7.2
follows: 5 Testing PHP / Getting Details About Your PHP
Installation
6 Getting MySQL Support In PHP
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
yum -y install epel-release 7 phpMyAdmin installation
8 Download as virtual machine
9 Links
To edit files on the shell, I'll install the nano editor. If you prefer
vi for file editing, then skip this step.
MariaDB is a MySQL fork of the original MySQL developer Monty Widenius. MariaDB is compatible with MySQL and I've
chosen to use MariaDB here instead of MySQL. Run this command to install MariaDB with yum:
Then we create the system startup links for MySQL (so that MySQL starts automatically whenever the system boots) and
start the MySQL server:
https://www.howtoforge.com/tutorial/centos-lamp-server-apache-mysql-php/ 2/21
12.09.2018 How to install Apache, PHP 7.1 and MySQL on CentOS 7.4 (LAMP)
mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
https://www.howtoforge.com/tutorial/centos-lamp-server-apache-mysql-php/ 3/21
12.09.2018 How to install Apache, PHP 7.1 and MySQL on CentOS 7.4 (LAMP)
production environment.
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
https://www.howtoforge.com/tutorial/centos-lamp-server-apache-mysql-php/ 4/21
12.09.2018 How to install Apache, PHP 7.1 and MySQL on CentOS 7.4 (LAMP)
3 Installing Apache
CentOS 7 ships with Apache 2.4. Apache is directly available as a CentOS 7 package, therefore we can install it like this:
https://www.howtoforge.com/tutorial/centos-lamp-server-apache-mysql-php/ 5/21
12.09.2018 How to install Apache, PHP 7.1 and MySQL on CentOS 7.4 (LAMP)
To be able to access the web server from outside, we have to open the HTTP (80) and HTTPS (443) ports in the firewall. The
default firewall on CentOS is firewalld which can be configured with the firewalld-cmd command.
Now direct your browser to the IP address of your server, in my case http://192.168.1.100, and you should see the
Apache placeholder page:
4 Installing PHP
https://www.howtoforge.com/tutorial/centos-lamp-server-apache-mysql-php/ 6/21
12.09.2018 How to install Apache, PHP 7.1 and MySQL on CentOS 7.4 (LAMP)
The PHP version that ships with CentOS as default is quite old (PHP 5.4). Therefore I will show you in this chapter some
options to install newer PHP versions like PHP 7.0 or 7.1 from Remi repository.
yum update
Now you have to chose which PHP version you want to use on the server. If you like to use PHP 5.4, then proceed to chapter
4.1. To install PHP 7.0, follow the commands in chapter 4.2, for PHP 7.1 chapter 4.3 and for PHP 7.1, use chapter 4.4
instead. Follow just one of the 4.x chapters and not all of them as you can only use one PHP version at a time with Apache
mod_php.
https://www.howtoforge.com/tutorial/centos-lamp-server-apache-mysql-php/ 7/21
12.09.2018 How to install Apache, PHP 7.1 and MySQL on CentOS 7.4 (LAMP)
We can install PHP 7.0 and the Apache PHP 7.0 module as follows:
https://www.howtoforge.com/tutorial/centos-lamp-server-apache-mysql-php/ 8/21
12.09.2018 How to install Apache, PHP 7.1 and MySQL on CentOS 7.4 (LAMP)
In this example and in the downloadable virtual machine, I'll use PHP 7.2.
The document root of the default website is /var/www/html. We will create a small PHP file (info.php) in that directory and
call it in a browser to test the PHP installation. The file will display lots of useful details about our PHP installation, such as
the installed PHP version.
nano /var/www/html/info.php
<?php
phpinfo();
https://www.howtoforge.com/tutorial/centos-lamp-server-apache-mysql-php/ 9/21
12.09.2018 How to install Apache, PHP 7.1 and MySQL on CentOS 7.4 (LAMP)
As you see, PHP 7.2 is working, and it's working through the Apache 2.0 Handler, as shown in the Server API line. If
you scroll further down, you will see all modules that are already enabled in PHP. MySQL is not listed there which means we
don't have MySQL support in PHP yet.
To get MySQL support in PHP, we can install the php-mysqlnd package. It's a good idea to install some other PHP modules
as well as you might need them for your applications. You can search for available PHP5 modules like this:
https://www.howtoforge.com/tutorial/centos-lamp-server-apache-mysql-php/ 10/21
12.09.2018 How to install Apache, PHP 7.1 and MySQL on CentOS 7.4 (LAMP)
Pick the ones you need and install them like this:
In the next step I will install some common PHP modules that are required by CMS Systems like Wordpress, Joomla, and
Drupal:
yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-soap
curl curl-devel
Now reload http://192.168.1.100/info.php in your browser and scroll down to the modules section again. You should
now find lots of new modules like curl etc there.:
https://www.howtoforge.com/tutorial/centos-lamp-server-apache-mysql-php/ 11/21
12.09.2018 How to install Apache, PHP 7.1 and MySQL on CentOS 7.4 (LAMP)
If you don't need the php info output anymore, then delete that file for security reasons.
rm /var/www/html/info.php
7 phpMyAdmin installation
phpMyAdmin is a web interface through which you can manage your MySQL databases.
phpMyAdmin can now be installed as follows:
https://www.howtoforge.com/tutorial/centos-lamp-server-apache-mysql-php/ 12/21
12.09.2018 How to install Apache, PHP 7.1 and MySQL on CentOS 7.4 (LAMP)
Now we configure phpMyAdmin. We change the Apache configuration so that phpMyAdmin allows connections not just from
localhost (by commenting out the <RequireAny> stanza and adding the 'Require all granted' line):
nano /etc/httpd/conf.d/phpMyAdmin.conf
[...]
Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin
<Directory /usr/share/phpMyAdmin/>
AddDefaultCharset UTF-8
<IfModule mod_authz_core.c>
# Apache 2.4
# <RequireAny>
# Require ip 127.0.0.1
# Require ip ::1
# </RequireAny>
Require all granted
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
</IfModule>
</Directory>
<Directory /usr/share/phpMyAdmin/>
Options none
AllowOverride Limit
Require all granted
</Directory>
https://www.howtoforge.com/tutorial/centos-lamp-server-apache-mysql-php/ 13/21
12.09.2018 How to install Apache, PHP 7.1 and MySQL on CentOS 7.4 (LAMP)
[...]
nano /etc/phpMyAdmin/config.inc.php
[...]
$cfg['Servers'][$i]['auth_type'] = 'http'; // Authentication method (config, http or cookie bas
ed)?
[...]
Restart Apache:
https://www.howtoforge.com/tutorial/centos-lamp-server-apache-mysql-php/ 14/21
12.09.2018 How to install Apache, PHP 7.1 and MySQL on CentOS 7.4 (LAMP)
This setup is available as virtual machine download in ova/ovf format (compatible with VMWare and Virtualbox) for
howtoforge subscribers.
https://www.howtoforge.com/tutorial/centos-lamp-server-apache-mysql-php/ 15/21
12.09.2018 How to install Apache, PHP 7.1 and MySQL on CentOS 7.4 (LAMP)
9 Links
Apache: http://httpd.apache.org/
PHP: http://www.php.net/
MySQL: http://www.mysql.com/
CentOS: http://www.centos.org/
phpMyAdmin: http://www.phpmyadmin.net/
Over 20 years experience as Software Developer and Linux System Administrator. Till Brehm is the founder
and lead developer of the ISPConfig Hosting Control Panel software (since 2000) and he founded
HowtoForge in 2005 as a place to share Linux knowledge with other Linux enthusiasts.
Suggested articles
https://www.howtoforge.com/tutorial/centos-lamp-server-apache-mysql-php/ 16/21
12.09.2018 How to install Apache, PHP 7.1 and MySQL on CentOS 7.4 (LAMP)
14 Comment(s)
Add comment
Name * Email *
p
Submit comment
I'm not a robot
reCAPTCHA
Privacy - Terms
Comments
https://www.howtoforge.com/tutorial/centos-lamp-server-apache-mysql-php/ 17/21
12.09.2018 How to install Apache, PHP 7.1 and MySQL on CentOS 7.4 (LAMP)
Hi,
Can you please tell how can we install specific version of MySQL. I need to install MySQL 5.6.23 on CentOS Linux 7.4.1708.
Thanks
Why are you changing phpmyadmin from cookie authentication to http authentication?
Hmmm... Unless I missed it somehow, it seems you're short of the instructions on how to configure httpd to load and make use of libphpX.so...
Cheers,
R.
There is nothing missing, just follow the tutorial and you will see that it works.
Thanks so much
After the installation I tried to upgrade plugins from wordpress admin, getting permission denied. The permission and ownership is of all files
and folders are correct. (I am not suing FTP or vSFTP)
How to fix this?
qué va gracias
Home How to install Apache, PHP 7.2 and MySQL on CentOS 7.4 (LAMP)
Sign up now!
https://www.howtoforge.com/tutorial/centos-lamp-server-apache-mysql-php/ 19/21
12.09.2018 How to install Apache, PHP 7.1 and MySQL on CentOS 7.4 (LAMP)
Tutorial Info
Download: CentOS-7.4-LAMP-Server.ova
Guide: VMWare Image Import Guide.
Other Downloads: List of all VMWare Images
40.2k Followers
Popular Tutorials
Xenforo skin by Xenfocus Contribute Contact Help Imprint and Legal Notice Top
https://www.howtoforge.com/tutorial/centos-lamp-server-apache-mysql-php/ 21/21