0% found this document useful (0 votes)
69 views

Debian 9 Lamp Server Tutorial With Apache, PHP 7 and Mariadb

Servidor

Uploaded by

Deyna Tamay
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views

Debian 9 Lamp Server Tutorial With Apache, PHP 7 and Mariadb

Servidor

Uploaded by

Deyna Tamay
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

30/7/2019 Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB

Log in or Sign up

Search...

Tutorials Tags Forums Linux Commands Subscribe ISPConfig News

 Tutorial search

Home Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB

Ad Scan your Web-Server for Malware with ISPProtect now. Get Free Trial.

Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB

LAMP is short for Linux, Apache, MySQL, PHP. This tutorial This tutorial exists for these OS versions
shows how you can install an Apache web server on a
Debian Stretch (9) server with PHP 7 (mod_php) and Debian 9 (Stretch)
MariaDB support. MariaDB is a fork of the well known MySQL Debian 8 (Jessie)
database server, it provides a MySQL compatible feature set and Debian 7 (Wheezy)
is a bit faster according to benchmarks that I found on the Debian 5 (Lenny)
internet. MariaDB will work with all applications that require Debian 6 (Squeeze)
MySQL like Wordpress, Joomla etc.
On this page

A LAMP setup is a perfect basis for CMS systems like Joomla, 1 Preliminary Note
Wordpress or Drupal. 2 Installing MariaDB as MySQL replacement
3 Installing Apache web server
4 Installing PHP 7.1

https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-lamp-on-debian-stretch/ 1/22
30/7/2019 Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB

5 Testing PHP / Getting details about your PHP


installation
1 Preliminary Note 6 Getting MySQL and MariaDB Support in PHP
7 PHP Cache to improve the PHP speed
In this tutorial, I use the hostname server1.example.com 8 phpMyAdmin
with the IP address 192.168.1.100. These settings might 9 Enable MySQL root Login for phpMyAdmin
differ for you, so you have to replace them where appropriate. 10 Links

2 Installing MariaDB as MySQL replacement

First, we install MariaDB like this:

apt-get -y install mariadb-server mariadb-client

Next, we will secure MariaDB with the mysql_secure_installation


command. Run the below command and follow the wizard.

mysql_secure_installation

The recommended input is shown in red.

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
https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-lamp-on-debian-stretch/ 2/22
30/7/2019 Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): <-- Hit return
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] <-- y


New password: <-- Enter the new password for the MariaDB root user
Re-enter new password: <-- Enter the password again
Password updated successfully!
Reloading privilege tables..
... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone


to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] <-- y


... Success!

Normally, root should only be allowed to connect from 'localhost'. This


ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] <-- y


... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-lamp-on-debian-stretch/ 3/22
30/7/2019 Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB
before moving into a production environment.

Remove test database and access to it? [Y/n] <-- y


- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] <-- y


... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

The MariaDB setup is secured now.

3 Installing Apache web server

Apache is available as a Debian package, therefore we can install it like this:

apt-get -y install apache2

https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-lamp-on-debian-stretch/ 4/22
30/7/2019 Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB

Now direct your browser to http://192.168.1.100, and you should see the Apache2 placeholder page (It works!):

Apache's default document root is /var/www on Debian, and the configuration file is /etc/apache2/apache2.conf.
Additional configurations are stored in subdirectories of the /etc/apache2 directory such as /etc/apache2/mods-
enabled (for Apache modules), /etc/apache2/sites-enabled (for virtual hosts), and /etc/apache2/conf-
enabled.

4 Installing PHP 7.1

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

https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-lamp-on-debian-stretch/ 5/22
30/7/2019 Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB

apt-get -y install php7.0 libapache2-mod-php7.0

We must restart Apache afterward:

service apache2 restart

5 Testing PHP / Getting details about your PHP installation

The document root of the default web site 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.

nano /var/www/html/info.php

<?php
phpinfo();

Now we call that file in a browser (e.g. http://192.168.1.100/info.php):

https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-lamp-on-debian-stretch/ 6/22
30/7/2019 Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB

As you see, PHP 7.0 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 / MariaDB is not listed there
which means we don't have MySQL support in PHP5 yet.

6 Getting MySQL and MariaDB Support in PHP

To get MySQL support in PHP, we will install the php7.0-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 PHP 7 modules like this:

apt-cache search php7.0

https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-lamp-on-debian-stretch/ 7/22
30/7/2019 Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB

Pick the ones you need and install them like this:

apt-get -y install php7.0-mysql php7.0-curl php7.0-gd php7.0-intl php-pear php-imagick php7.0-imap


php7.0-mcrypt php-memcache php7.0-pspell php7.0-recode php7.0-sqlite3 php7.0-tidy php7.0-xmlrpc ph
p7.0-xsl

Now restart Apache:

service apache2 restart

7 PHP Cache to improve the PHP speed

To speed up PHP, an Opcache should be installed. Check if the PHP Opcache module has been installed and enabled
correctly.Run this command:

php --version

The output shall contain the line I marked in red.

PHP 7.0.27-0+deb9u1 (cli) (built: Jan 5 2018 13:51:52) ( NTS )


Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.27-0+deb9u1, Copyright (c) 1999-2017, by Zend Technologies

If you do not see the Opcache module in the result, install it with this command:

https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-lamp-on-debian-stretch/ 8/22
30/7/2019 Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB

apt-get -y install php7.0-opcache

There is one more cache which might be useful, it's name is APCu. APCu is a free PHP opcode cacher for caching and
optimizing PHP intermediate code.

APCu can be installed as follows:

apt-get -y install php-apcu

Now restart Apache:

service apache2 restart

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 there, including the MySQL module which is used as MariaDB driver:

https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-lamp-on-debian-stretch/ 9/22
30/7/2019 Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB

8 phpMyAdmin

phpMyAdmin is a web interface through which you can manage your MySQL and MariaDB databases. It's a good idea to
install it:

apt-get -y install phpmyadmin

You will see the following questions:

https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-lamp-on-debian-stretch/ 10/22
30/7/2019 Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB

Web server to reconfigure automatically: <-- apache2

Configure database for phpmyadmin with dbconfig-common?<-- Yes

MySQL application password for phpmyadmin: <-- Press enter, apt will create a random password automatically.

https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-lamp-on-debian-stretch/ 11/22
30/7/2019 Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB

Afterwards, you can access phpMyAdmin under http://192.168.1.100/phpmyadmin/:

9 Enable MySQL root Login for phpMyAdmin

While you can log in as root user into MariaDB on the shell, the root login will not work in phpMyAdmin. To allow the root
user to use phpMyAdmin as well, run the following command on the shell:

echo "UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'root' AND plugin = 'uni
x_socket';FLUSH PRIVILEGES;" | mysql -u root -p

https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-lamp-on-debian-stretch/ 12/22
30/7/2019 Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB

10 Links
Apache: http://httpd.apache.org/
PHP: http://www.php.net/
MySQL: http://www.mysql.com/
Debian: http://www.debian.org/
phpMyAdmin: http://www.phpmyadmin.net/

About Till Brehm

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.

view as pdf | print

Share this page:

Suggested articles

https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-lamp-on-debian-stretch/ 13/22
30/7/2019 Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB

Interactive diagrams How to install PHP 7.x as Automate AD Password Ubuntu 18.04 (LTS) LAMP
PHP-FPM & FastCGI for Resets server tutorial with
ISPConfig 3.1 with apt... Apache, PHP 7.2, and...
Ad GoJS howtoforge.com Ad ADSelfService Plus howtoforge.com

Hosting especializado How to install Apache, Installing Apache2 With Apache2-SSL-PHP5-


Drupal - Con Soporte en PHP 7.3 and MySQL on PHP5 And MySQL Howto (+ Zend Optimizer
Español 24/7 CentOS 7.6 (LAMP) Support On OpenSUSE... And IonCube Loader)
Ad seedem.co howtoforge.com howtoforge.com howtoforge.com

18 Comment(s)
Add comment
Name * Email *

https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-lamp-on-debian-stretch/ 14/22
30/7/2019 Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB

    

p

Submit comment
I'm not a robot
reCAPTCHA
Privacy - Terms

Comments

By: ejjus at: 2018-05-10 22:01:02 Reply

Step 8 doesn't work without :


A cleaner way is to create the new configuration file:
/etc/apache2/conf-available/phpmyadmin.conf
and write the following in it:
Include /etc/phpmyadmin/apache.conf
then, soft link the file to the directory /etc/apache2/conf-enabled:
sudo ln -s /etc/apache2/conf-available/phpmyadmin.conf /etc/apache2/conf-enabled

By: till at: 2018-05-11 05:40:12 Reply

What you described is necessary just in case you missed selecting "Apache2" in the first apt dialog from Stp 8 shown in this tutorial. The better
and easier way is to just follow the tutorial and select 'Apache2' when apt ask you which web server shall be configured.

By: ejjus at: 2018-05-11 19:06:02 Reply

https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-lamp-on-debian-stretch/ 15/22
30/7/2019 Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB

I actually came back to add that I might have wrongfuly selected or typed something. It definetally is a misstep on my part, because I
struggled with some server internal things for 5 or 6 hours prior to setting up LAMP. I should have worded my first comment differentely,
more like in the format of "In my case..."
Have a nice day.

By: ejjus at: 2018-05-10 22:02:32 Reply

I didn't try the echo on the last step. This did the same:

Maybe a bit late, but I found this answer looking over the internet. It could help others with the same problem.
$sudo mysql -u root
[mysql] use mysql;
[mysql] update user set plugin='' where User='root';
[mysql] flush privileges;
[mysql] \q
Now you should be able to log in as root in phpmyadmin.
Nice tutorial. Helped me a lot. Cheers.

By: Michael Guldhammer at: 2019-03-06 18:04:47 Reply

Run theese 2 commands again, it works for me.


systemctl start mariadb mysql_secure_installation

By: Hopy at: 2018-06-01 13:26:43 Reply

in file info.php
You forget ?>

By: till at: 2018-06-01 13:28:38 Reply

I don't forgot it, the closing ?> is not required anymore in current PHP versions. Try it out, you will see it works without it :)

By: Vassilis at: 2018-06-28 09:45:15 Reply

https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-lamp-on-debian-stretch/ 16/22
30/7/2019 Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB

Thank you for your sharing and your secure setup. I have just installed this for a new website development on a debian9 LXC container through
proxmox, everything works perfect. thank you again

By: jim at: 2018-07-27 18:31:26 Reply

While I do appreciate Till's site and sharing... I'm not sure this should be considered a "secure setup."
AppArmor/SELinux is disabled, access to MariaDB beyond localhost, root access to phpMyAdmin/SSH, no key pair access, etc.

Active Directory self-service password


management solution.
Ad Self-service password management for Active
Directory users' domain and cloud accounts.
ADSelfService Plus

Learn more

A series of articles entitled "Secured Perfect Servers" might be interesting.

By: Patrice at: 2018-09-13 12:04:14 Reply

Works like a charm !

Many thanks :)
Pat

By: Baptiste at: 2018-10-13 15:11:29 Reply

Hello
( Sorry i'm french )

I have been follow your tutorial but on the step 8 at the end Phpmyadmin not work
https://i.imgur.com/XbeTOte.pngI don't know why .... can you help me pls

https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-lamp-on-debian-stretch/ 17/22
30/7/2019 Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB

Thanks ^^

By: Abdurakhman at: 2018-11-22 05:45:02 Reply

so i fixed by this command


sudo ln -s /usr/share/phpmyadmin /var/www/html/

By: till at: 2018-11-22 08:39:16 Reply

The error means that you did not select "apache" as described in the tutorial when the phpmyadmin installer asked you "Web server to
reconfigure automatically". You can redo the phpmyadmin configuration with the command dpkg-reconfigure phpmyadmin
Ensure to select apache2 by navigation to that point with the tab key on your keyboard and then select it with the space key. If you miss to
select it with space, then the option is not used by apt and phpmyadmin will not get activated for apache.

By: Leilf Falkenstrom at: 2018-10-18 17:47:42 Reply

Very good and clear instruktion, but I would recommend that the instruktions updates to install a newer version of php because Joomla will soon
stop supporting that old version. When update you might update the path for joomla too as it have got closer to version 4 (3.8.14 today)
Now when most webb sites use https would it be nice for that to be included in the guide too.

By: Gilson at: 2018-12-13 17:22:19 Reply

Prob: phpmyadmin: "Access denied for user 'root'@'localhost'"


I followed the instruction but cannot login to phpmyadmin. I tries both, the echo code and the "
$sudo mysql -u root
[mysql] use mysql;
[mysql] update user set plugin='' where User='root';
[mysql] flush privileges;
[mysql] \q"
But didn't work.
So, how can I solve this? Paword root phpmyadmin...

Thank

https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-lamp-on-debian-stretch/ 18/22
30/7/2019 Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB

By: sky at: 2018-12-15 13:37:07 Reply

Nice tutorial
Helped me a loot
Many thanks
:D

By: piotao at: 2019-03-11 12:57:59 Reply

on fresh debian install, the step 2 is NOT WORKING, because there apparently IS the password in root account set in the database, so:
Enter current password for root (enter for none): <-- Hit return DO NOT WORK.

By: till at: 2019-03-11 13:09:32 Reply

Step 2 is working fine as it is. I've installed it on a fresh Debian system today, no default password was set there. It might be thought that you
used a different base system from an ISP which had MariaDB installed and therefore a password was set already, in that case, you should enter
the password that you had set when the command requests it.
Please don't claim that a step is wrong just because your particular server as a different preset of applications than a default empty Debian
server.

Home Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB

Sign up now!

https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-lamp-on-debian-stretch/ 19/22
30/7/2019 Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB

 Tutorial Info

Author: Till Brehm


Published: May 02, 2018
Tags: apache, debian, mysql, php, web server

 VMware image download

Debian 9 LAMP Server


Tutorial with Apache,
PHP 7 and MariaDB as
ready to use virtual
machine image download
in ovf/ova format,
compatible with VMWare
and Virtualbox.

Download: debian-9-lamp-server.ova
Guide: VMWare Image Import Guide.
Other Downloads: List of all VMWare Images

 Share This Page

40.2k Followers

https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-lamp-on-debian-stretch/ 20/22
30/7/2019 Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB

 Popular Tutorials

Linux Commands - Overview and Examples

How to create Docker Images with a Dockerfile

https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-lamp-on-debian-stretch/ 21/22
30/7/2019 Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB

How to use grep to search for strings in files on


the shell

How to search files from the terminal on Linux

How to use the Linux ftp command to up- and


download files on the shell

How to Setup ZSH and Oh-my-zsh on Linux

The Perfect Server - Debian 10 (Buster) with


Apache, BIND, Dovecot, PureFTPD and ISPConfig
3.1

Setting, Changing and Resetting MySQL Root


Passwords

How To Configure Remote Access To Your


Ubuntu Desktop

How to install Apache, PHP 7.3 and MySQL on


CentOS 7.6

Xenforo skin by Xenfocus Contribute Contact Help Imprint and Legal Notice Top 

Howtoforge © projektfarm GmbH. Terms and Rules Privacy Policy

https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-lamp-on-debian-stretch/ 22/22

You might also like