{"id":1195,"date":"2026-11-28T13:00:00","date_gmt":"2026-11-28T13:00:00","guid":{"rendered":"https:\/\/vpslake.com\/blog\/?p=1195"},"modified":"2026-11-28T13:00:00","modified_gmt":"2026-11-28T13:00:00","slug":"install-lamp-ubuntu-26-04-mariadb","status":"publish","type":"post","link":"https:\/\/vpslake.com\/blog\/2026\/11\/28\/install-lamp-ubuntu-26-04-mariadb\/","title":{"rendered":"How to Install LAMP Stack with MariaDB on Ubuntu 26.04"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Install LAMP stack with MariaDB on Ubuntu 26.04 and you will have Apache serving web requests, PHP 8.5 processing dynamic pages, and MariaDB storing application data. This setup takes about ten minutes on a clean VPS and includes a firewall, a local database account, and a safe PHP check.<\/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 26.04 LTS (Resolute) 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 IP address and outbound access to the Ubuntu package repositories.<\/li>\n\n\n<li>A domain such as <code>YOUR_DOMAIN<\/code> is optional for this initial install, but required for a trusted 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 logged in as <code>root<\/code>, remove <code>sudo<\/code> from each command. Keep your current SSH session open while enabling UFW.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Confirm Ubuntu 26.04 and update packages<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Checking the release first prevents you from installing packages or service names from a different Ubuntu version.<\/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 show <code>VERSION_ID=\"26.04\"<\/code>, the <code>resolute<\/code> codename, and normally <code>x86_64<\/code> on an AMD64 VPS.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PRETTY_NAME=\"Ubuntu 26.04 LTS\"\nVERSION_ID=\"26.04\"\nVERSION_CODENAME=resolute\nx86_64<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If <code>apt update<\/code> reports a failing third-party repository, disable that repository before continuing. Do not mix packages from another Ubuntu codename.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Install Apache and allow web traffic<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apache handles HTTP requests, while UFW permits only the SSH and web traffic needed to administer and reach this server.<\/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\">Create the SSH rule before enabling UFW. If SSH uses a custom port, replace <code>OpenSSH<\/code> with <code>YOUR_SSH_PORT\/tcp<\/code>, using the numeric port configured for <code>sshd<\/code>. The checks should show <code>Syntax OK<\/code>, <code>active<\/code>, and an active firewall. Ubuntu&#8217;s <a href=\"https:\/\/ubuntu.com\/server\/docs\/how-to\/web-services\/install-apache2\/\" target=\"_blank\" rel=\"noopener\">Apache2 installation guide<\/a> explains the standard configuration layout.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Test Apache locally before testing the public IP. This confirms that the service works independently of DNS or a provider-level firewall.<\/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<p class=\"wp-block-paragraph\">You can also visit <code>http:\/\/SERVER_IP\/<\/code> in a browser. Replace <code>SERVER_IP<\/code> with the VPS address; the default Apache page means port 80 is reachable.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Install PHP 8.5-FPM for Apache<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Ubuntu 26.04 provides PHP 8.5 in its native repositories, and PHP-FPM lets Apache pass dynamic requests to a separate, restartable FastCGI service.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Install the runtime, MariaDB connector, and common extensions used by PHP applications.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install -y php8.5-cli php8.5-fpm php8.5-mysql php8.5-curl php8.5-gd php8.5-mbstring php8.5-xml php8.5-zip php8.5-opcache\nphp --version<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The first version line should begin with PHP 8.5.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PHP 8.5.x (cli) (built: ...)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Enable Apache&#8217;s FastCGI modules and the configuration that points Apache to the PHP 8.5 socket.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo a2enmod proxy_fcgi setenvif\nsudo a2enconf php8.5-fpm\nsudo systemctl enable --now php8.5-fpm\nsudo systemctl reload apache2\nsudo systemctl is-active php8.5-fpm<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A short health endpoint proves that Apache is executing PHP without exposing the detailed server information shown by <code>phpinfo()<\/code>.<\/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<p class=\"wp-block-paragraph\">The file is removed immediately after the check. Do not leave diagnostic PHP pages in a public document root.<\/p>\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 the application data; keeping its listener private allows PHP on this VPS to connect without exposing port 3306 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 asks interactive questions. On a new installation, press Enter when it asks for an empty current root password if that is the authentication state shown on your server. Remove anonymous accounts, reject remote root login, remove the test database, and reload the privilege tables. MariaDB documents the choices in its official <a href=\"https:\/\/mariadb.com\/docs\/server\/clients-and-utilities\/deployment-tools\/mariadb-secure-installation\" target=\"_blank\" rel=\"noopener\"><code>mariadb-secure-installation<\/code> reference<\/a>; Unix-socket authentication for the administrative account is normal on current packages.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a database and a separate local account for the application. Replace <code>YOUR_DB_PASSWORD<\/code> with a long, unique password before running this block. It is a placeholder, not a password to copy literally.<\/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 last command should return <code>lampdb<\/code>. Applications should use <code>lampuser<\/code>, not the MariaDB administrative account. Do not add a UFW rule for port 3306 when the website and database share this VPS.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Verify the LAMP stack<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Run these checks together to confirm that all three services start at boot, PHP is connected to Apache, and MariaDB is answering local queries.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl is-active apache2 php8.5-fpm mariadb\nsudo systemctl is-enabled apache2 php8.5-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 <code>Status: active<\/code> from UFW.<\/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 root access for Apache, PHP, and MariaDB on your own server.<\/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.5-fpm<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The package index may be stale, or the VPS may not be using the Resolute repositories. Confirm the release and inspect the package candidate before retrying.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep -E '^(VERSION_ID|VERSION_CODENAME)=' \/etc\/os-release\nsudo apt update\napt-cache policy php8.5-fpm\nsudo apt install -y php8.5-fpm<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The policy output should show a candidate for Ubuntu 26.04. Do not add a PHP repository or install packages built for another Ubuntu release to work around a source configuration error.<\/p>\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 loaded the matching FastCGI configuration. Check the unit, log, and socket before restarting services.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl status php8.5-fpm --no-pager\nsudo journalctl -u php8.5-fpm -n 40 --no-pager\nls -l \/run\/php\/php8.5-fpm.sock\nsudo apachectl configtest\nsudo systemctl restart php8.5-fpm apache2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the socket is missing, fix the first PHP-FPM error in the journal. Never expose the FPM socket or a FPM TCP port to the public network.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">PHP code appears as plain text in the browser<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Apache is serving the file but is not passing <code>.php<\/code> requests to PHP-FPM. Re-enable the proxy modules and version-specific configuration, then reload Apache.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo a2enmod proxy_fcgi setenvif\nsudo a2enconf php8.5-fpm\nsudo apachectl configtest\nsudo systemctl reload apache2<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">SSH stops working after UFW is enabled<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The firewall rule did not match the port used by <code>sshd<\/code>. Open <strong>VPS control panel (Virtualizor) \u2192 VNC console<\/strong> from the VPSLake client area, allow the actual SSH port, and keep the current console open while testing another 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 listening port. Remove an obsolete rule only after a new SSH session succeeds.<\/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 restricted to local access and port 3306 closed. If remote access is truly required, restrict it to a known source IP and use encrypted connections.<\/li>\n\n\n<li>Keep SSH key authentication enabled, remove unused firewall 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, and 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 does Ubuntu 26.04 use?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The native Ubuntu 26.04 repositories provide the PHP 8.5 package series. This guide names <code>php8.5-fpm<\/code> explicitly so Apache, the systemd unit, and the FPM socket all refer to the same version.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Do I need to open MariaDB port 3306?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. A PHP application on the same VPS can connect locally, so the database port should remain closed to the Internet. Open it only for a deliberate remote connection, restricted by source address and protected with encryption.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can Apache and PHP-FPM run on a server without a domain?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Apache can serve its default site through the VPS IP, and the local health check does not require DNS. Add a domain later, create a virtual host, and enable TLS after the DNS record resolves to the server.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why is the PHP health file deleted immediately?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A dedicated health response confirms that PHP execution works without revealing configuration, paths, or extensions. Leaving even a harmless test endpoint online creates an unnecessary public URL that can be forgotten during later maintenance.<\/p>\n\n\n\n<script type=\"application\/ld+json\">{\"@context\": \"https:\/\/schema.org\", \"@type\": \"FAQPage\", \"mainEntity\": [{\"@type\": \"Question\", \"name\": \"Which PHP version does Ubuntu 26.04 use?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"The native Ubuntu 26.04 repositories provide the PHP 8.5 package series. This guide names `php8.5-fpm` explicitly so Apache, the systemd unit, and the FPM socket all refer to the same version.\"}}, {\"@type\": \"Question\", \"name\": \"Do I need to open MariaDB port 3306?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. A PHP application on the same VPS can connect locally, so the database port should remain closed to the Internet. Open it only for a deliberate remote connection, restricted by source address and protected with encryption.\"}}, {\"@type\": \"Question\", \"name\": \"Can Apache and PHP-FPM run on a server without a domain?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Yes. Apache can serve its default site through the VPS IP, and the local health check does not require DNS. Add a domain later, create a virtual host, and enable TLS after the DNS record resolves to the server.\"}}, {\"@type\": \"Question\", \"name\": \"Why is the PHP health file deleted immediately?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"A dedicated health response confirms that PHP execution works without revealing configuration, paths, or extensions. Leaving even a harmless test endpoint online creates an unnecessary public URL that can be forgotten during later maintenance.\"}}]}<\/script>\n\n","protected":false},"excerpt":{"rendered":"Install LAMP stack with MariaDB on Ubuntu 26.04 using Apache, PHP 8.5-FPM, UFW, and a secure database setup for a working, secure VPS in minutes.","protected":false},"author":1,"featured_media":1196,"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,104],"class_list":["post-1195","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-26-04","cs-entry"],"_links":{"self":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1195","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=1195"}],"version-history":[{"count":1,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1195\/revisions"}],"predecessor-version":[{"id":4252,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/1195\/revisions\/4252"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media\/1196"}],"wp:attachment":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media?parent=1195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/categories?post=1195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/tags?post=1195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}