arrow_upward

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to install Apache, PHP 7.1 and MySQL on CentOS 7.3
#1
This tutorial shows how you can install an Apache webserver on a CentOS 7 server with PHP support (mod_php) and MySQL support. LAMP is short for Linux, Apache, MySQL, PHP.

This updated tutorial shows the installation of the latest PHP versions (7.0 and 7.1) on CentOS 7.3.
[font=Tahoma, Helvetica, Arial, sans-serif]1 Preliminary Note[/font]

I will add the EPEL repo here to install latest phpMyAdmin as follows:

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
yum -y install epel-release
yum -y install nano

To edit files on the shell, I'll install the nano editor. If you prefer vi for file editing, then skip this step.

[font=Tahoma, Helvetica, Arial, sans-serif]2 Installing MySQL / MariaDB[/font]
[font=Tahoma, Helvetica, Arial, sans-serif][font=Tahoma, Helvetica, Arial, sans-serif]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:[/font][/font]

yum -y install mariadb-server mariadb

Then we create the system startup links for MySQL (so that MySQL starts automatically whenever the system boots) and start the MySQL server:

systemctl start mariadb.service
systemctl enable mariadb.service

Set passwords for the MySQL root account:

mysql_secure_installation

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:

yum -y install httpd

Now configure your system to start Apache at boot time...

systemctl start httpd.service
systemctl enable httpd.service

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.

firewall-cmd --permanent --zone=public --add-service=http 
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

Now direct your browser to the IP address of your server (http://your_vps_ip_address), and you should see the Apache placeholder page

[font=Tahoma, Helvetica, Arial, sans-serif]4 Installing PHP
[/font]

The PHP version that ships with CentOS is quite old (PHP 5.4), therefore I will show you in this step some options to install newer PHP versions like PHP 7.0 or 7.1 from Remi repository.

Add the Remi CentOS repository.

rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Install yum-utils as we need the yum-config-manager utility.


yum -y install yum-utils

and run VPS packages update


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 with the next command. To install PHP 7.0, follow the commands in chapter 4.1 and for PHP 7.1, use chapter 4.2 instead.

To install PHP 5.4, run this command:


yum -y install php

4.1 Install PHP 7.0 (optional)

We can install PHP 7.0 and the Apache PHP 7.0 module as follows:


yum-config-manager --enable remi-php70
yum -y install php php-opcache

4.2 Install PHP 7.1 (optional)

If you want to use PHP 7.1 instead, use:


yum-config-manager --enable remi-php71

yum -y install php php-opcache


In this example and in the downloadable virtual machine, I'll use PHP 7.1.

We must restart Apache to apply the changes:

 systemctl restart httpd.service

[font=Tahoma, Helvetica, Arial, sans-serif]6 Getting MySQL Support In PHP

[/font]

To get MySQL support in PHP, we can install the [font=monospace]php71w-mysql 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:[/font]


yum search php


Pick the ones you need and install them like this:


yum -y install php-mysql


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 restart Apache web server:

 
systemctl restart httpd.service

7 phpMyAdmin installation

phpMyAdmin is a web interface through which you can manage your MySQL databases.
phpMyAdmin can now be installed as follows:



yum -y install phpMyAdmin


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>

[...]


Next, we change the authentication in phpMyAdmin from [font=monospace]cookie to http:[/font]


nano /etc/phpMyAdmin/config.inc.php
[...]
$cfg['Servers'][$i]['auth_type']     = 'http';    // Authentication method (config, http or cookie based)?
[...]

Restart Apache:


systemctl restart  httpd.service

Afterwards, you can access phpMyAdmin under [font=monospace]http://your_vps_ip_adderess/phpmyadmin/[/font]
Thanks to @Post4VPS & @Hostdare for Providing their VPS Hosting Services: VPS 12
#2
I will use these tutorials when I get a VPS for sure, I was looking for something like this since its hard to find many stuffs in same tutorial, it will be awesome for newbies and beginners. Keep it up @Zorono.
 - Thanks to Post4VPS & Host4Fun for the amazing VPS 1 -
#3
if you want better performance i reccomend nginx instead of apache but nginx is harder to configure . but the performance isnt that far anyway if you just host a small website . but if you host a large website the performance is very significant if im not wrong nginx can perform 10x faster than apache2
Terminal
humanpuff69@FPAX:~$ Thanks To Shadow Hosting And Post4VPS for VPS 5


Possibly Related Threads…
Thread
Author
Replies
Views
Last Post
1,540
05-09-2021, 04:39 PM
Last Post: deanhills

person_pin_circle Users browsing this thread: 2 Guest(s)
Sponsors: VirMach - Host4Fun - CubeData - Evolution-Host - HostDare - Hyper Expert - Shadow Hosting - Bladenode - Hostlease - RackNerd - ReadyDedis - Limitless Hosting