{"id":11704,"date":"2025-02-07T10:40:09","date_gmt":"2025-02-07T10:40:09","guid":{"rendered":"https:\/\/www.ssdnodes.com\/?p=11704"},"modified":"2025-09-19T20:46:49","modified_gmt":"2025-09-19T20:46:49","slug":"install-lamp-mariadb-with-lets-encrypt-on-ubuntu-24-04","status":"publish","type":"post","link":"https:\/\/www.ssdnodes.com\/blog\/install-lamp-mariadb-with-lets-encrypt-on-ubuntu-24-04\/","title":{"rendered":"How to Install LAMP (MariaDB) &#038; Let&#8217;s Encrypt on Ubuntu 24.04"},"content":{"rendered":"<p>Installing LAMP on Ubuntu 24.04 and securing it with Let\u2019s Encrypt is easier than ever. You can now quickly set up Apache, MariaDB, and PHP on your Linux server and start developing web applications with <a href=\"https:\/\/www.ssdnodes.com\/blog\/an-introduction-to-the-http-protocol-and-its-role-in-the-web\/\">HTTPS<\/a> thanks to <a href=\"https:\/\/www.ssdnodes.com\/blog\/install-lets-encrypt-on-ubuntu-certbot-apache-and-nginx\/\">Let\u2019s Encrypt and its Certbot<\/a> client in just a few commands.<\/p>\n<p>In this guide, I'll walk you through a complete setup: first installing the LAMP stack components (Linux, Apache, MariaDB, and PHP), testing your configuration, and finally securing your web server with Let's Encrypt SSL certificates using <a href=\"https:\/\/certbot.eff.org\/\" target=\"_blank\" rel=\"noopener\">Certbot<\/a>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-11761 size-full\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/How-to-Install-LAMP-Lets-Encrypt-on-Ubuntu-24.04.png\" alt=\"Install LAMP (MariaDB) &amp; Let's Encrypt on Ubuntu 24.04\" width=\"600\" height=\"400\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/How-to-Install-LAMP-Lets-Encrypt-on-Ubuntu-24.04.png 600w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/How-to-Install-LAMP-Lets-Encrypt-on-Ubuntu-24.04-300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<h3>Note<\/h3>\n<p>Need a quick setup? Deploy our <strong>1-click<\/strong> LAMP stack by selecting LAMP from the OS menu when creating <a href=\"https:\/\/www.ssdnodes.com\/?utm_source=blog&amp;utm_medium=ubuntu-LAMP\">your server<\/a>. For manual installation steps, continue reading below.<\/p>\n<h2>How to Install LAMP (MariaDB) on Ubuntu with Let's Encrypt<\/h2>\n<p>To Install LAMP on Ubuntu 24.04 with MariaDB and Let's Encrypt, you'll first set up MariaDB, configure the Apache server, install PHP, and verify your installation with a test page. You will then secure your installation with Let's Encrypt SSL using Certbot. This setup ensures a secure environment for hosting dynamic web applications.<\/p>\n<h2>Prerequisites to Installing LAMP on Ubuntu 24.04<\/h2>\n<ul>\n<li>You'll need an Ubuntu 24.04 server with <code>sudo<\/code> privileges. Looking for the perfect server? Our <a href=\"https:\/\/www.ssdnodes.com\/?utm_source=blog&amp;utm_medium=ubuntu-LAMP\">Ubuntu VPS<\/a> combines industry-leading performance with unbeatable prices, backed by enterprise-grade reliability. Take a look at our <a href=\"https:\/\/www.ssdnodes.com\/cheap-vps-hosting\/?utm_source=blog&amp;utm_medium=ubuntu-LAMP\">deals<\/a> and prepare for your mind to be blown \ud83e\udd2f.<\/li>\n<\/ul>\n<p>Check out our <a href=\"https:\/\/www.ssdnodes.com\/blog\/tutorial-setting-up-and-securing-ssh-based-authentication\/\">How to access your server using SSH<\/a> guide to learn how to access your server and create a <code>sudo<\/code> user.<\/p>\n<h2>Step 1 <strong>-<\/strong> Update The Package Cache<\/h2>\n<p>Before you install LAMP on Ubuntu 24.04, start by updating the packages in the package manager cache to the latest available versions using the following command:<\/p>\n<pre><code>sudo apt update<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-11707\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/Update-Ubuntu-24.04-to-Install-LAMP-1024x305.webp\" alt=\"Update Ubuntu 24.04 to Install LAMP with MariaDB\" width=\"600\" height=\"179\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/Update-Ubuntu-24.04-to-Install-LAMP-1024x305.webp 1024w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/Update-Ubuntu-24.04-to-Install-LAMP-300x89.webp 300w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/Update-Ubuntu-24.04-to-Install-LAMP-768x229.webp 768w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/Update-Ubuntu-24.04-to-Install-LAMP-1536x457.webp 1536w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/Update-Ubuntu-24.04-to-Install-LAMP.webp 1680w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<h2>Step 2 <strong>-<\/strong> Install MariaDB, The Database Component of LAMP<\/h2>\n<p>After you update your packages, we'll install the MariaDB database server, the <strong>M<\/strong> in our LAMP stack. We've chosen MariaDB over MySQL for its advanced features, enhanced storage engines, and superior performance capabilities.<\/p>\n<p>This modern database will serve as the foundational data store for your dynamic LAMP web applications. Once your database is set up, it\u2019s also important to design it properly. Tools like <a href=\"https:\/\/chartdb.io\/\" target=\"_blank\" rel=\"noopener\">ChartDB<\/a>\u00a0help you avoid common database design mistakes and organise your schema effectively.<\/p>\n<p>To install MariaDB, execute the following command:<\/p>\n<pre><code>sudo apt install mariadb-server mariadb-client<\/code><\/pre>\n<p>Here, you install:<\/p>\n<ul>\n<li><code>mariadb-server<\/code>: The MariaDB database server which actually stores data.<\/li>\n<li><code>mariadb-client<\/code>: The MariaDB database client which allows you to interact with and manage the database server via the command line.<\/li>\n<\/ul>\n<p>Let's verify that MariaDB installed successfully on your server. Check the MariaDB version using the following command:<\/p>\n<pre><code class=\"language-bash\">mariadb --version<\/code><\/pre>\n<p>Output:<\/p>\n<pre><code class=\"language-bash\">mariadb  Ver 15.1 Distrib 10.11.8-MariaDB, for debian-linux-gnu (x86_64) using  EditLine wrapper<\/code><\/pre>\n<p>Check the current status of MariaDB with this command to ensure your database server is up and running:<\/p>\n<pre><code>sudo service mariadb status<\/code><\/pre>\n<p>You can see that the service is active and running in the line <code>\"Active: active (running) ...\"<\/code>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-11709\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/MariaDB-for-LAMP-1-1.webp\" alt=\"MariaDB for LAMP\" width=\"700\" height=\"274\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/MariaDB-for-LAMP-1-1.webp 1562w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/MariaDB-for-LAMP-1-1-300x118.webp 300w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/MariaDB-for-LAMP-1-1-1024x401.webp 1024w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/MariaDB-for-LAMP-1-1-768x301.webp 768w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/MariaDB-for-LAMP-1-1-1536x602.webp 1536w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/p>\n<h3>Make MariaDB Start at Boot<\/h3>\n<p>Enable MariaDB to automatically start whenever your system boots by running the <code>systemctl enable<\/code> command:<\/p>\n<pre><code>sudo systemctl enable mariadb.service<\/code><\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-11710\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/systemctl-enable-mariadb.webp\" alt=\"systemctl enable mariadb\" width=\"800\" height=\"100\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/systemctl-enable-mariadb.webp 1900w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/systemctl-enable-mariadb-300x38.webp 300w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/systemctl-enable-mariadb-1024x128.webp 1024w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/systemctl-enable-mariadb-768x96.webp 768w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/systemctl-enable-mariadb-1536x192.webp 1536w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/p>\n<h3>Securing The MariaDB Database Server<\/h3>\n<p>When you install LAMP on Ubuntu 24.04, securing MariaDB is a crucial step. By default, MariaDB's settings may leave your database vulnerable to security risks. Let's strengthen your database security by running MariaDB's built-in security script, which guides you through essential security configurations. Later, we'll also secure your web traffic with Let's Encrypt SSL certificates.<\/p>\n<p>To begin the security hardening process for MariaDB, execute the <code>mysql_secure_installation<\/code> script:<\/p>\n<pre><code>sudo mysql_secure_installation<\/code><\/pre>\n<p>You\u2019ll be asked for your current root password:<\/p>\n<pre><code>NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB\r\n      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!\r\n\r\nIn order to log into MariaDB to secure it, we'll need the current\r\npassword for the root user. If you've just installed MariaDB, and\r\nhaven't set the root password yet, you should just press enter here.\r\n\r\nEnter current password for root (enter for none):<\/code><\/pre>\n<p>Tap <strong>Enter<\/strong>.<\/p>\n<p>Next, you'll be asked whether you want to use the <code>unix_socket<\/code> authentication method:<\/p>\n<pre><code>OK, successfully used password, moving on...\r\n\r\nSetting the root password or using the unix_socket ensures that nobody\r\ncan log into the MariaDB root user without the proper authorisation.\r\n\r\nYou already have your root account protected, so you can safely answer 'n'.\r\n\r\nSwitch to unix_socket authentication [Y\/n]<\/code><\/pre>\n<p>As the message says, you already have the root account protected, so just answer with '<strong>n<\/strong>'.<\/p>\n<p>The reason is that you already have password authentication set up for the root account. The <code>unix_socket<\/code> authentication is an alternative method that would tie MariaDB authentication to system user accounts. Since you're already using password authentication and it's working properly, there's no need to switch to <code>unix_socket<\/code> authentication.<\/p>\n<p>In the context of a standard LAMP installation with MariaDB on Ubuntu, we typically want to:<\/p>\n<ol>\n<li>Keep using password authentication since it's more flexible and commonly used in LAMP setups<\/li>\n<li>Maintain compatibility with web applications that expect password authentication<\/li>\n<li>Allow for remote database connections if needed (which <code>unix_socket<\/code> makes more complex)<\/li>\n<\/ol>\n<p>So while <code>unix_socket<\/code> authentication has its merits and can be more secure in certain scenarios, for a typical LAMP stack installation, we should answer '<strong>n<\/strong>' to keep using password authentication. This maintains better compatibility while still being secure when properly configured.<\/p>\n<p>Next, you'll be asked to change the root password:<\/p>\n<pre><code>Enabled successfully!\r\nReloading privilege tables..\r\n ... Success!\r\n\r\nChange the root password? [Y\/n]\r\n<\/code><\/pre>\n<p>Tap <strong>Y<\/strong> to set a new password for root, and re-enter it for validation.<\/p>\n<p>Next, you'll be asked to remove anonymous users:<\/p>\n<pre><code>Change the root password? [Y\/n] y\r\nNew password:\r\nRe-enter new password:\r\nPassword updated successfully!\r\nReloading privilege tables..\r\n ... Success!\r\n\r\nBy default, a MariaDB installation has an anonymous user, allowing anyone\r\nto log into MariaDB without having to have a user account created for\r\nthem.  This is intended only for testing, and to make the installation\r\ngo a bit smoother.  You should remove them before moving into a\r\nproduction environment.\r\n\r\nRemove anonymous users? [Y\/n]\r\n<\/code><\/pre>\n<p>Tap <strong>Y<\/strong> to remove the anonymous users that come with your MariaDB installation.<\/p>\n<p>Next, you\u2019ll be asked whether you want to disallow remote root logins:<\/p>\n<pre><code>Remove anonymous users? [Y\/n] y\r\n ... Success!\r\n\r\nNormally, root should only be allowed to connect from 'localhost'.  This\r\nensures that someone cannot guess at the root password from the network.\r\n\r\nDisallow root login remotely? [Y\/n]\r\n<\/code><\/pre>\n<p>Tap <strong>Y<\/strong> to disable remote root login.<\/p>\n<p>Next, you\u2019ll be asked whether you want to remove the test database that comes with your MariaDB installation:<\/p>\n<pre><code>Disallow root login remotely? [Y\/n] y\r\n ... Success!\r\n\r\nBy default, MariaDB comes with a database named 'test' that anyone can\r\naccess.  This is also intended only for testing, and should be removed\r\nbefore moving into a production environment.\r\n\r\nRemove test database and access to it? [Y\/n]\r\n<\/code><\/pre>\n<p>Tap <strong>Y<\/strong> to remove the MariaDB test database.<\/p>\n<p>Now, let's apply your security changes by reloading MariaDB's privilege tables when prompted:<\/p>\n<pre><code>Remove test database and access to it? [Y\/n] y\r\n - Dropping test database...\r\n ... Success!\r\n - Removing privileges on test database...\r\n ... Success!\r\n\r\nReloading the privilege tables will ensure that all changes made so far\r\nwill take effect immediately.\r\n\r\nReload privilege tables now? [Y\/n]\r\n<\/code><\/pre>\n<p>Tap <strong>Y<\/strong> to reload your MariaDB privilege tables. This ensures changes take effect immediately.<\/p>\n<pre><code>Reload privilege tables now? [Y\/n] y\r\n ... Success!\r\n\r\nCleaning up...\r\n\r\nAll done!  If you've completed all of the above steps, your MariaDB\r\ninstallation should now be secure.\r\n\r\nThanks for using MariaDB!<\/code><\/pre>\n<p>You've now secured your MariaDB installation, which is a crucial step before implementing Let's Encrypt SSL certificates later. Following these security best practices creates a solid foundation for your database server.<\/p>\n<h3>Test Your MariaDB Installation<\/h3>\n<p>Let's verify your MariaDB installation with a simple test.<\/p>\n<p>First, access your MariaDB server:<\/p>\n<pre><code class=\"language-sql\">sudo mariadb -u root -p<\/code><\/pre>\n<p>Create a test database by typing:<\/p>\n<pre><code class=\"language-sql\">CREATE DATABASE testdb;<\/code><\/pre>\n<p>Run this command to see your new database listed alongside the default MariaDB system databases:<\/p>\n<pre><code class=\"language-sql\">SHOW DATABASES;<\/code><\/pre>\n<p>This will show a list of databases, including the new <code>testdb<\/code> you just created, as well as system databases (e.g., <code>information_schema<\/code>, <code>mysql<\/code>).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-11711\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/MariaDB-SHOW-DATABASES.webp\" alt=\"MariaDB SHOW DATABASES\" width=\"518\" height=\"536\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/MariaDB-SHOW-DATABASES.webp 518w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/MariaDB-SHOW-DATABASES-290x300.webp 290w\" sizes=\"auto, (max-width: 518px) 100vw, 518px\" \/><\/p>\n<p>Set up a new test user with:<\/p>\n<pre><code class=\"language-sql\">CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'your_password';<\/code><\/pre>\n<p>Give your new user full access to the test database:<\/p>\n<pre><code class=\"language-sql\">GRANT ALL PRIVILEGES ON testdb.* TO 'testuser'@'localhost';<\/code><\/pre>\n<p>Apply these changes:<\/p>\n<pre><code class=\"language-sql\">FLUSH PRIVILEGES;<\/code><\/pre>\n<p>Leave the MariaDB console:<\/p>\n<pre><code class=\"language-sql\">EXIT;<\/code><\/pre>\n<p>That's it! Your MariaDB server is working properly if you've completed these steps without errors.<\/p>\n<p>Next, let's move on to installing the Apache HTTP server, which we'll also secure with HTTPS using Let\u2019s Encrypt and Certbot. This web server is the '<strong>A<\/strong>' in our LAMP stack and will serve your MariaDB-powered applications to users.<\/p>\n<hr \/>\n<h2>Step 3 <strong>-<\/strong> Install the Apache HTTP Server<\/h2>\n<p>After installing and securing the MariaDB database server, the next step in our LAMP stack installation is installing the Apache HTTP server, which serves web content.<\/p>\n<p>Use <code>apt<\/code> to install Apache using the following command:<\/p>\n<pre><code>sudo apt install apache2<\/code><\/pre>\n<p>You\u2019ll be asked to confirm the installation. Tap the <strong>y<\/strong> key then <strong>Enter<\/strong> to continue.<\/p>\n<p>Once the installation is finished, check Apache\u2019s version to confirm that it was properly installed using the following command:<\/p>\n<pre><code>sudo apachectl -v<\/code><\/pre>\n<p>You should receive an output that looks as follows:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-11712\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/apachectl.webp\" alt=\"apachectl\" width=\"728\" height=\"234\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/apachectl.webp 728w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/apachectl-300x96.webp 300w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/p>\n<p>Set Apache to start at boot:<\/p>\n<pre><code class=\"language-bash\">sudo systemctl enable apache2<\/code><\/pre>\n<p>Then check Apache\u2019s status:<\/p>\n<pre><code>sudo systemctl status apache2<\/code><\/pre>\n<p>The output should show that the Apache service is enabled and running:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-11713\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/Apache-Status-for-LAMP.webp\" alt=\"Apache Status for LAMP\" width=\"700\" height=\"324\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/Apache-Status-for-LAMP.webp 1524w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/Apache-Status-for-LAMP-300x139.webp 300w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/Apache-Status-for-LAMP-1024x474.webp 1024w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/Apache-Status-for-LAMP-768x356.webp 768w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/p>\n<p>Access the default Apache web page to verify it\u2019s working correctly:<\/p>\n<pre><code class=\"language-bash\">http:\/\/your_domain_or_IP<\/code><\/pre>\n<p>You should see a default page informing you that the Apache server is correctly set up:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-11714\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/LAMP_Apache2-Ubuntu-Default-Page.webp\" alt=\"Apache2 Ubuntu Default Page\" width=\"812\" height=\"730\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/LAMP_Apache2-Ubuntu-Default-Page.webp 812w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/LAMP_Apache2-Ubuntu-Default-Page-300x270.webp 300w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/LAMP_Apache2-Ubuntu-Default-Page-768x690.webp 768w\" sizes=\"auto, (max-width: 812px) 100vw, 812px\" \/><\/p>\n<p>You now have Apache installed. Next, you\u2019ll install the PHP language.<\/p>\n<h2>Step 4 <strong>-<\/strong> Install PHP<\/h2>\n<p>Now that you have MariaDB managing your data and Apache serving your web content (which we'll later secure with Let's Encrypt HTTPS), let's install PHP. This powerful scripting language will enable dynamic content processing, letting your users interact with your web applications through forms, API calls, and database-driven features.<\/p>\n<p>Install PHP and its essential packages with this command:<\/p>\n<pre><code>sudo apt install -y php php-fpm php-mysql php-opcache php-cli php-xml php-mbstring libapache2-mod-php php-curl php-gd php-zip<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-11715\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/install-php-and-extensions.webp\" alt=\"install php and extensions\" width=\"2000\" height=\"232\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/install-php-and-extensions.webp 2000w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/install-php-and-extensions-300x35.webp 300w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/install-php-and-extensions-1024x119.webp 1024w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/install-php-and-extensions-768x89.webp 768w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/install-php-and-extensions-1536x178.webp 1536w\" sizes=\"auto, (max-width: 2000px) 100vw, 2000px\" \/><\/p>\n<p>When prompted, tap the <strong>y<\/strong> key then <strong>Enter<\/strong> to continue the installation.<\/p>\n<p>In the preceding command, you install the following packages:<\/p>\n<ul>\n<li><code>php<\/code> and <code>php-fpm<\/code>: The core PHP packages<\/li>\n<li><code>php-mysql<\/code>: For MySQL\/MariaDB database connectivity<\/li>\n<li><code>php-opcache<\/code>: Improves PHP performance by storing precompiled script bytecode<\/li>\n<li><code>php-cli<\/code>: Command line interface for PHP<\/li>\n<li><code>php-xml<\/code> and <code>php-mbstring<\/code>: Essential for handling XML and multi-byte strings, required by many PHP applications<\/li>\n<li><code>libapache2-mod-php<\/code>: Apache PHP module<\/li>\n<li><code>php-curl<\/code>: For making HTTP requests<\/li>\n<li><code>php-gd<\/code>: For image processing<\/li>\n<li><code>php-zip<\/code>: For handling ZIP files<\/li>\n<\/ul>\n<p>To ensure PHP was successfully installed, check its version using the following command:<\/p>\n<pre><code>php -v<\/code><\/pre>\n<p>You should receive an output similar to the following:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-11716\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/PHP-version.webp\" alt=\"PHP version\" width=\"800\" height=\"126\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/PHP-version.webp 2000w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/PHP-version-300x47.webp 300w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/PHP-version-1024x162.webp 1024w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/PHP-version-768x121.webp 768w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/PHP-version-1536x243.webp 1536w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>This means that you've successfully installed PHP.<\/p>\n<p>Now start and enable PHP-FPM. Remember to use your installed PHP version:<\/p>\n<pre><code class=\"language-bash\">sudo systemctl start php8.3-fpm\r\nsudo systemctl enable php8.3-fpm<\/code><\/pre>\n<p>Check the status of PHP-FPM:<\/p>\n<pre><code class=\"language-bash\">sudo systemctl status php8.3-fpm<\/code><\/pre>\n<p>It should be active and running:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-11717\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/php-fpm-status.webp\" alt=\"php-fpm status\" width=\"800\" height=\"280\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/php-fpm-status.webp 2000w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/php-fpm-status-300x105.webp 300w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/php-fpm-status-1024x358.webp 1024w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/php-fpm-status-768x269.webp 768w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/php-fpm-status-1536x538.webp 1536w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>Now, for Apache to work with PHP-FPM, enable the following required modules:<\/p>\n<pre><code class=\"language-bash\">sudo a2enmod proxy_fcgi setenvif<\/code><\/pre>\n<p>This command enables two Apache modules:<\/p>\n<ul>\n<li><code>proxy_fcgi<\/code>: Allows Apache to communicate with PHP-FPM, which runs PHP code.<\/li>\n<li><code>setenvif<\/code>: Lets Apache set environment variables based on request conditions and enable communication between Apache and PHP-FPM.<\/li>\n<\/ul>\n<p>After enabling these modules, you'll need to restart Apache:<\/p>\n<pre><code class=\"language-bash\">sudo systemctl restart apache2<\/code><\/pre>\n<p>Enable the PHP-FPM configuration in Apache. This creates a link from the available configurations to the enabled configurations. After running this, Apache will know how to handle PHP files using PHP-FPM:<\/p>\n<pre><code class=\"language-bash\">sudo a2enconf php8.3-fpm<\/code><\/pre>\n<p>To apply changes, restart Apache:<\/p>\n<pre><code class=\"language-bash\">sudo systemctl restart apache2<\/code><\/pre>\n<p>Restart PHP-FPM:<\/p>\n<pre><code class=\"language-bash\">sudo systemctl restart php8.3-fpm<\/code><\/pre>\n<h3>Setting up PHP-FPM with Apache's Default Virtual Host<\/h3>\n<p>This section demonstrates how to set up PHP-FPM with Apache's default virtual host configuration. In a production environment, you would typically create dedicated virtual hosts under <code>\/etc\/apache2\/sites-available\/<\/code> with specific configurations for each domain, separate log files, and isolated web root directories for better organization and security. However, if you just need a basic PHP setup, here's how to configure it with the default Apache host:<\/p>\n<p>Edit the default Apache configuration:<\/p>\n<pre><code class=\"language-bash\">sudo nano \/etc\/apache2\/sites-available\/000-default.conf<\/code><\/pre>\n<p>Add your domain name with <code>ServerName<\/code> and the <code>FilesMatch<\/code> PHP handler inside the VirtualHost block:<\/p>\n<pre><code>&lt;VirtualHost *:80&gt;\r\n    **ServerName www.example.com**\r\n\r\n    ServerAdmin webmaster@localhost\r\n    DocumentRoot \/var\/www\/html\r\n\r\n    ErrorLog ${APACHE_LOG_DIR}\/error.log\r\n    CustomLog ${APACHE_LOG_DIR}\/access.log combined\r\n  **&lt;FilesMatch \\\\.php$&gt;\r\n      SetHandler \"proxy:unix:\/var\/run\/php\/php8.3-fpm.sock|fcgi:\/\/localhost\/\"\r\n  &lt;\/FilesMatch&gt;**\r\n&lt;\/VirtualHost&gt;<\/code><\/pre>\n<p>Test Apache configuration:<\/p>\n<pre><code class=\"language-bash\">sudo apache2ctl configtest<\/code><\/pre>\n<p>You may see a warning with before the <code>Syntax OK<\/code> message:<\/p>\n<pre><code>AH00558: apache2: Could not reliably determine the server's fully qualified domain name\r\nSyntax OK<\/code><\/pre>\n<p>This warning is informational only and won't affect Apache's operation, and you can safely proceed.<\/p>\n<p>If there are actual configuration errors, Apache will provide specific error messages to help you identify and fix the problems.<\/p>\n<p>After confirming the syntax is correct, restart Apache:<\/p>\n<pre><code class=\"language-bash\">sudo systemctl restart apache2<\/code><\/pre>\n<p>Create a test PHP file:<\/p>\n<pre><code class=\"language-bash\">sudo nano \/var\/www\/html\/info.php<\/code><\/pre>\n<p>Add PHP info code:<\/p>\n<pre><code class=\"language-php\">&lt;?php\r\nphpinfo();\r\n?&gt;<\/code><\/pre>\n<p>Access this newly created PHP info page on your website:<\/p>\n<pre><code>http:\/\/your_server_ip_or_domain\/info.php<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-11718\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/PHP-8-3-6-phpinfo-.webp\" alt=\"PHP Info\" width=\"942\" height=\"721\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/PHP-8-3-6-phpinfo-.webp 942w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/PHP-8-3-6-phpinfo--300x230.webp 300w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/PHP-8-3-6-phpinfo--768x588.webp 768w\" sizes=\"auto, (max-width: 942px) 100vw, 942px\" \/><\/p>\n<h2>Step 5 <strong>-<\/strong> Testing LAMP with a Custom-Made Web Page<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-11763 size-full\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/How-to-Install-LAMP-Lets-Encrypt-on-Ubuntu-24.04-1.png\" alt=\"Testing LAMP\" width=\"600\" height=\"400\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/How-to-Install-LAMP-Lets-Encrypt-on-Ubuntu-24.04-1.png 600w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/How-to-Install-LAMP-Lets-Encrypt-on-Ubuntu-24.04-1-300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>After we've finished installing all the components of the LAMP stack, we will now test our Apache server by creating a small HTML file.<\/p>\n<p>First, create a file called <code>example.html<\/code> inside your <code>\/var\/www\/html<\/code> directory:<\/p>\n<pre><code>sudo nano \/var\/www\/html\/example.html<\/code><\/pre>\n<p>Paste the following into the file:<\/p>\n<pre><code>&lt;!DOCTYPE html&gt;\r\n&lt;html lang=\"en\"&gt;\r\n&lt;head&gt;\r\n    &lt;meta charset=\"UTF-8\"&gt;\r\n    &lt;title&gt;My Test Site&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n    &lt;h1&gt;Hello World!&lt;\/h1&gt;\r\n    &lt;p&gt;If you see this, Apache is working correctly.&lt;\/p&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<p>As you can see, this is straightforward HTML code.<\/p>\n<p>Save and close the file.<\/p>\n<p>Use your browser and navigate to your server\u2019s domain name or IP address:<\/p>\n<pre><code>http:\/\/your_server_domain_or_IP\/example.html<\/code><\/pre>\n<p>You will likely encounter a message informing you that the server doesn\u2019t support a secure connection, this is because we are not encrypting the connection using HTTPS. We\u2019ll fix this later and secure the site using Let\u2019s Encrypt in the next step.<\/p>\n<p>For now, just ignore the warning and proceed to the site:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-11720\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/LAMP-HTTPS-Connection-Required.webp\" alt=\"LAMP HTTPS Connection Required\" width=\"674\" height=\"408\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/LAMP-HTTPS-Connection-Required.webp 674w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/LAMP-HTTPS-Connection-Required-300x182.webp 300w\" sizes=\"auto, (max-width: 674px) 100vw, 674px\" \/><\/p>\n<p>You should see that the <code>example.html<\/code> file you created earlier is correctly served.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-11749\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/LAMP-TEST-Page-1.webp\" alt=\"LAMP TEST Page\" width=\"619\" height=\"583\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/LAMP-TEST-Page-1.webp 619w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/LAMP-TEST-Page-1-300x283.webp 300w\" sizes=\"auto, (max-width: 619px) 100vw, 619px\" \/><br \/>\nGreat! Your LAMP stack is now installed and running. The final step is setting up HTTPS with Let's Encrypt to enable secure connections to your web server.<\/p>\n<h2>Step 6 - Secure Apache With Let's Encrypt Through Certbot<\/h2>\n<p>Now that your LAMP stack is up and running, let's secure your web traffic with Let's Encrypt SSL certificates using Certbot. This final step will enable HTTPS for your web server, ensuring encrypted connections between your users and your applications.<\/p>\n<p><strong>Note:<\/strong> Before proceeding, make sure your firewall allows connections to port <code>80<\/code>.<\/p>\n<p>First, let's install Certbot and its Apache plugin:<\/p>\n<pre><code class=\"language-bash\">sudo apt install certbot python3-certbot-apache<\/code><\/pre>\n<p>With Certbot installed, you can now obtain and configure your SSL certificate. Run the following command:<\/p>\n<pre><code class=\"language-bash\">sudo certbot --apache<\/code><\/pre>\n<p>Certbot will guide you through a simple process:<\/p>\n<ul>\n<li>Enter your email address for important notifications<\/li>\n<li>Accept the terms of service<\/li>\n<li>Answer with <strong>(N)<\/strong> if you want to decline sharing your email with the Electronic Frontier Foundation<\/li>\n<li>Select which domains you want to secure<\/li>\n<\/ul>\n<p>After you generate and configure your Let\u2019s Encrypt certificate, you\u2019ll receive an output similar to the following:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-11723\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/Lets-Encrypt-Certbot-Certificate.webp\" alt=\"Let's Encrypt Certbot Certificate for a LAMP website\" width=\"800\" height=\"262\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/Lets-Encrypt-Certbot-Certificate.webp 2000w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/Lets-Encrypt-Certbot-Certificate-300x98.webp 300w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/Lets-Encrypt-Certbot-Certificate-1024x336.webp 1024w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/Lets-Encrypt-Certbot-Certificate-768x252.webp 768w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/Lets-Encrypt-Certbot-Certificate-1536x504.webp 1536w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>Once Certbot completes its configuration, visit your website using HTTPS:<\/p>\n<pre><code>https:\/\/your_domain<\/code><\/pre>\n<p>You should see that the HTTPS connection is now working correctly.<\/p>\n<p>Certbot automatically sets up certificate renewal. To verify this, run:<\/p>\n<pre><code class=\"language-bash\">sudo systemctl status certbot.timer<\/code><\/pre>\n<p>You can also test the renewal process, without making actual changes, using the <code>--dry-run<\/code> option:<\/p>\n<pre><code class=\"language-bash\">sudo certbot renew --dry-run<\/code><\/pre>\n<p>Your\u2019ll see a simulation of the exact steps Certbot takes to renew your Let\u2019s Encrypt certificate:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-11724\" src=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/Lets-Encrypt-Certbot-Renewal-1.webp\" alt=\"Let's Encrypt Certbot Renewal\" width=\"800\" height=\"246\" srcset=\"https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/Lets-Encrypt-Certbot-Renewal-1.webp 2000w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/Lets-Encrypt-Certbot-Renewal-1-300x92.webp 300w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/Lets-Encrypt-Certbot-Renewal-1-1024x314.webp 1024w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/Lets-Encrypt-Certbot-Renewal-1-768x236.webp 768w, https:\/\/www.ssdnodes.com\/wp-content\/uploads\/2025\/01\/Lets-Encrypt-Certbot-Renewal-1-1536x472.webp 1536w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>That's it! Your LAMP stack is now fully installed and secured with SSL\/TLS encryption. Your web applications will benefit from both the security of Let's Encrypt certificates and the robust performance of the LAMP stack.<\/p>\n<h2>Reader Alert!<\/h2>\n<p>Need a simpler solution? We've got you covered! Our <a href=\"https:\/\/www.ssdnodes.com\/features\/\">1-Click LAMP installation<\/a> does all the heavy lifting for you. Just select LAMP when choosing your server, and we'll handle the technical setup automatically. Head over to <a href=\"https:\/\/www.ssdnodes.com\/\">our website<\/a>, pick your server specs, and you'll be up and running in minutes.<br \/>\nMuch easier, right? \ud83d\ude0a<\/p>\n<h2>FAQ<\/h2>\n<h3>How do I check if MariaDB is running and configured correctly for LAMP?<\/h3>\n<p>Use <code>sudo systemctl status mariadb<\/code> to check if the service is running. To verify the configuration, try logging in with <code>mysql -u root -p<\/code> and run <code>SHOW DATABASES;<\/code>. If both work, your basic setup is correct. Check error logs at <code>\/var\/log\/mysql\/error.log<\/code> if you encounter issues.<\/p>\n<h3>What if the Let's Encrypt certificate doesn't auto-renew?<\/h3>\n<p>First, check if the Certbot timer is active with <code>sudo systemctl status certbot.timer<\/code>. If the timer is running but renewal fails, ensure ports 80 and 443 are open and your domain still points to your server. You can also manually test renewal with <code>sudo certbot renew --dry-run<\/code>.<\/p>\n<h3>Can I use a single Let's Encrypt certificate for multiple domains?<\/h3>\n<p>Yes! When running Certbot, you can secure multiple domains with a single certificate using <code>sudo certbot --apache -d domain1.com -d domain2.com<\/code>. This works for both subdomains and completely different domain names pointing to your server.<\/p>\n<h3>If MariaDB installation seems successful but I can't connect, what's wrong?<\/h3>\n<p>First, verify MariaDB is running with <code>sudo systemctl status mariadb<\/code>. If it's running but you can't connect, you might need to run <code>sudo mysql_secure_installation<\/code> again or check if your user has the correct database privileges using <code>GRANT<\/code> commands.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Set up LAMP on Ubuntu 24.04 &#038; secure it with Let\u2019s Encrypt! \ud83d\ude80 Get Apache, MariaDB &#038; PHP running with HTTPS in just a few steps!<\/p>\n","protected":false},"author":19,"featured_media":11845,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[18,30],"tags":[],"class_list":["post-11704","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops","category-tutorials"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/posts\/11704","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/comments?post=11704"}],"version-history":[{"count":13,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/posts\/11704\/revisions"}],"predecessor-version":[{"id":13916,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/posts\/11704\/revisions\/13916"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/media\/11845"}],"wp:attachment":[{"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/media?parent=11704"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/categories?post=11704"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ssdnodes.com\/wp-json\/wp\/v2\/tags?post=11704"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}