In this quick tutorial I will show you how to install an Apache web server on CentOS 7 server with PHP and MySQL support. LAMP stands for Linux Apache MySQL PHP. There are also Windows and Mac variations of this named WAMP and MAMP respectively.
To start, we will have to add the EPEL repo to install the latest phpMyAdmin:
[simterm]
rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY*
yum -y install epel-release
[/simterm]
In case you are on a fresh install of CentOS, we will need to install a tool to do some file editing. For the purposes of this tutorial we will use nano:
[simterm]
yum -y install nano
[/simterm]
Install MySQL
We are now ready to install MySQL / MariaDB. What’s MariaDB? MariaDB is a fork of MySQL by the original MySQL developer Monty Widenius. We will be using MariaDB which is fully compatible with MySQL
[simterm]
yum -y install mariadb-server mariadb
[/simterm]
Next we need to create system startup links for MySQL and also start the MySQL Server:
[simterm]
systemctl start mariadb.service
systemctl enable maraidb.service
[/simterm]
We will now perform the initial setup for MySQL
[simterm]
mysql_secure_installation
[/simterm]
Next, you will be presented with some options. You can accept the defaults for these, be sure to pick a password you will remember.
Install Apache
The apache installation is pretty straight forward.
[simterm]
yum -y install httpd
[/simterm]
After the installation completes, we will need to add Apache to start at boot time
[simterm]
systemctl start httpd.service
systemctl enable httpd.service
[/simterm]
Next we have to ensure that the firewall is not blocking incoming connections to port 80 and 443 http and https respectively.
[simterm]
firewall-cmd –permanent –zone=public –add-service=http
firewall-cmd –permanent –zone=public –add-service=https
firewall-cmd –reload
[/simterm]
You should now be able to direct your browser to the IP address of your server and you should see the following:
Install PHP
For the purposes of this tutorial we are going to install PHP 7.1, just be aware that there are other versions such as 5.4 or 7.0 to choose from.
Lets add the Remi CentOS repository
[simterm]
rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
[/simterm]
We will now install the yum-config-manager which is part of yum-utils
[simterm]
yum -y install yum-utils
[/simterm]
Now lets update ym
[simterm]
yum update
[/simterm]
Finally, we can install PHP:
[simterm]
yum-config-manager –enable remi-php71
yum -y install php php-opcache
[/simterm]
We now have to restart Apache
[simterm]
systemctl restart httpd.service
[/simterm]
Install MySQL Support in PHP
To use MySQL with PHP we have to install the php71w-mysql package. It’s also not a bad idea to install some other modules while we’re at it.
[simterm]
yum -y install php71w-mysql
[/simterm]
Next lets install some commonly used PHP modules that are required by CMS systems like WordPress and Joomla.
[simterm]
yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-soap curl curl-devel
[/simterm]
Now we need to restart Apache for the new modules to be activated.
[simterm]
systemctl restart httpd.service
[/simterm]
Install phpMyAdmin
phpMyAdmin is a web interface to manage databases and users for MySQL which makes management quick and simple.
[simterm]
yum -y install phpMyAdmin
[/simterm]
After the install completes, we have to do just a little bit of configuring.
[simterm]
nano /etc/httpd/conf.d/phpMyAdmin.conf
[/simterm]
You’ll need to comment out the RequireAny and Require IP statements as well as add the Require all granted line. The changes are highlighted in the text below:
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>
To save the file press Control – X and you will be asked to save, just press Y
We are going to change the authentication method from cookies to http
[simterm]
nano /etc/phpMyAdmin/config.inc.php
[/simterm]
$cfg['Servers'][$i]['auth_type'] = 'http'; // Authentication method (config, http or cookie based)?
To save the file press Control – X and you will be asked to save, just press Y
Finally, we need to restart Apache one last time
[simterm]
systemctl restart httpd.service
[/simterm]
You should now be able to access phpMyAdmin using your servers IP address http://192.168.1.10/phpMyAdmin/
To login, you would use the username root and the password you setup during the MySQL installation portion of the tutorial.
So that’s it, this tutorial was mostly just a reference for myself. I’m always setting these up and every time I do I end up searching google for a tutorial, well now I can just come here. If you guys have questions or comments, please feel free to leave those below.
Thanks for stopping by.
0 Comments for “How to install Apache, PHP 7.1 and MySQL on CentOS 7.3 (LAMP)”