Install Apache, PHP and MySQL On CentOS 7 (LAMP)
Install Apache, PHP and MySQL On CentOS 7 (LAMP)
Log in or Sign up
Tutorial search
This tutorial shows how This tutorial exists for these OS versions
you can install an
Apache2 webserver on a CentOS 7.6
CentOS 7.0 server with CentOS 7.4
PHP5 support (mod_php) CentOS 7.3
and MySQL support. CentOS 7
LAMP is short for Linux, CentOS 6.5
Apache, MySQL, PHP. CentOS 6.2
On this page
1 Preliminary Note
1 Preliminary 2 Installing MySQL / MariaDB
3 Installing Apache2
Note 4 Installing PHP5
5 Testing PHP5 / Getting Details About Your PHP5
In this tutorial, I use the Installation
hostname 6 Getting MySQL Support In PHP5
server1.example.com 7 phpMyAdmin installation
with the IP address 8 Links
192.168.0.100. These
settings might differ for
you, so you have to replace them where appropriate.
https://www.howtoforge.com/apache_php_mysql_on_centos_7_lamp 1/24
2/1/2021 Install Apache, PHP And MySQL On CentOS 7 (LAMP)
I will add the EPEL repo here to install latest phpMyAdmin as follows:
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. To
install MySQL, we do install MariaDB like this:
Then we create the system startup links for MySQL (so that MySQL starts
automatically whenever the system boots) and start the MySQL server:
mysql_secure_installation
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.
Reloading the privilege tables will ensure that all changes made so
far
will take effect immediately.
https://www.howtoforge.com/apache_php_mysql_on_centos_7_lamp 3/24
2/1/2021 Install Apache, PHP And MySQL On CentOS 7 (LAMP)
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
3 Installing Apache2
CentOS 7 ships with apache 2.4. Apache2 is directly available as a CentOS 7.0
package, therefore we can install it like this:
By default apache will be installed, if-not then please install it as shown above
In CentOS 7.0 uses Firewall-cmd, so I will customize it to allow external access to port
80 (http) and 443 (https).
https://www.howtoforge.com/apache_php_mysql_on_centos_7_lamp 4/24
2/1/2021 Install Apache, PHP And MySQL On CentOS 7 (LAMP)
Now direct your browser to http://192.168.0.100, and you should see the Apache2
placeholder page:
4 Installing PHP5
https://www.howtoforge.com/apache_php_mysql_on_centos_7_lamp 5/24
2/1/2021 Install Apache, PHP And MySQL On CentOS 7 (LAMP)
The document root of the default website is /var/www/html. We will now create a
small PHP file (info.php) in that directory and call it in a browser. The file will display
lots of useful details about our PHP installation, such as the installed PHP version.
vi /var/www/html/info.php
<?php
phpinfo();
?>
As you see, PHP5 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 PHP5. MySQL is not listed there which means we don't
have MySQL support in PHP5 yet.
To get MySQL support in PHP, we can install the php-mysql package. It's a good idea
to install some other PHP5 modules as well as you might need them for your
applications. You can search for available PHP5 modules like this:
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:
https://www.howtoforge.com/apache_php_mysql_on_centos_7_lamp 7/24
2/1/2021 Install Apache, PHP And MySQL On CentOS 7 (LAMP)
7 phpMyAdmin installation
phpMyAdmin is a web interface through which you can manage your MySQL
databases.
phpMyAdmin can now be installed as follows:
vi /etc/httpd/conf.d/phpMyAdmin.conf
[...]
Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin
#<Directory /usr/share/phpMyAdmin/>
# <IfModule mod_authz_core.c>
# # Apache 2.4
# <RequireAny>
# Require ip 127.0.0.1
# Require ip ::1
https://www.howtoforge.com/apache_php_mysql_on_centos_7_lamp 8/24
2/1/2021 Install Apache, PHP And MySQL On CentOS 7 (LAMP)
# </RequireAny>
# </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>
[...]
vi /etc/phpMyAdmin/config.inc.php
[...]
$cfg['Servers'][$i]['auth_type'] = 'http'; // Authentication met
hod (config, http or cookie based)?
[...]
Restart Apache:
https://www.howtoforge.com/apache_php_mysql_on_centos_7_lamp 9/24
2/1/2021 Install Apache, PHP And MySQL On CentOS 7 (LAMP)
8 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/
Suggested articles
https://www.howtoforge.com/apache_php_mysql_on_centos_7_lamp 10/24
2/1/2021 Install Apache, PHP And MySQL On CentOS 7 (LAMP)
63 Comment(s)
Add comment
Name * Email *
Submit comment
Comments
By: Reply
Thnak you for pointing out the broken link targets, it is fixed now. 8 is the number of the chapter
here, not the number of the links.
Hello, just wanted to let you know that you actually installed an old phpMyAdmin package. There are
two PMA packages, "phpmyadmin" which installs v2.11.11 and "phpMyAdmin" which installs v3.5.7. I
don't know if you wanted to use the old version intentionally, but I just thought that I'd point it out.
By: Reply
By: Reply
Why mariaDB and not mysql, or are they the same now ?
https://www.howtoforge.com/apache_php_mysql_on_centos_7_lamp 11/24
2/1/2021 Install Apache, PHP And MySQL On CentOS 7 (LAMP)
MariaDB is the free MySQL fork, MariaDB is compatible with MySQL and the commands from
MariaDB are still nemad "mysql" or "mysqldump", so there are no differences from the Client
side. All Major Linux Distributions replaced MySQL with MariaDB now, so we will use that for the
tutorials as well. Some users also Report that MariDB is faster then MySQL in the latest releases.
Thanks for the one stop instructions. Everything worked as expected. Very common setup for CMS
systems.
-nick
Step one, installing EPEL can be done by simply installing it with yum, since it is included in the
default repository;
yum install epel-release
https://www.howtoforge.com/apache_php_mysql_on_centos_7_lamp 12/24
2/1/2021 Install Apache, PHP And MySQL On CentOS 7 (LAMP)
phpMyAdmin is not available in CentOS 7's default repository. before installing phpMyAdmin,
run sudo yum install epel-release
See step one of the tutorial. It explains the installation of the epel repo.
I want to thank you very much for this very helpful tutorial, appreciate it, please don't stop writing
as you've a very good skills in explaining things :)
thanks man!!!
you don't know how much your tutorial helped me.
all the best dearest man :)
thanks man. You don't know how much your tutorial helped me.
All the best dearest man :)
https://www.howtoforge.com/apache_php_mysql_on_centos_7_lamp 13/24
2/1/2021 Install Apache, PHP And MySQL On CentOS 7 (LAMP)
great tutorial,
Thanks!!
I was able to get this all installed and working. Only problem I am having is I cannot login to
phpmyadmin from my laptop to my headless CentOS server. It will not take my login credentials on
root, my regular user account, or leaving it blank. I can login to both the root and my user account
via my ssh connection to the server with no problem. But the same accounts will not work via the
web page. I get the prompt, but it just keeps reprompting me. Any ideas on what to check?
Use your MySQL/MariaDB password. You are not using your Linux login to access the database,
which you're trying to do with phpmyadmin
Hi,
I'm getting below things while I'm trying to access phpmyadmin in GUI mode.
Forbidden
You don't have permission to access /phpMyAdmin on this server.
I'm having the same issue like you. Did you fix it?
Great tutorial and very well-explained. Works perfectly if you follow all the steps. I did notice the link
for epel in step 1 is old. I used the latest one, 7.5, which is referenced elsewhere in these
comments. Also, when I commented out the section of code in phpMyAdmin, I could not log into it
from localhost, so I un-commented them since I likely would not be logging into phpMyAdmin from a
different machine anyway. Otherwise, Great stuff! Thanks a million!
</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>
I could net get access to my new site after extracting it to the html folder until I disabled selinux.
CentOS changes the package names / URL's quite often. I updated the URL to the new name
now.
Nice tutorial :)
Very useful tutorial. Keep the good work and thank you for sharing. Gracias
Thank you for great article for noobs like myself. I have running into a problem after I edited the
phpmyadmin.conf file with commenting out the line you said. Now when I run #systemctl restart
httpd.service, I get this error: "job for httpd.service failed because the control process exited with
error code. see "systemctl status httpd.service" and "journalctl -xe" for details."
What did I get wrong?
This is conf edited:
https://www.howtoforge.com/apache_php_mysql_on_centos_7_lamp 15/24
2/1/2021 Install Apache, PHP And MySQL On CentOS 7 (LAMP)
Great tutorial. I do have one request, can you add some information about getting SELinux to play
nice with Apache? I'm new to setting up Linux servers and this is the first time I have worked with
CentOS, so I wasn't aware of what kinds of problems can be caused by SELinux, or how easy it is to
fix them. Lets just say it would have saved me some time, and a lot of frustrations if I had known
about the restorecon command before trying to install a CMS.
Muito obrigado por dedicar um tempo a ajudar outras pessoas... Foi o único tutorial que funcionou.
Parabens !!!
at June 2016, epel version release is 7.7you can checked version in url in this
belowhttp://dl.fedoraproject.org/pub/epel/7/x86_64/e/
I can't seem to get the phpinfo to display in the browser. I typed myip/info.php (obviously my ip
address instead of myip) and also tried localhost/info.php however it just brings me to a still white
screen. Not sure if I have to enable something?
Maybe you didn't close it properly. tail -f /var/log/httpd/error_logs will give you exactly whats wrong
usually.
https://www.howtoforge.com/apache_php_mysql_on_centos_7_lamp 16/24
2/1/2021 Install Apache, PHP And MySQL On CentOS 7 (LAMP)
Hey!! good tutorial. one thing which i want to point out is that CentOs 7 has bugs with php5. Php 7
works better. I followed all the steps except that I installed php 7. In the editor/console, I checked
and LAMP is installed. Even my welcome page after installing apache was working. But after i
created info.php, in the web server I am having three problems:
1. http://localhost/ gives me a blank page.
2. http://my-ip-address/info.php/ the requested url was not found in this server/
3. http://my-ip-address/phpmyadmin the requested url was not found in this server
Thanks A Lot :)
Then you might have missed a step. Re-Check that you run all installation commands and then
check the httpd error.log to see if there are any errors on your server.
https://www.howtoforge.com/apache_php_mysql_on_centos_7_lamp 17/24
2/1/2021 Install Apache, PHP And MySQL On CentOS 7 (LAMP)
https://www.howtoforge.com/apache_php_mysql_on_centos_7_lamp 18/24
2/1/2021 Install Apache, PHP And MySQL On CentOS 7 (LAMP)
</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>
to:
<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>
</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>
<IfModule mod_authz_core.c>
# Apache 2.4
<RequireAny>
Require ip [ WINDOWS IP TO ALLOW GOES HERE ]
Require ip ::1
</RequireAny>
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from [ WINDOWS IP TO ALLOW GOES HERE ]
Allow from ::1
</IfModule>
</Directory>
service httpd restart
change $cfg['Servers'][$i]['auth_type'] = 'cookie'; to $cfg['Servers'][$i]['auth_type'] = 'http';
service httpd restart
https://www.howtoforge.com/apache_php_mysql_on_centos_7_lamp 19/24
2/1/2021 Install Apache, PHP And MySQL On CentOS 7 (LAMP)
/etc/selinux/config change
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
to
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
reboot centos
IN WINDOWS POINT BROWSER TO: http://192.168.170.128/phpmyadmin, should be all good
copy website to: /var/www/html/[ WEBSITE NAME ]
chmod -R 777 html
If you are going to show people how to disable all security, as you do by by commenting out the
entire block, you should warn them that this makes it so any IP is accepted--so if they place this
configuration on a web facing network, anyone will be able to get to phpmyadmin from any IP
https://www.howtoforge.com/apache_php_mysql_on_centos_7_lamp 20/24
2/1/2021 Install Apache, PHP And MySQL On CentOS 7 (LAMP)
address. They should be asked if that is what they intend. However, it is far better to simply show
them the correct way, that is by putting in either their internal subnet only, if they only manage from
a private IP space (so that would be done in CIDR format as in 192.168.1.0/24 or 10.0.0.0/24 and
so on. If they want to be able to get to and manage from the Internet (which should only be done if
you don't have any other way to get to it) they should find out what their external IP is from where
they will be managing and put that IP address in i.e. 67.67.77.156 but certainly you don't want any
of the millions of IP address from all over the planet to be able to bang away at the php
administration logon, do you?
For those that say this is just for testing or developing...I've lost count of how many times a dev or
test system somehow got placed in production with security either very relaxed or non-existent and
then next thing you know, the site is hacked.
And for those requesting that SELinux be disabled. Do yourselves a favor, learn how to work with it.
Don't just disable it or put it in permissive mode. It is one of many things that is between you and
hackers. Why purposely, for the lack of spending time with a book or documentation, weaken the
security of a system on the Internet?
If a person can't deploy and configure a LAMP stack without disabling security then maybe they
shouldn't be trying to deploy and configure a LAMP stack.
Do it right or don't do it at all.
Same here
any idea?
great tutorial,
https://www.howtoforge.com/apache_php_mysql_on_centos_7_lamp 21/24
2/1/2021 Install Apache, PHP And MySQL On CentOS 7 (LAMP)
Thanks a lot
Just starting with VPS and this tutorial is a lifesaver. I have save it to my bookmarks. Please always
keep it up to date if it is not too much to ask. Amazing contribution to the community this is!
No mod_ssl & Full database access using plain text http (through phpmyadmin). Your work is usually
so detailed, what happened here?
Sign up now!
Tutorial Info
Author: howtoforge
Tags:
apache, centos, linux, mysql, php, server, web
server
https://www.howtoforge.com/apache_php_mysql_on_centos_7_lamp 22/24
2/1/2021 Install Apache, PHP And MySQL On CentOS 7 (LAMP)
Download: centOS7.0_perfect_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
https://www.howtoforge.com/apache_php_mysql_on_centos_7_lamp 23/24
2/1/2021 Install Apache, PHP And MySQL On CentOS 7 (LAMP)
https://www.howtoforge.com/apache_php_mysql_on_centos_7_lamp 24/24