Linux: Install LAMP Stack on Debian 10 (Buster)

Hi ,

this post describes the steps to install a lamp stack on debian linux. This is the base for many content management systems like Joomla, WordPress or Drupal.

In Debian 10 the LAMP stack consists of Linux, the Apache 2 Webserver, MariaDB 10 and PHP 7.3.

LAMP means linux as operating system, apache as webserver, mysql as database and PHP as script language. To install all packages login as root.

Refresh package list from repositories

root@debdevt:~# apt-get update

Install apache 2

root@debdevt:~# apt-get -y install apache2

The config of the default site (http) is defined in file
/etc/apache2/sites-available/000-default.conf
Add a

HostnameLookups Off

directive to do not resolve IP Addresses to hostnames in logfile.
Note: If wordpress permalinks returns 404 file not found errorpages add a

<Directory /var/www/html>
AllowOverride All
</Directory>

directive into the virtualhost section of /etc/apache2/sites-available/000-default.conf. Also check that module mod_rewrite is enabled.
root@debdevt:~# a2query -m rewrite

if not enable it
root@debdevt:~# a2enmod rewrite
and check if the .htaccess file in the root directory of your wordpress installation is writeable for the user www-data.
root@debdevt:/var/www/html/blog# ls -la /var/www/html/blog/.htaccess
-rw-rw---- 1 www-data root 246 Feb 24 22:32 /var/www/html/blog/.htaccess

respectively for https
/etc/apache2/sites-available/default-ssl.conf
Note: https is disabled by default due to missing certificates. Here you can find an how to generate a selfsigned certificate for an apache webserver.

Start apache
root@debdevt:~# systemctl start apache2
if the start on jessie fails check systemd log
root@debdevt:~# journalctl -xn

Install MariaDB. During the installation you will be prompted for the mysql root password. Choose a secure password and notice it in a secure location.

root@debdevt:~# apt-get -y install mariadb-common mariadb-server

Secure your MySQL database installation

root@debdevt:~# mysql_secure_installation
Remove anonymous users? [Y/n] y
... Success!
Disallow root login remotely? [Y/n] y
... Success!
Remove test database and access to it? [Y/n] y
- Dropping test database...
Reload privilege tables now? [Y/n] y
Cleaning up...

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

Thanks for using MariaDB!

Open MySQL Console

root@debdevt:~# mysql -u root -p

Create a database named cms and a user with full permission on the datebase with Username cmsuser and password cmspassword

MariaDB> create database cms;
MariaDB> CREATE USER 'cmsuser'@'localhost' identified by 'cmspassword';
MariaDB> grant all on cms.* to 'cmsuser'@'localhost';

Install php

root@debdevt:~# apt-get -y install php7.3 libapache2-mod-php7.3 php7.3-mysql php-pear

Check PHP. Create a php file in your webserver root


cat > /var/www/html/phpinfo.php <<EOF
<?php
phpinfo();
?>
EOF

Time to check the LAMP stack. Open a browser and navigate to
http://IPorHostnameOfyourLAMP/phpinfo.php
this should show a php status site.

php state 7.3
php state 7.3

If phpinfo site is shown correctly delete the file
root@debdevt:~# rm /var/www/html/phpinfo.php

Not necessary but useful: Enable apache PHP logging for apache.
Create a directory for logs

root@debdevt:~# mkdir /var/log/php
root@debdevt:~# chown www-data /var/log/php

Edit /etc/php/7.3/apache2/php.ini and set

error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
display_errors = Off 
log_errors = On 
error_log = /var/log/php/error.log  

To import a database exported by myPhpAdmin for example. Open the sql file and alter the database name at the top of the file

CREATE DATABASE IF NOT EXISTS `DATABASE_AT_WEBHOSTER` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `DATABASE_AT_WEBHOSTER`;

to

CREATE DATABASE IF NOT EXISTS `cms` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `cms`;

and import the database

root@debdevt:~# mysql -u cmsuser -p < exported_database.sql

That’s it.

Michael

Advertisment to support michlstechblog.info

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.