09-26-2017, 11:28 AM
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:
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]
Then we create the system startup links for MySQL (so that MySQL starts automatically whenever the system boots) and start the MySQL server:
Set passwords for the MySQL root account:
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:
Now configure your system to start Apache at boot time...
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 (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.
Install yum-utils as we need the yum-config-manager utility.
and run VPS packages 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:
4.1 Install PHP 7.0 (optional)
We can install PHP 7.0 and the Apache PHP 7.0 module as follows:
4.2 Install PHP 7.1 (optional)
If you want to use PHP 7.1 instead, use:
In this example and in the downloadable virtual machine, I'll use PHP 7.1.
We must restart Apache to apply the changes:
[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]
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:
Now restart Apache web server:
7 phpMyAdmin installation
phpMyAdmin is a web interface through which you can manage your MySQL databases.
phpMyAdmin can now be installed as follows:
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):
Next, we change the authentication in phpMyAdmin from [font=monospace]cookie to http:[/font]
Restart Apache:
Afterwards, you can access phpMyAdmin under [font=monospace]http://your_vps_ip_adderess/phpmyadmin/[/font]
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:
Code: (Select All)
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
yum -y install epel-release
yum -y install nanoTo 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]
Code: (Select All)
yum -y install mariadb-server mariadbThen we create the system startup links for MySQL (so that MySQL starts automatically whenever the system boots) and start the MySQL server:
Code: (Select All)
systemctl start mariadb.service
systemctl enable mariadb.serviceSet passwords for the MySQL root account:
Code: (Select All)
mysql_secure_installation3 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:
Code: (Select All)
yum -y install httpdNow configure your system to start Apache at boot time...
Code: (Select All)
systemctl start httpd.service
systemctl enable httpd.serviceTo 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.
Code: (Select All)
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reloadNow 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.
Code: (Select All)
rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpmInstall yum-utils as we need the yum-config-manager utility.
Code: (Select All)
yum -y install yum-utilsand run VPS packages update
Code: (Select All)
yum updateNow 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:
Code: (Select All)
yum -y install php4.1 Install PHP 7.0 (optional)
We can install PHP 7.0 and the Apache PHP 7.0 module as follows:
Code: (Select All)
yum-config-manager --enable remi-php70
yum -y install php php-opcache4.2 Install PHP 7.1 (optional)
If you want to use PHP 7.1 instead, use:
Code: (Select All)
yum-config-manager --enable remi-php71
yum -y install php php-opcacheIn this example and in the downloadable virtual machine, I'll use PHP 7.1.
We must restart Apache to apply the changes:
Code: (Select All)
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]
Code: (Select All)
yum search phpPick the ones you need and install them like this:
Code: (Select All)
yum -y install php-mysqlIn the next step I will install some common PHP modules that are required by CMS Systems like Wordpress, Joomla, and Drupal:
Code: (Select All)
yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-soap curl curl-develNow restart Apache web server:
Code: (Select All)
systemctl restart httpd.service7 phpMyAdmin installation
phpMyAdmin is a web interface through which you can manage your MySQL databases.
phpMyAdmin can now be installed as follows:
Code: (Select All)
yum -y install phpMyAdminNow 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):
Code: (Select All)
nano /etc/httpd/conf.d/phpMyAdmin.confCode: (Select All)
[...]
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]
Code: (Select All)
nano /etc/phpMyAdmin/config.inc.php
[...]
$cfg['Servers'][$i]['auth_type'] = 'http'; // Authentication method (config, http or cookie based)?
[...]Restart Apache:
Code: (Select All)
systemctl restart httpd.serviceAfterwards, you can access phpMyAdmin under [font=monospace]http://your_vps_ip_adderess/phpmyadmin/[/font]
