{"id":2392,"date":"2020-12-08T17:36:35","date_gmt":"2020-12-08T17:36:35","guid":{"rendered":"https:\/\/linuxways.net\/?p=2392"},"modified":"2020-12-08T17:36:37","modified_gmt":"2020-12-08T17:36:37","slug":"how-to-install-linux-apache-mariadb-php-lamp-stack-on-debian-10","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/debian\/how-to-install-linux-apache-mariadb-php-lamp-stack-on-debian-10\/","title":{"rendered":"How to Install Linux, Apache, MariaDB, PHP (LAMP) Stack on Debian 10"},"content":{"rendered":"<p>LAMP (stands for Linux, Apache, MariaDB, PHP) is a collection of open-source software that is used to create dynamic websites and web-based applications. It uses Linux as the OS, Apache as a web server to serve web content over simple URLs, MariaDB as a database server to store websites and applications data, and PHP as the scripting language to serve dynamic content. Usually, the Lamp stack uses MySQL as a database server, however, for Debian systems; <a href=\"https:\/\/mariadb.com\/kb\/en\/moving-from-mysql-to-mariadb-in-debian-9\/\">MariaDB<\/a> is now the default MySQL server.<\/p>\n<p>In this post, we will demonstrate how to install Linux, Apache, MariaDB, and PHP (LAMP) Stack on Debian 10.<\/p>\n<h2>Pre-requisites<\/h2>\n<ul>\n<li>Debian 10 system<\/li>\n<li>User with sudo privileges<\/li>\n<\/ul>\n<h2>Step 1: Installing Apache<\/h2>\n<p>First, update the apt index using the below command in Terminal:<\/p>\n<pre>$ sudo apt update<\/pre>\n<p>Then to install Apache, issue this command:<\/p>\n<pre>$ sudo apt install apache2<\/pre>\n<p>Once the installation is completed, the Apache service will start running automatically. Here is the command to verify the status of the Apache service:<\/p>\n<pre>$ sudo systemctl status apache2<\/pre>\n<p>Now if a firewall is enabled on your system, you will need to allow Apache port through it. The Debian system comes with different profiles for Apache which can be used to adjust the firewall settings. To view the list of all application profiles, issue the below command in Terminal:<\/p>\n<pre>$ sudo ufw app list<\/pre>\n<p>We will enable the &#8220;<strong>WWW Full<\/strong>&#8221; profile for Apache that will allow the traffic on both port <strong>80(HTTP)<\/strong> and port <strong>443(HTTPS).<\/strong> To view information about the &#8220;WWW Full&#8221; profile, execute the below command in Terminal:<\/p>\n<pre>$ sudo ufw app info \"WWW Full\"<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"485\" height=\"176\" class=\"wp-image-2393\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-90.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-90.png 485w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-90-300x109.png 300w\" sizes=\"auto, (max-width: 485px) 100vw, 485px\" \/><\/p>\n<p>To enable the \u201cWWW Full&#8221; profile, execute the below command in Terminal:<\/p>\n<pre>$ sudo ufw allow in \"WWW Full\"<\/pre>\n<p>To verify if the rule has been added successfully, execute the below command in Terminal:<\/p>\n<pre>$ sudo ufw status<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"229\" class=\"wp-image-2394\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-91.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-91.png 600w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-91-300x115.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>Now to check if Apache is working and can serve web pages, try to open Apache&#8217;s default webpage in your web browser:<\/p>\n<pre><a href=\"http:\/\/ip-address\">http:\/\/ip-address<\/a><\/pre>\n<p>Replace the <strong>ip-address<\/strong> with the IP address of your own system.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"741\" height=\"495\" class=\"wp-image-2395\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-92.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-92.png 741w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-92-300x200.png 300w\" sizes=\"auto, (max-width: 741px) 100vw, 741px\" \/><\/p>\n<p>Alternatively, you can also access Apache&#8217;s default webpage using the curl command in your Terminal:<\/p>\n<pre>$ curl <a href=\"http:\/\/ip-address\">http:\/\/ip-address<\/a><\/pre>\n<h2>Step 2 \u2014 Installing MariaDB<\/h2>\n<p>Now, we will install the MariaDB database that will be used to store data for our site. Execute the below command in Terminal to install MariaDB database:<\/p>\n<pre>$ sudo apt install mariadb-server<\/pre>\n<p>Now execute the security script to implement some security features. Use the below command in Terminal to execute the script:<\/p>\n<pre>$ sudo mysql_secure_installation<\/pre>\n<p>You will be presented with a few questions to configure some options for MariaDB. When you are asked to provide the password for root, hit <strong>n<\/strong>. Then it will ask you to set the root password, again hit <strong>N<\/strong>, and then <strong>Enter<\/strong>. Then for all the next questions, hit <strong>y<\/strong> and then <strong>Enter<\/strong> to answer yes and accept the default values.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"814\" height=\"740\" class=\"wp-image-2396\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-93.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-93.png 814w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-93-300x273.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-93-768x698.png 768w\" sizes=\"auto, (max-width: 814px) 100vw, 814px\" \/><\/p>\n<p>Now connect to MariaDB console as a root user. You can do so using this command in Terminal:<\/p>\n<pre>$ sudo mariadb<\/pre>\n<p>Enter the sudo password.<\/p>\n<p>Now create a database let&#8217;s say &#8220;<strong>test<\/strong>&#8220;.<\/p>\n<pre>CREATE DATABASE test;<\/pre>\n<p>Now create a user along with a password and give it full permission to the &#8220;<strong>test<\/strong>&#8221; database. Execute the below command to do so:<\/p>\n<pre>GRANT ALL ON test.* TO tin@'localhost' IDENTIFIED BY 'tintin' WITH GRANT OPTION;<\/pre>\n<p>We have created a user \u2018tin\u2019 with password \u2018tintin\u2019.<\/p>\n<p>Now reload the privileges using the below command:<\/p>\n<pre>FLUSH PRIVILEGES;<\/pre>\n<p>Then exit the console:<\/p>\n<pre>exit<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"899\" height=\"503\" class=\"wp-image-2397\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-94.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-94.png 899w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-94-300x168.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-94-768x430.png 768w\" sizes=\"auto, (max-width: 899px) 100vw, 899px\" \/><\/p>\n<p>Now try logging in to the MariaDB console using the new user credentials you have set in the previous step.<\/p>\n<pre>$ mariadb -u tin -p<\/pre>\n<p>Now enter the password for this user (in our case, it was &#8220;tintin&#8221;).<\/p>\n<p>To view the database &#8220;test&#8221; that you have created in the previous step, execute the below command in Terminal:<\/p>\n<pre>SHOW DATABASES;<\/pre>\n<p>To leave the console, execute the below command in Terminal:<\/p>\n<pre>exit<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"878\" height=\"505\" class=\"wp-image-2398\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-95.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-95.png 878w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-95-300x173.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-95-768x442.png 768w\" sizes=\"auto, (max-width: 878px) 100vw, 878px\" \/><\/p>\n<h2>Step 3: Installing PHP<\/h2>\n<p>In this, we will install PHP to connect with the MariaDB database and retrieve the required information. PHP also connects with the Apache server to hand over the processed information for displaying over the web.<\/p>\n<p>In order to install PHP, issue this command in Terminal:<\/p>\n<pre>$ sudo apt install php libapache2-mod-php php-mysql<\/pre>\n<p>Usually, when a user requests something from the Apache server, it first searches it in the <strong>index.html<\/strong> file. In order to make the server first look for the requested item in the <strong>index.php<\/strong> file, you will need to make a little change in the <strong>dir.conf<\/strong> <strong>file for Apache<\/strong>. Execute the below command in Terminal to edit this file:<\/p>\n<pre>$ sudo nano \/etc\/apache2\/mods-enabled\/dir.conf<\/pre>\n<p>Find the below line in the <strong>dir.conf<\/strong> file:<\/p>\n<pre>DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm<\/pre>\n<p>From the above line, cut <strong>index.php<\/strong> entry and paste it after the <strong>DirectoryIndex <\/strong>as shown in the following screenshot.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"965\" height=\"195\" class=\"wp-image-2399\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-96.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-96.png 965w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-96-300x61.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-96-768x155.png 768w\" sizes=\"auto, (max-width: 965px) 100vw, 965px\" \/><\/p>\n<p>Then save and close the <strong>dir.conf<\/strong> file and reload Apache&#8217;s configuration using the below command.<\/p>\n<pre>$ sudo systemctl reload apache2<\/pre>\n<p>Then execute the below command to verify the status of Apache and to make sure there is no error:<\/p>\n<pre>$ sudo systemctl status apache2<\/pre>\n<h2>Step 4\u2014 Testing PHP Processing on Apache<\/h2>\n<p>Now in this step, we will check if Apache is configured properly and can process requests for PHP files. To do so, create a new <strong>info.php<\/strong> file inside the <strong>\/var\/www\/html<\/strong> directory using the below command in Terminal:<\/p>\n<pre>$ sudo nano \/var\/www\/html\/info.php<\/pre>\n<p>Then add the below lines of code in the <strong>info.php<\/strong> file:<\/p>\n<pre>&lt;?php\n\nphpinfo();<\/pre>\n<p>After that save and close the <strong>info.php<\/strong> file.<\/p>\n<p>Open the below address in your web browser:<\/p>\n<pre>http:\/\/ip-address\/info.php<\/pre>\n<p>Replace the <strong>ip-address<\/strong> with the IP address of your own system.<\/p>\n<p>If you see the below page, then it verifies that the Apache is configured correctly to serve the PHP content.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"941\" height=\"551\" class=\"wp-image-2400\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-97.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-97.png 941w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-97-300x176.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-97-768x450.png 768w\" sizes=\"auto, (max-width: 941px) 100vw, 941px\" \/><\/p>\n<p>This page also shows some information about PHP so it is recommended to remove this page. Issue the below command in Terminal to do so:<\/p>\n<pre>$ sudo rm \/var\/www\/html\/info.php<\/pre>\n<p>That is all there is to it! In this post, you have learned how to install the LAMP stack (Linux, Apache, MariaDB, and PHP ) in your Debian system. We hope you find this post helpful!<\/p>","protected":false},"excerpt":{"rendered":"<p>LAMP (stands for Linux, Apache, MariaDB, PHP) is a collection of open-source software that is used to create dynamic websites and web-based applications. It uses Linux as the&hellip;<\/p>","protected":false},"author":4,"featured_media":2403,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[17,101],"class_list":["post-2392","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-debian","tag-debian-10","tag-lamp-stack"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/2392","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=2392"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/2392\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/2403"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=2392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=2392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=2392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}