{"id":1191,"date":"2026-11-28T03:00:00","date_gmt":"2026-11-28T03:00:00","guid":{"rendered":"https:\/\/vpslake.com\/blog\/?p=1191"},"modified":"2026-11-28T03:00:00","modified_gmt":"2026-11-28T03:00:00","slug":"install-lamp-ubuntu-24-04-mariadb","status":"publish","type":"post","link":"https:\/\/vpslake.com\/blog\/2026\/11\/28\/install-lamp-ubuntu-24-04-mariadb\/","title":{"rendered":"How to Install LAMP Stack with MariaDB on Ubuntu 24.04"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Install LAMP stack on Ubuntu 24.04 and you will have Apache serving web requests, PHP 8.3 running through PHP-FPM, and MariaDB ready for application data. On a fresh VPS, the base setup takes about ten minutes and includes UFW rules plus a disposable PHP health check.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This guide uses Ubuntu 24.04 LTS packages instead of a third-party PHP repository. The database stays local to the server, which is the safer default for a website running on the same machine.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n\n<li>A 64-bit Ubuntu 24.04 LTS VPS with at least 1 GB of RAM and 10 GB of free disk space.<\/li>\n\n\n<li>SSH access as <code>root<\/code>, or a normal user with working <code>sudo<\/code> privileges.<\/li>\n\n\n<li>A public IPv4 address for testing Apache and outbound access to Ubuntu package mirrors.<\/li>\n\n\n<li>A domain such as <code>YOUR_DOMAIN<\/code> is optional for installation, but required for a production TLS certificate.<\/li>\n\n\n<li>A <a href=\"https:\/\/vpslake.com\/buy-vps\">VPSLake Linux VPS<\/a> with root access if you need a server for this stack.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The commands below use <code>sudo<\/code>. If you are already connected as <code>root<\/code>, remove <code>sudo<\/code> from each command.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Confirm Ubuntu 24.04 and update the VPS<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Checking the release first prevents you from applying package instructions meant for another Ubuntu version, while the full upgrade installs current security updates.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep -E '^(PRETTY_NAME|VERSION_ID|VERSION_CODENAME)=' \/etc\/os-release\nuname -m\nsudo apt update\nsudo apt full-upgrade -y<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The release check should identify Noble Numbat and a 64-bit architecture. A package version may differ as Ubuntu publishes updates.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PRETTY_NAME=\"Ubuntu 24.04 LTS\"\nVERSION_ID=\"24.04\"\nVERSION_CODENAME=noble\nx86_64<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the upgrade installs a new kernel, keep this SSH connection open until you have confirmed that a reboot is safe.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Install Apache and open web ports<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apache is the public-facing web server, and UFW limits inbound traffic to SSH and the HTTP(S) ports a website needs.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install -y apache2 apache2-utils curl ufw\nsudo ufw allow OpenSSH\nsudo ufw allow 80\/tcp\nsudo ufw allow 443\/tcp\nsudo ufw --force enable\nsudo systemctl enable --now apache2\nsudo apachectl configtest\nsudo systemctl is-active apache2\nsudo ufw status verbose<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add the SSH rule before enabling UFW. If SSH listens on a custom port, allow that port instead of the <code>OpenSSH<\/code> profile. The checks should show <code>Syntax OK<\/code>, an active Apache service, and an active firewall.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Test Apache from the server before testing its public address. A successful local response proves that the service is listening even if a provider firewall or DNS setting is still wrong.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -fsSI http:\/\/127.0.0.1\/<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>HTTP\/1.1 200 OK\nContent-Type: text\/html<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Install PHP 8.3-FPM and connect it to Apache<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Ubuntu 24.04 provides PHP 8.3 in its native repositories; PHP-FPM keeps PHP workers separate from Apache and works with Apache&#8217;s event-based request handling. The <a href=\"https:\/\/www.php.net\/manual\/en\/install.fpm.php\" target=\"_blank\" rel=\"noopener\">PHP-FPM manual<\/a> explains the process manager used here.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Install the PHP runtime, the Apache connector, and extensions commonly needed by database-backed applications.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install -y php8.3-cli php8.3-fpm php8.3-mysql php8.3-curl php8.3-gd php8.3-mbstring php8.3-xml php8.3-zip php8.3-opcache\nphp -v<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The first line of the version check should start with PHP 8.3.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PHP 8.3.x (cli) (built: ...)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Enable Apache&#8217;s FastCGI modules, load Ubuntu&#8217;s PHP-FPM configuration, and start the matching service at boot.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo a2enmod proxy_fcgi setenvif\nsudo a2enconf php8.3-fpm\nsudo systemctl enable --now php8.3-fpm\nsudo systemctl reload apache2\nsudo systemctl is-active php8.3-fpm<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create a small endpoint that returns a fixed result rather than exposing server settings with <code>phpinfo()<\/code>. Remove it as soon as the check succeeds.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>printf '%s\\n' '&lt;?php echo \"PHP OK\\\\n\"; ?&gt;' | sudo tee \/var\/www\/html\/health.php &gt; \/dev\/null\ncurl -fsS http:\/\/127.0.0.1\/health.php\nsudo rm -f \/var\/www\/html\/health.php<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>PHP OK<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Install and secure MariaDB<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">MariaDB stores application data, while a separate local account lets the website work without exposing the database service to the Internet.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install -y mariadb-server mariadb-client\nsudo systemctl enable --now mariadb\nsudo systemctl is-active mariadb\nsudo mariadb-secure-installation<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The security utility is interactive. On a new install, press Enter when it asks for an empty current root password if that is what your server uses; remove anonymous users, disallow remote root login, remove the test database, and reload the privilege tables. Keep Unix-socket authentication enabled when the script offers it. MariaDB documents these choices in its <a href=\"https:\/\/mariadb.com\/docs\/server\/clients-and-utilities\/deployment-tools\/mariadb-secure-installation\" target=\"_blank\" rel=\"noopener\">official hardening reference<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create one database and an application user restricted to that database. Replace <code>YOUR_DB_PASSWORD<\/code> with a long, unique password before running the block, and do not reuse your SSH password.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mariadb &lt;&lt;'SQL'\nCREATE DATABASE lampdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;\nCREATE USER 'lampuser'@'localhost' IDENTIFIED BY 'YOUR_DB_PASSWORD';\nGRANT ALL PRIVILEGES ON lampdb.* TO 'lampuser'@'localhost';\nFLUSH PRIVILEGES;\nSQL\nsudo mariadb -e \"SHOW DATABASES LIKE 'lampdb';\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The final command should return a row named <code>lampdb<\/code>. Do not add a UFW rule for port 3306: a local PHP application can connect over the local socket or loopback interface.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Verify the LAMP stack<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These checks confirm that Apache, PHP-FPM, and MariaDB are running, enabled for the next boot, and configured to handle PHP requests.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl is-active apache2 php8.3-fpm mariadb\nsudo systemctl is-enabled apache2 php8.3-fpm mariadb\nsudo apachectl configtest\nphp -m | grep -E 'mysqli|mysqlnd|PDO|mbstring|xml'\nsudo mariadb -e \"SELECT VERSION();\"\ncurl -fsSI http:\/\/127.0.0.1\/\nsudo ufw status<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Expect three <code>active<\/code> results, three <code>enabled<\/code> results, <code>Syntax OK<\/code>, PHP module names, a MariaDB version, an HTTP success response, and an active UFW policy.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>active\nactive\nactive\nenabled\nenabled\nenabled\nSyntax OK\nHTTP\/1.1 200 OK\nStatus: active<\/code><\/pre>\n\n\n\n<aside class=\"vl-element vl-cta-banner\" aria-label=\"Launch your LAMP server\">\n\t<div class=\"vl-cta-banner__content\">\n\t\t<p class=\"vl-cta-banner__eyebrow\">Ubuntu VPS<\/p>\n\t\t<h3 class=\"vl-cta-banner__title\">Launch your LAMP server<\/h3>\n\t\t<p class=\"vl-cta-banner__text\">Get a root-access VPS for Apache, PHP, and MariaDB on Ubuntu 24.04.<\/p>\n\t<\/div>\n\t<a class=\"vl-cta-banner__button\" href=\"\/buy-vps\" aria-label=\"View Linux VPS plans\">View Linux VPS plans<\/a>\n<\/aside>\n\n\n\n<h2 class=\"wp-block-heading\">Troubleshooting<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><code>E: Unable to locate package php8.3-fpm<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The package index may be stale, or the machine may not be using Ubuntu 24.04 repositories. Confirm the release and refresh APT before trying the install again.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep -E '^(PRETTY_NAME|VERSION_ID|VERSION_CODENAME)=' \/etc\/os-release\nsudo apt update\napt-cache policy php8.3-fpm\nsudo apt install -y php8.3-fpm<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Do not mix Noble repositories with another Ubuntu release. That can produce incompatible PHP libraries and a broken Apache module.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>Unit php8.3-fpm.service not found<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The FPM package was not installed successfully, so systemd has no matching unit to start. Install the package, enable the Apache configuration, and reload Apache.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install -y php8.3-fpm\nsudo a2enmod proxy_fcgi setenvif\nsudo a2enconf php8.3-fpm\nsudo systemctl enable --now php8.3-fpm\nsudo systemctl reload apache2<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Apache returns <code>503 Service Unavailable<\/code> for PHP<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">PHP-FPM may be stopped, or Apache may not have its FastCGI configuration enabled. Check the service log and the expected Unix socket before restarting the two services.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl status php8.3-fpm --no-pager\nsudo journalctl -u php8.3-fpm -n 40 --no-pager\nls -l \/run\/php\/php8.3-fpm.sock\nsudo apachectl configtest\nsudo systemctl restart php8.3-fpm apache2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the socket is missing, fix the FPM service error first. Do not expose the FPM socket or port to the public network.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">SSH stopped working after UFW was enabled<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The firewall was activated without a rule for the actual SSH port. Open <strong>VPS control panel (Virtualizor) \u2192 VNC console<\/strong> from the VPSLake client area, allow the port, and then test a second SSH connection.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ss -ltnp | grep ssh\nsudo ufw allow YOUR_SSH_PORT\/tcp\nsudo ufw status numbered<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace <code>YOUR_SSH_PORT<\/code> with the numeric port shown by <code>ss<\/code>. Keep the existing session open until the new connection works.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Hardening<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n\n<li>Point <code>YOUR_DOMAIN<\/code> at the VPS, create an Apache virtual host, and issue a trusted TLS certificate before accepting passwords or personal data.<\/li>\n\n\n<li>Keep MariaDB bound to local access and leave port 3306 closed unless a separate host truly needs database access; if it does, restrict the source IP and use encrypted connections.<\/li>\n\n\n<li>Keep SSH key authentication enabled, remove unused UFW rules, and review the policy with the <a href=\"https:\/\/vpslake.com\/ufw-firewall-generator\">VPSLake UFW firewall generator<\/a>.<\/li>\n\n\n<li>Back up <code>\/var\/www<\/code> and MariaDB separately, then apply Ubuntu security updates regularly.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">FAQ<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Which PHP version comes with Ubuntu 24.04?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Ubuntu 24.04&#8217;s standard repositories provide the PHP 8.3 package series. This guide names the versioned FPM service so Apache and systemd use the same runtime rather than whichever PHP version happens to be selected by a future package change.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Is <code>libapache2-mod-php<\/code> required for this installation?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. Apache forwards PHP requests to <code>php8.3-fpm<\/code> through <code>proxy_fcgi<\/code>, so the embedded <code>mod_php<\/code> module is not part of this setup. That keeps the PHP worker pool independently restartable.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Should I open port 3306 for WordPress or another PHP website?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No, not when the application and MariaDB share the VPS. The application can use <code>localhost<\/code>, while a remote database connection should be a deliberate exception restricted by source IP and encryption.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can I use this LAMP stack without a domain?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Apache and the local health check work with the server IP address. Add the domain later, configure the virtual host, and enable TLS after DNS resolves to the VPS.<\/p>\n\n\n\n<script type=\"application\/ld+json\">{\"@context\": \"https:\/\/schema.org\", \"@type\": \"FAQPage\", \"mainEntity\": [{\"@type\": \"Question\", \"name\": \"Which PHP version comes with Ubuntu 24.04?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Ubuntu 24.04's standard repositories provide the PHP 8.3 package series. This guide names the versioned FPM service so Apache and systemd use the same runtime rather than whichever PHP version happens to be selected by a future package change.\"}}, {\"@type\": \"Question\", \"name\": \"Is `libapache2-mod-php` required for this installation?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. Apache forwards PHP requests to `php8.3-fpm` through `proxy_fcgi`, so the embedded `mod_php` module is not part of this setup. That keeps the PHP worker pool independently restartable.\"}}, {\"@type\": \"Question\", \"name\": \"Should I open port 3306 for WordPress or another PHP website?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No, not when the application and MariaDB share the VPS. The application can use `localhost`, while a remote database connection should be a deliberate exception restricted by source IP and encryption.\"}}, {\"@type\": \"Question\", \"name\": \"Can I use this LAMP stack without a domain?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Yes. Apache and the local health check work with the server IP address. Add the domain later, configure the virtual host, and enable TLS after DNS resolves to the VPS.\"}}]}<\/script>\n\n","protected":false},"excerpt":{"rendered":"Install LAMP stack on Ubuntu 24.04 with Apache, PHP 8.3-FPM, MariaDB, UFW, and a safe health check for a working web server in ten minutes.","protected":false},"author":1,"featured_media":1192,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"csco_singular_sidebar":"","csco_page_header_type":"","csco_page_load_nextpost":"","footnotes":""},"categories":[5,9],"tags":[71,117,73,72,102],"class_list":["post-1191","post","type-post","status-publish","format-standard","has-post-thumbnail","category-guides","category-vps-hosting","tag-apache","tag-lamp-stack","tag-mariadb","tag-php","tag-ubuntu-24-04","cs-entry"],"_links":{"self":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/comments?post=1191"}],"version-history":[{"count":1,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1191\/revisions"}],"predecessor-version":[{"id":4247,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1191\/revisions\/4247"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media\/1192"}],"wp:attachment":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media?parent=1191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/categories?post=1191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/tags?post=1191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}