Debian 9 Lamp Server Tutorial With Apache, PHP 7 and Mariadb
Debian 9 Lamp Server Tutorial With Apache, PHP 7 and Mariadb
Log in or Sign up
Search...
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.
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
mysql_secure_installation
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.
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.
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
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.
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
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();
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.
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:
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:
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
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
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.
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:
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
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
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/
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.
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
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
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.
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.
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.
in file info.php
You forget ?>
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 :)
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
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.
Learn more
Many thanks :)
Pat
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 ^^
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.
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.
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
Nice tutorial
Helped me a loot
Many thanks
:D
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.
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
Download: debian-9-lamp-server.ova
Guide: VMWare Image Import Guide.
Other Downloads: List of all VMWare Images
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
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
Xenforo skin by Xenfocus Contribute Contact Help Imprint and Legal Notice Top
https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-lamp-on-debian-stretch/ 22/22