{"id":16976,"date":"2023-11-04T09:31:00","date_gmt":"2023-11-04T09:31:00","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=16976"},"modified":"2023-11-04T09:31:02","modified_gmt":"2023-11-04T09:31:02","slug":"how-to-install-lamp-apache-mariadb-php-on-debian-12","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2023\/11\/04\/how-to-install-lamp-apache-mariadb-php-on-debian-12\/","title":{"rendered":"How to Install LAMP (Apache, MariaDB, PHP) on Debian 12"},"content":{"rendered":"\n<p>Hello&nbsp;<strong>Debian<\/strong>&nbsp;users, are you looking to install the widely used&nbsp;<strong>LAMP Stack<\/strong>&nbsp;on your system? This will empower you to develop and deploy incredible websites.<\/p>\n\n\n\n<p>If you\u2019re interested, follow along with this comprehensive guide that outlines the installation process for&nbsp;<strong>LAMP<\/strong>&nbsp;on your&nbsp;<strong>Debian 12<\/strong>&nbsp;system.<\/p>\n\n\n\n<p><strong>Contents<\/strong>\u00a0:<\/p>\n\n\n\n<p><strong>What is LAMP?<\/strong><\/p>\n\n\n\n<p><strong>Install Apache in Debian 12<\/strong><\/p>\n\n\n\n<p><strong>Install MariaDB in Debian 12<\/strong><\/p>\n\n\n\n<p><strong>Install PHP, Perl, and Python in Debian 12<\/strong><\/p>\n\n\n\n<p><strong>Install PHP in Debian<\/strong><\/p>\n\n\n\n<p><strong>Install Python in Debian<\/strong><\/p>\n\n\n\n<p><strong>Install Python in Debian<\/strong><\/p>\n\n\n\n<p><strong>Check PHP Info on Debian<\/strong><\/p>\n\n\n\n<p><strong>Create a Virtual Hosting for a Website Using LAMP<\/strong><\/p>\n\n\n\n<p><strong>Host a Website on LAMP Stack<\/strong><\/p>\n\n\n\n<p><strong>Conclusion<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What is LAMP?<\/strong><\/h2>\n\n\n\n<p><strong>LAMP<\/strong>&nbsp;is a combination of four powerful open-source tools (<strong>Linux<\/strong>,&nbsp;<strong>Apache<\/strong>,&nbsp;<strong>MariaDB<\/strong>,&nbsp;<strong>PHP<\/strong>) which aid in building and hosting websites and applications.<\/p>\n\n\n\n<p>Linux (<strong>Debian 12<\/strong>) is a free, open-source operating system,&nbsp;<strong>Apache<\/strong>&nbsp;serves as the web server,&nbsp;<strong>MariaDB<\/strong>&nbsp;is a powerful database server and&nbsp;<strong>PHP<\/strong>&nbsp;is the programming language.<\/p>\n\n\n\n<p>Before&nbsp;<strong>MariaDB<\/strong>,&nbsp;<strong>MySQL<\/strong>&nbsp;was used in the&nbsp;<strong>LAMP<\/strong>&nbsp;stack. However, some people argue about using&nbsp;<strong>Python<\/strong>&nbsp;or&nbsp;<strong>Perl<\/strong>&nbsp;in place of&nbsp;<strong>PHP<\/strong>&nbsp;now.<\/p>\n\n\n\n<p>Let\u2019s initiate the process of\u00a0<strong>LAMP Stack<\/strong>\u00a0installation on a\u00a0fresh Debian 12 installation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Install Apache in Debian 12<\/strong><\/h2>\n\n\n\n<p>Begin by executing the provided\u00a0apt command\u00a0to refresh the local package repository cache, which will update the package lists and upgrade any installed packages:<\/p>\n\n\n\n<p><strong>$ sudo apt update &amp;&amp; sudo apt upgrade -y<\/strong><\/p>\n\n\n\n<p>With your repositories and packages now up-to-date, proceed to install the\u00a0<strong>Apache<\/strong>\u00a0web server from the official repository:<\/p>\n\n\n\n<p><strong>$ sudo apt install apache2* -y<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_8820\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/07\/Install-Apache-in-Debian.png\" alt=\"Install Apache in Debian\" class=\"wp-image-8820\"\/><figcaption class=\"wp-element-caption\">Install Apache in Debian<\/figcaption><\/figure>\n\n\n\n<p>Now that\u00a0<strong>Apache2<\/strong>\u00a0is installed on your system, verify its version by running the following command:<\/p>\n\n\n\n<p><strong>$ sudo apache2 -v<\/strong> <\/p>\n\n\n\n<p>Server version: Apache\/2.4.57 (Debian) <\/p>\n\n\n\n<p>Server built: 2023-04-13T03:26:51<\/p>\n\n\n\n<p>To initiate the service of your\u00a0<strong>Apache2<\/strong>\u00a0web server, execute the \u2018<strong>systemctl start<\/strong>\u2018 command provided below.<\/p>\n\n\n\n<p><strong>$ sudo systemctl start apache2<\/strong><\/p>\n\n\n\n<p>After initiating your web server service, you can also run the command to enable the\u00a0<strong>Apache2<\/strong>\u00a0service to start automatically after a reboot:<\/p>\n\n\n\n<p><strong>$ sudo systemctl enable apache2<\/strong><\/p>\n\n\n\n<p>Moving forward, we can examine the status of the\u00a0<strong>Apache2<\/strong>\u00a0service using the command below.<\/p>\n\n\n\n<p><strong>$ sudo systemctl status apache2<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_8821\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/07\/Check-Apache-in-Debian.png\" alt=\"Check Apache Status\" class=\"wp-image-8821\"\/><figcaption class=\"wp-element-caption\">Check Apache Status<\/figcaption><\/figure>\n\n\n\n<p>Next, you should configure your firewall to allow access to the\u00a0<strong>Apache<\/strong>\u00a0web server from any web browser:<\/p>\n\n\n\n<p><strong>$ sudo ufw allow 80 <\/strong><\/p>\n\n\n\n<p><strong>$ sudo ufw reload<\/strong><\/p>\n\n\n\n<p>Next, let\u2019s check if our&nbsp;<strong>Apache2<\/strong>&nbsp;server is running successfully. To do this, open any web browser and enter \u201c<strong>http:\/\/localhost<\/strong>\u201d in the address bar.<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_8822\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/07\/Check-Apache-Web-Page-in-Debian.png\" alt=\"Check Apache Web Page\" class=\"wp-image-8822\"\/><figcaption class=\"wp-element-caption\">Check Apache Web Page<\/figcaption><\/figure>\n\n\n\n<p>However, you can also access the Apache page by entering your server\u2019s IP address or domain name:<\/p>\n\n\n\n<p><strong>http:\/\/your_server_ip\/ <\/strong><\/p>\n\n\n\n<p>OR <\/p>\n\n\n\n<p><strong>http:\/\/your_domain.com\/<\/strong><\/p>\n\n\n\n<p>If you are unsure about your server\u2019s IP address, run the \u2018<a rel=\"noreferrer noopener\" href=\"https:\/\/www.ubuntumint.com\/find-linux-ip-address\/\" target=\"_blank\">ip addr<\/a>\u2018 command to locate it:<\/p>\n\n\n\n<p><strong>$ ip addr<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_9008\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/08\/Find-Linux-Server-IP-Address.png\" alt=\"Find Linux Server IP Address\" class=\"wp-image-9008\"\/><figcaption class=\"wp-element-caption\">Find Linux Server IP Address<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Install MariaDB in Debian 12<\/strong><\/h2>\n\n\n\n<p><strong>MariaDB<\/strong>&nbsp;is a widely used, high-speed, open-source relational database system that assists users in storing and organizing their data.<\/p>\n\n\n\n<p>To utilize the\u00a0<strong>MariaDB<\/strong>\u00a0database server, execute the provided command to install it:<\/p>\n\n\n\n<p><strong>$ sudo apt install mariadb-* -y<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_8824\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/07\/Install-MariaDB-in-Debian.png\" alt=\"Install MariaDB in Debian\" class=\"wp-image-8824\"\/><figcaption class=\"wp-element-caption\">Install MariaDB in Debian<\/figcaption><\/figure>\n\n\n\n<p>To view the version of the installed\u00a0<strong>MariaDB<\/strong>\u00a0server, type the following:<\/p>\n\n\n\n<p><strong>$ mariadb -V<\/strong><\/p>\n\n\n\n<p>mariadb Ver 15.1 Distrib 10.11.3-MariaDB, for debian-linux-gnu (x86_64) using EditLine wrapper<\/p>\n\n\n\n<p>Next, initiate, enable, and verify the status of your\u00a0<strong>MariaDB<\/strong>\u00a0database server service:<\/p>\n\n\n\n<p><strong>$ sudo systemctl start mariadb <\/strong><\/p>\n\n\n\n<p><strong>$ sudo systemctl enable mariadb <\/strong><\/p>\n\n\n\n<p><strong>$ sudo systemctl status mariadb<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_8825\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/07\/Check-MariaDB-in-Debian.png\" alt=\"Check MariaDB in Debian\" class=\"wp-image-8825\"\/><figcaption class=\"wp-element-caption\">Check MariaDB in Debian<\/figcaption><\/figure>\n\n\n\n<p>Lastly, we will run the following command to ensure the security of our database server:<\/p>\n\n\n\n<p><strong>$ sudo mariadb-secure-installation<\/strong><\/p>\n\n\n\n<p><strong>Note:<\/strong>&nbsp;The primary aim of this command is to generate robust passwords, eliminate anonymous users and unnecessary databases, and disable remote logins. However, you can customize the security settings of your database according to your preferences.<\/p>\n\n\n\n<p>The terminal will present various questions. Read and respond to them correctly.<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_8826\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/07\/Secure-MariaDB-in-Debian.png\" alt=\"Secure MariaDB in Debian\" class=\"wp-image-8826\"\/><figcaption class=\"wp-element-caption\">Secure MariaDB in Debian<\/figcaption><\/figure>\n\n\n\n<p>After securing your database, log in to it by executing the provided command. The terminal will request your password. Enter the password you previously set for your database to successfully access your database server:<\/p>\n\n\n\n<p><strong>$ sudo mariadb -u root -p<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_8827\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/07\/Connect-MySQL-in-Debian.png\" alt=\"Connect MySQL in Debian\" class=\"wp-image-8827\"\/><figcaption class=\"wp-element-caption\">Connect MySQL to Debian<\/figcaption><\/figure>\n\n\n\n<p>After successfully logging into your database server, you can create and manage your databases. Since we have already set up Linux and installed&nbsp;<strong>Apache<\/strong>&nbsp;and&nbsp;<strong>MariaDB<\/strong>, we can finalize our&nbsp;<em>LAMP<\/em>&nbsp;stack installation by adding&nbsp;<strong>PHP<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Install PHP, Perl, and Python in Debian 12<\/strong><\/h2>\n\n\n\n<p>Although the \u2018<strong>P<\/strong>\u2018 in the&nbsp;<strong>LAMP<\/strong>&nbsp;stack traditionally stands for the PHP programming language, there is an ongoing discussion about potentially replacing it with&nbsp;<strong>Perl<\/strong>&nbsp;or&nbsp;<strong>Python<\/strong>.<\/p>\n\n\n\n<p>In this context, we will install&nbsp;<strong>PHP<\/strong>,&nbsp;<strong>Python<\/strong>, and&nbsp;<strong>Perl<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Install PHP in Debian<\/strong><\/h3>\n\n\n\n<p>To install\u00a0<strong>PHP<\/strong>, execute the command provided below:<\/p>\n\n\n\n<p><strong>$ sudo apt install php libapache2-mod-php php-mysql -y<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_8828\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/07\/Install-PHP-in-Debian.png\" alt=\"Install PHP in Debian\" class=\"wp-image-8828\"\/><figcaption class=\"wp-element-caption\">Install PHP in Debian<\/figcaption><\/figure>\n\n\n\n<p>After installing\u00a0<strong>PHP<\/strong>, enter the command\u00a0<code>\u201cphp -v\u201d<\/code>\u00a0to display the installed version:<\/p>\n\n\n\n<p><strong>$ php -v<\/strong> <\/p>\n\n\n\n<p>PHP 8.2.7 (cli) (built: Jun 9 2023 19:37:27) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.7, Copyright (c) Zend Technologies with Zend OPcache v8.2.7, Copyright (c), by Zend Technologies<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Install Python in Debian<\/strong><\/h3>\n\n\n\n<p>However, if you\u2019re someone who wants to install\u00a0<strong>Perl<\/strong>\u00a0instead of\u00a0<strong>PHP<\/strong>, the choice is yours. Simply run the following command to install\u00a0<strong>Perl<\/strong>:<\/p>\n\n\n\n<p><strong>$ sudo apt install perl libapache2-mod-perl2 -y<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_8829\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/07\/Install-Perl-in-Debian.png\" alt=\"Install Perl in Debian\" class=\"wp-image-8829\"\/><figcaption class=\"wp-element-caption\">Install Perl in Debian<\/figcaption><\/figure>\n\n\n\n<p>To determine the installed version of\u00a0<strong>Perl<\/strong>, execute the command:<\/p>\n\n\n\n<p><strong>$ perl -v<\/strong><\/p>\n\n\n\n<p>This is perl 5, version 36, subversion 0 (v5.36.0) built for x86_64-linux-gnu-thread-multi<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Install Python in Debian<\/strong><\/h3>\n\n\n\n<p>Continuing, let\u2019s provide the command to install\u00a0<strong>Python<\/strong>\u00a0on your system, in case you wish to do so:<\/p>\n\n\n\n<p><strong>$ sudo apt install python3 libapache2-mod-python -y<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_8830\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/07\/Install-Python-in-Debian.png\" alt=\"Install Python in Debian\" class=\"wp-image-8830\"\/><figcaption class=\"wp-element-caption\">Install Python in Debian<\/figcaption><\/figure>\n\n\n\n<p>To verify the installed version of\u00a0<strong>Python3<\/strong>, enter the following command:<\/p>\n\n\n\n<p><strong>$ python3 &#8211;version<\/strong> <\/p>\n\n\n\n<p>Python 3.11.2<\/p>\n\n\n\n<p>With our&nbsp;<strong>LAMP<\/strong>&nbsp;stack now fully configured and operational, let\u2019s assess its functionality by hosting a&nbsp;<strong>PHP<\/strong>&nbsp;website on it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Check PHP Info on Debian<\/strong><\/h2>\n\n\n\n<p>Begin by creating a\u00a0<strong>PHP<\/strong>\u00a0file named \u201c<strong>ubuntumint_test.php<\/strong>\u201d within the\u00a0<strong>Apache2<\/strong>\u00a0directory using the\u00a0<a rel=\"noreferrer noopener\" href=\"https:\/\/www.ubuntumint.com\/nano-editor-linux\/\" target=\"_blank\">nano editor<\/a>:<\/p>\n\n\n\n<p><strong>$ sudo nano \/var\/www\/html\/ubuntumint_test.php<\/strong><\/p>\n\n\n\n<p>Next, add the following line to the file, which will display comprehensive information about the PHP installation and configuration:<\/p>\n\n\n\n<p><strong>&lt;?php phpinfo(); ?><\/strong><\/p>\n\n\n\n<p>Now, open a web browser and enter the following URL to view your successfully deployed webpage using the LAMP stack:<\/p>\n\n\n\n<p><strong>http:\/\/localhost\/ubuntumint_test.php <\/strong><\/p>\n\n\n\n<p> OR<\/p>\n\n\n\n<p><strong>http:\/\/your_server_ip\/ubuntumint_test.php<\/strong><\/p>\n\n\n\n<p> OR<\/p>\n\n\n\n<p><strong>http:\/\/your_domain.com\/ubuntumint_test.php<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_8831\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/07\/Check-PHP-Info-in-Debian.png\" alt=\"Check PHP Info in Debian\" class=\"wp-image-8831\"\/><figcaption class=\"wp-element-caption\">Check PHP Info in Debian<\/figcaption><\/figure>\n\n\n\n<p>Here, we can observe that our sample website is hosted on an Apache web server. Continuing, we will thoroughly test the functionality of our LAMP Stack by creating a virtual host and deploying a PHP website on it, along with connecting to a MariaDB database.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Create a Virtual Hosting for a Website Using LAMP<\/strong><\/h2>\n\n\n\n<p><strong>Apache<\/strong>&nbsp;provides the capability to create virtual hosts, a feature that enables hosting multiple domains on a single server.<\/p>\n\n\n\n<p>In&nbsp;<strong>Debian 12<\/strong>, the default configuration of&nbsp;<strong>Apache<\/strong>&nbsp;includes a server block designed to serve a single website, with its documents located in the \u201c<strong>\/var\/www\/html<\/strong>\u201d directory.<\/p>\n\n\n\n<p>However, if your intention is to host multiple websites on Apache, you can accomplish this by creating a new directory within the \u201c<strong>\/var\/www\/<\/strong>\u201d directory using the \u201c<strong>mkdir<\/strong>\u201d command. This new directory should be named after your domain:<\/p>\n\n\n\n<p><strong>$ sudo mkdir \/var\/www\/ubuntumint<\/strong><\/p>\n\n\n\n<p>Now that we\u2019ve successfully created a directory named \u201c<strong>ubuntumint<\/strong>\u201d, let\u2019s assign ownership of this directory to the \u201c<strong>$USER<\/strong>\u201d environment variable, as illustrated below:<\/p>\n\n\n\n<p><strong>$ sudo chown -R $USER:$USER \/var\/www\/ubuntumint<\/strong><\/p>\n\n\n\n<p>Next, generate a new configuration file named \u201c<strong>ubuntumint.conf<\/strong>\u201d within the \u201c<strong>sites-available<\/strong>\u201d directory, which will guide Apache on how to handle the specified domain name:<\/p>\n\n\n\n<p><strong>$ sudo nano \/etc\/apache2\/sites-available\/ubuntumint.conf<\/strong><\/p>\n\n\n\n<p>In this new file, copy and paste the code provided below. Remember to modify the values of \u201c<strong>ServerName<\/strong>\u201d, \u201c<strong>ServerAlias<\/strong>\u201d, \u201c<strong>DocumentRoot<\/strong>\u201d, and \u201c<strong>Directory<\/strong>\u201d to match your domain settings:<\/p>\n\n\n\n<p>&lt;VirtualHost *:80> <\/p>\n\n\n\n<p>      ServerName ubuntumint<\/p>\n\n\n\n<p>      ServerAlias www.ubuntumint<\/p>\n\n\n\n<p>      DocumentRoot \/var\/www\/ubuntumint<\/p>\n\n\n\n<p>       &lt;Directory \/var\/www\/ubuntumint> <\/p>\n\n\n\n<p>               Options Indexes FollowSymLinks<\/p>\n\n\n\n<p>                AllowOverride All <\/p>\n\n\n\n<p>                Require all granted <\/p>\n\n\n\n<p>           &lt;\/Directory> <\/p>\n\n\n\n<p>            ErrorLog ${APACHE_LOG_DIR}\/error.log<\/p>\n\n\n\n<p>            CustomLog ${APACHE_LOG_DIR}\/access.log combined &lt;\/VirtualHost><\/p>\n\n\n\n<p>After saving this file, it\u2019s time to enable the new virtual host:<\/p>\n\n\n\n<p><strong>$ sudo a2ensite ubuntumint<\/strong><\/p>\n\n\n\n<p>Since you\u2019re now using a custom domain name, you might want to disable the default Apache website. To do so, execute the following command:<\/p>\n\n\n\n<p><strong>$ sudo a2dissite 000-default<\/strong><\/p>\n\n\n\n<p>Lastly, verify the integrity of your configuration file by utilizing the following command:<\/p>\n\n\n\n<p><strong>$ sudo apache2ctl configtest<\/strong><\/p>\n\n\n\n<p>Subsequently, execute the\u00a0<strong>reload<\/strong>\u00a0command to apply the changes to the Apache web server configurations:<\/p>\n\n\n\n<p><strong>$ sudo systemctl reload apache2<\/strong><\/p>\n\n\n\n<p>Let\u2019s test this domain by moving the sample PHP file we previously created into our domain\u2019s directory:<\/p>\n\n\n\n<p><strong>$ cp \/var\/www\/html\/ubuntumint_test.php \/var\/www\/ubuntumint\/<\/strong><\/p>\n\n\n\n<p>Now that you\u2019ve established a domain for your website, you can access your website by entering the following URL into your web browser.<\/p>\n\n\n\n<p><strong>http:\/\/your_domain.com\/ubuntumint_test.php<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_9009\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/08\/Verify-Virtual-Hosting-Domain.png\" alt=\"Verify Virtual Hosting Domain\" class=\"wp-image-9009\"\/><figcaption class=\"wp-element-caption\">Verify Virtual Hosting Domain<\/figcaption><\/figure>\n\n\n\n<p>Observe that your website is successfully hosted on the custom domain instead of localhost. This demonstrates how to configure your Apache web server for hosting any website.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Host a Website on LAMP Stack<\/strong><\/h2>\n\n\n\n<p>In this step, we will cover the configuration and testing of the MariaDB database server and PHP for website creation. Subsequently, we will proceed to host this website using the custom domain on the Apache web server.<\/p>\n\n\n\n<p>Now connect to the MariaDB database server and create a new database named \u201c<strong>umdatabase<\/strong>\u201d:<\/p>\n\n\n\n<p><strong>$ sudo mariadb -u root -p <\/strong><\/p>\n\n\n\n<p><strong>$ CREATE DATABASE umdatabase;<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_9010\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/08\/Create-MySQL-Database.png\" alt=\"Create MySQL Database\" class=\"wp-image-9010\"\/><figcaption class=\"wp-element-caption\">Create MySQL Database<\/figcaption><\/figure>\n\n\n\n<p>After successfully creating a new database, proceed to create a new user named \u201c<strong>neem<\/strong>\u201d for all databases and set its password as \u201c<strong>Pass123?<\/strong>\u201d. If you encounter any errors, consult MariaDB\u2019s password policy for guidance:<\/p>\n\n\n\n<p><strong>CREATE USER &#8216;neem&#8217;@&#8217;%&#8217; IDENTIFIED BY &#8216;Pass123?&#8217;;<\/strong><\/p>\n\n\n\n<p>Next, provide the necessary or all privileges to this user by executing the \u201c<strong>GRANT<\/strong>\u201d command:<\/p>\n\n\n\n<p><strong>GRANT ALL PRIVILEGES ON umdatabase.* TO &#8216;neem&#8217;@&#8217;%&#8217;;<\/strong><\/p>\n\n\n\n<p>After granting permissions, it\u2019s necessary to reload the privileges by executing the following command:<\/p>\n\n\n\n<p><strong>FLUSH PRIVILEGES;<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_9011\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/08\/Create-Database-User.png\" alt=\"Create Database User\" class=\"wp-image-9011\"\/><figcaption class=\"wp-element-caption\">Create Database User<\/figcaption><\/figure>\n\n\n\n<p>Continuing, let\u2019s generate a new PHP file named \u201c<strong>lampUser.php<\/strong>\u201d in the domain\u2019s directory using the\u00a0nano editor:<\/p>\n\n\n\n<p><strong>$ sudo nano \/var\/www\/ubuntumint\/lampUser.php<\/strong><\/p>\n\n\n\n<p>In this file, copy and paste the code provided below to create a website capable of storing data in the\u00a0<strong>MariaDB<\/strong>\u00a0database. This code will establish a connection to the database and display an error message if any issues arise during the connection:<\/p>\n\n\n\n<p>&lt;?php \/\/ Database connection parameters<\/p>\n\n\n\n<p> $dbHost = &#8220;localhost&#8221;; \/\/ Replace with your database host <\/p>\n\n\n\n<p>$dbUsername = &#8220;neem&#8221;; \/\/ Replace with your database username $dbPassword = &#8220;Pass123?&#8221;; \/\/ Replace with your database password $dbName = &#8220;umdatabase&#8221;; \/\/ Replace with your database name <\/p>\n\n\n\n<p>\/\/ change your database connection parameters according to your system <\/p>\n\n\n\n<p>\/\/ Create a database connection<\/p>\n\n\n\n<p> $conn = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName); <\/p>\n\n\n\n<p>\/\/ Check if the connection was successful <\/p>\n\n\n\n<p>if ($conn->connect_error) {<\/p>\n\n\n\n<p>                     die(&#8220;Connection failed: &#8221; . $conn->connect_error);<\/p>\n\n\n\n<p> } <\/p>\n\n\n\n<p>\/\/ Create the &#8216;UMusers&#8217; table if it doesn&#8217;t exist <\/p>\n\n\n\n<p>$sqlCreateTable = &#8220;CREATE TABLE IF NOT EXISTS UMusers (<\/p>\n\n\n\n<p>             id INT(11) AUTO_INCREMENT PRIMARY KEY, <\/p>\n\n\n\n<p>             first_name VARCHAR(50) NOT NULL, <\/p>\n\n\n\n<p>             last_name VARCHAR(50) )&#8221;; <\/p>\n\n\n\n<p>\/\/ Throw an exception if table does not create<\/p>\n\n\n\n<p> if ($conn->query($sqlCreateTable) === FALSE) {<\/p>\n\n\n\n<p>                echo &#8220;Error creating table: &#8221; . $conn->error; <\/p>\n\n\n\n<p>                $conn->close(); <\/p>\n\n\n\n<p>                exit(); <\/p>\n\n\n\n<p>} <\/p>\n\n\n\n<p>\/\/ Check if the form is submitted<\/p>\n\n\n\n<p> if ($_SERVER[&#8220;REQUEST_METHOD&#8221;] == &#8220;POST&#8221;) { <\/p>\n\n\n\n<p>                 \/\/ Get the form data <\/p>\n\n\n\n<p>                 $firstName = $_POST[&#8220;first_name&#8221;]; <\/p>\n\n\n\n<p>                 $lastName = $_POST[&#8220;last_name&#8221;]; <\/p>\n\n\n\n<p>                \/\/ Prepare and execute the SQL query to insert the data into the &#8216;users&#8217; table<\/p>\n\n\n\n<p>                $sqlInsert = &#8220;INSERT INTO UMusers (first_name, last_name) VALUES (&#8216;$firstName&#8217;, &#8216;$lastName&#8217;)&#8221;; <\/p>\n\n\n\n<p>                  if ($conn->query($sqlInsert) === TRUE) {<\/p>\n\n\n\n<p>                   echo &#8220;Data saved successfully!&#8221;;<\/p>\n\n\n\n<p>                    } else { <\/p>\n\n\n\n<p>                   echo &#8220;Error: &#8221; . $sqlInsert . &#8220;&lt;br>&#8221; . $conn->error; <\/p>\n\n\n\n<p>                    }<\/p>\n\n\n\n<p> }<\/p>\n\n\n\n<p> \/\/ Close the database connection <\/p>\n\n\n\n<p>$conn->close();<\/p>\n\n\n\n<p>?><\/p>\n\n\n\n<p> &lt;!DOCTYPE html> <\/p>\n\n\n\n<p>&lt;html><\/p>\n\n\n\n<p> &lt;head> <\/p>\n\n\n\n<p>             &lt;title>UbuntuMint LAMP&lt;\/title><\/p>\n\n\n\n<p>  &lt;\/head><\/p>\n\n\n\n<p> &lt;body> <\/p>\n\n\n\n<p>             &lt;h1>UbuntuMint &#8211; LAMP Guide&lt;\/h1> <\/p>\n\n\n\n<p>             &lt;form method=&#8221;post&#8221; action=&#8221;&lt;?php echo $_SERVER[&#8220;PHP_SELF&#8221;]; ?>&#8221;><\/p>\n\n\n\n<p>              &lt;label for=&#8221;first_name&#8221;>First Name:&lt;\/label> <\/p>\n\n\n\n<p>              &lt;input type=&#8221;text&#8221; id=&#8221;first_name&#8221; name=&#8221;first_name&#8221; required>&lt;br>&lt;br> <\/p>\n\n\n\n<p>               &lt;label for=&#8221;last_name&#8221;>Last Name:&lt;\/label><\/p>\n\n\n\n<p>               &lt;input type=&#8221;text&#8221; id=&#8221;last_name&#8221; name=&#8221;last_name&#8221; required>&lt;br>&lt;br><\/p>\n\n\n\n<p>               &lt;input type=&#8221;submit&#8221; value=&#8221;Save&#8221;> <\/p>\n\n\n\n<p>                &lt;\/form><\/p>\n\n\n\n<p> &lt;\/body><\/p>\n\n\n\n<p> &lt;\/html><\/p>\n\n\n\n<p>Save this file and open your web browser to test this PHP website, which can store data in the database table named \u201c<strong>UMusers<\/strong>\u201d:<\/p>\n\n\n\n<p><strong>http:\/\/your_domain\/lampUser.php<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_9012\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/08\/Check-Website-on-LAMP-Stack.gif\" alt=\"Check Website on LAMP Stack\" class=\"wp-image-9012\"\/><figcaption class=\"wp-element-caption\">Check the Website on the LAMP Stack<\/figcaption><\/figure>\n\n\n\n<p>Let\u2019s save some data using this website to verify if it will be stored in your MariaDB server or not:<\/p>\n\n\n\n<p><strong>$ sudo mariadb -u neem -p USE umdatabase; <\/strong><\/p>\n\n\n\n<p><strong>SELECT * FROM UMusers;<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_9013\"><img decoding=\"async\" src=\"https:\/\/www.ubuntumint.com\/wp-content\/uploads\/2023\/08\/Check-Data-on-Database.png\" alt=\"Check Data on Database\" class=\"wp-image-9013\"\/><figcaption class=\"wp-element-caption\">Check Data on the Database<\/figcaption><\/figure>\n\n\n\n<h5 class=\"wp-block-heading\">Conclusion<\/h5>\n\n\n\n<p><strong>LAMP<\/strong>\u00a0is a robust combination of four open-source tools that are essential for creating and\u00a0hosting websites and applications. This article has presented a comprehensive guide for installing\u00a0<strong>LAMP<\/strong>\u00a0on\u00a0<strong>Debian 12<\/strong>.<\/p>\n\n\n\n<p><a href=\"https:\/\/www.ubuntumint.com\/install-lamp-apache-mariadb-php-on-debian-12\/\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello&nbsp;Debian&nbsp;users, are you looking to install the widely used&nbsp;LAMP Stack&nbsp;on your system? This will empower you to develop and deploy incredible websites. If you\u2019re interested, follow along with this comprehensive guide that outlines the installation process for&nbsp;LAMP&nbsp;on your&nbsp;Debian 12&nbsp;system. Contents\u00a0: What is LAMP? Install Apache in Debian 12 Install MariaDB in Debian 12 Install PHP, &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2023\/11\/04\/how-to-install-lamp-apache-mariadb-php-on-debian-12\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Install LAMP (Apache, MariaDB, PHP) on Debian 12&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-16976","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/16976","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=16976"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/16976\/revisions"}],"predecessor-version":[{"id":16977,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/16976\/revisions\/16977"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=16976"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=16976"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=16976"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}