{"id":115,"date":"2026-05-26T16:13:20","date_gmt":"2026-05-26T16:13:20","guid":{"rendered":"https:\/\/hostandtech.com\/kb\/linux\/how-to-install-lamp-stack-ubuntu\/"},"modified":"2026-05-26T16:13:20","modified_gmt":"2026-05-26T16:13:20","slug":"how-to-install-lamp-stack-ubuntu","status":"publish","type":"post","link":"https:\/\/hostandtech.com\/kb\/linux\/how-to-install-lamp-stack-ubuntu\/","title":{"rendered":"How to Install a LAMP Stack on Ubuntu 22.04 \/ 24.04"},"content":{"rendered":"<h2>Overview<\/h2>\n<p>LAMP stands for Linux, Apache, MySQL, and PHP. It&#8217;s the foundation most PHP-based applications \u2014 WordPress, Laravel, Joomla, Magento \u2014 expect to run on. LAMP installation on an Ubuntu server is one of the most common first tasks after spinning up a new VPS, and it&#8217;s also one of the most common sources of silent failures when steps get skipped or done out of order.<\/p>\n<p>This guide covers a clean LAMP install on Ubuntu 22.04 LTS (Jammy) and Ubuntu 24.04 LTS (Noble). The commands are the same for both unless noted. If you&#8217;re on Ubuntu 20.04, the process is nearly identical, but that release hits end-of-life in April 2025, so I&#8217;d recommend upgrading before you build on it.<\/p>\n<p>If you don&#8217;t have a server yet, our <a href=\"https:\/\/www.hostandtech.com\/vps-ssd-servers\">VPS SSD Hosting<\/a> plans start at $5.83\/mo and come with Ubuntu pre-installed \u2014 you can be at the command line in under five minutes.<\/p>\n<h2>Prerequisites<\/h2>\n<ul>\n<li>A server or VPS running Ubuntu 22.04 or 24.04 (fresh install preferred)<\/li>\n<li>Root or sudo access via SSH<\/li>\n<li>A non-root user with sudo privileges (running everything as root is fine for testing, but not for production)<\/li>\n<li>A domain name pointed at your server&#8217;s IP if you want to test virtual hosts \u2014 DNS propagation can take up to 48 hours, though it&#8217;s usually under an hour<\/li>\n<li>Basic comfort with a terminal and a text editor like <code class=\"\" data-line=\"\">nano<\/code> or <code class=\"\" data-line=\"\">vim<\/code><\/li>\n<\/ul>\n<h2>Step-by-Step Instructions<\/h2>\n<h3>Step 1: Update your package index<\/h3>\n<p>Always do this before installing anything. Ubuntu&#8217;s package cache can be days or weeks old on a fresh server, and installing from a stale cache causes version mismatches that are annoying to debug later.<\/p>\n<div class='ht-code-snippet'><button class='ht-code-snippet__copy' onclick='htCopyCode(\"code-block-1\")' type='button' aria-label='Copy code'><svg class='ht-copy-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z'><\/path><path d='M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z'><\/path><\/svg><svg class='ht-check-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M13,24l-9-9,1.414-1.414L13,21.171,26.586,7.586,28,9Z'><\/path><\/svg><\/button><span class='ht-code-snippet__feedback'>Copied to clipboard<\/span><\/p>\n<pre class='ht-code-snippet__code' id='code-block-1'><code class=\"\" data-line=\"\">sudo apt update &amp;&amp; sudo apt upgrade -y<\/code><\/pre>\n<\/div>\n<p>The <code class=\"\" data-line=\"\">-y<\/code> flag auto-confirms prompts. If this is a production server and you want to review changes before applying them, drop the <code class=\"\" data-line=\"\">-y<\/code> and read through what&#8217;s being upgraded.<\/p>\n<h3>Step 2: Install Apache<\/h3>\n<div class='ht-code-snippet'><button class='ht-code-snippet__copy' onclick='htCopyCode(\"code-block-2\")' type='button' aria-label='Copy code'><svg class='ht-copy-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z'><\/path><path d='M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z'><\/path><\/svg><svg class='ht-check-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M13,24l-9-9,1.414-1.414L13,21.171,26.586,7.586,28,9Z'><\/path><\/svg><\/button><span class='ht-code-snippet__feedback'>Copied to clipboard<\/span><\/p>\n<pre class='ht-code-snippet__code' id='code-block-2'><code class=\"\" data-line=\"\">sudo apt install apache2 -y<\/code><\/pre>\n<\/div>\n<p>Once installed, Apache starts automatically. Verify it&#8217;s running:<\/p>\n<div class='ht-code-snippet'><button class='ht-code-snippet__copy' onclick='htCopyCode(\"code-block-3\")' type='button' aria-label='Copy code'><svg class='ht-copy-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z'><\/path><path d='M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z'><\/path><\/svg><svg class='ht-check-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M13,24l-9-9,1.414-1.414L13,21.171,26.586,7.586,28,9Z'><\/path><\/svg><\/button><span class='ht-code-snippet__feedback'>Copied to clipboard<\/span><\/p>\n<pre class='ht-code-snippet__code' id='code-block-3'><code class=\"\" data-line=\"\">sudo systemctl status apache2<\/code><\/pre>\n<\/div>\n<p>You should see <code class=\"\" data-line=\"\">active (running)<\/code> in green. If your server has a firewall (UFW) enabled, you&#8217;ll need to allow HTTP and HTTPS traffic, otherwise nothing will reach Apache from outside:<\/p>\n<div class='ht-code-snippet'><button class='ht-code-snippet__copy' onclick='htCopyCode(\"code-block-4\")' type='button' aria-label='Copy code'><svg class='ht-copy-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z'><\/path><path d='M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z'><\/path><\/svg><svg class='ht-check-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M13,24l-9-9,1.414-1.414L13,21.171,26.586,7.586,28,9Z'><\/path><\/svg><\/button><span class='ht-code-snippet__feedback'>Copied to clipboard<\/span><\/p>\n<pre class='ht-code-snippet__code' id='code-block-4'><code class=\"\" data-line=\"\">sudo ufw allow in &quot;Apache Full&quot;\nsudo ufw status<\/code><\/pre>\n<\/div>\n<p>Open a browser and navigate to your server&#8217;s IP address. You should see the Apache2 Ubuntu Default Page. If you see a connection timeout instead, the firewall rule above is almost always the reason.<\/p>\n<h3>Step 3: Install MySQL<\/h3>\n<div class='ht-code-snippet'><button class='ht-code-snippet__copy' onclick='htCopyCode(\"code-block-5\")' type='button' aria-label='Copy code'><svg class='ht-copy-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z'><\/path><path d='M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z'><\/path><\/svg><svg class='ht-check-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M13,24l-9-9,1.414-1.414L13,21.171,26.586,7.586,28,9Z'><\/path><\/svg><\/button><span class='ht-code-snippet__feedback'>Copied to clipboard<\/span><\/p>\n<pre class='ht-code-snippet__code' id='code-block-5'><code class=\"\" data-line=\"\">sudo apt install mysql-server -y<\/code><\/pre>\n<\/div>\n<p>Ubuntu 22.04 installs MySQL 8.0 by default. Ubuntu 24.04 also ships MySQL 8.0 from the default repos. After installation, run the security script \u2014 this is not optional if you care about security at all:<\/p>\n<div class='ht-code-snippet'><button class='ht-code-snippet__copy' onclick='htCopyCode(\"code-block-6\")' type='button' aria-label='Copy code'><svg class='ht-copy-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z'><\/path><path d='M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z'><\/path><\/svg><svg class='ht-check-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M13,24l-9-9,1.414-1.414L13,21.171,26.586,7.586,28,9Z'><\/path><\/svg><\/button><span class='ht-code-snippet__feedback'>Copied to clipboard<\/span><\/p>\n<pre class='ht-code-snippet__code' id='code-block-6'><code class=\"\" data-line=\"\">sudo mysql_secure_installation<\/code><\/pre>\n<\/div>\n<p>You&#8217;ll be asked several questions. Here&#8217;s what I&#8217;d recommend:<\/p>\n<ul>\n<li><strong>VALIDATE PASSWORD component<\/strong> \u2014 Enable it (<code class=\"\" data-line=\"\">Y<\/code>). Choose policy level 1 (MEDIUM) for most use cases.<\/li>\n<li><strong>Remove anonymous users<\/strong> \u2014 Yes.<\/li>\n<li><strong>Disallow root login remotely<\/strong> \u2014 Yes, unless you have a specific reason to allow remote root login (you probably don&#8217;t).<\/li>\n<li><strong>Remove test database<\/strong> \u2014 Yes.<\/li>\n<li><strong>Reload privilege tables<\/strong> \u2014 Yes.<\/li>\n<\/ul>\n<p>\ud83d\udcdd Note: On MySQL 8.0, the root user uses <code class=\"\" data-line=\"\">auth_socket<\/code> authentication by default, which means you log in with <code class=\"\" data-line=\"\">sudo mysql<\/code> \u2014 not a password. This trips up a lot of people who expect to set a root password during setup and then can&#8217;t figure out why it won&#8217;t accept it.<\/p>\n<h3>Step 4: Create a dedicated MySQL database and user<\/h3>\n<p>Don&#8217;t use the root account for your application. Create a separate user with only the permissions it needs. Log into MySQL first:<\/p>\n<div class='ht-code-snippet'><button class='ht-code-snippet__copy' onclick='htCopyCode(\"code-block-7\")' type='button' aria-label='Copy code'><svg class='ht-copy-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z'><\/path><path d='M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z'><\/path><\/svg><svg class='ht-check-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M13,24l-9-9,1.414-1.414L13,21.171,26.586,7.586,28,9Z'><\/path><\/svg><\/button><span class='ht-code-snippet__feedback'>Copied to clipboard<\/span><\/p>\n<pre class='ht-code-snippet__code' id='code-block-7'><code class=\"\" data-line=\"\">sudo mysql<\/code><\/pre>\n<\/div>\n<p>Then run the following SQL, replacing the placeholders with your actual values:<\/p>\n<div class='ht-code-snippet'><button class='ht-code-snippet__copy' onclick='htCopyCode(\"code-block-8\")' type='button' aria-label='Copy code'><svg class='ht-copy-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z'><\/path><path d='M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z'><\/path><\/svg><svg class='ht-check-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M13,24l-9-9,1.414-1.414L13,21.171,26.586,7.586,28,9Z'><\/path><\/svg><\/button><span class='ht-code-snippet__feedback'>Copied to clipboard<\/span><\/p>\n<pre class='ht-code-snippet__code' id='code-block-8'><code class=\"\" data-line=\"\">CREATE DATABASE myappdb;\nCREATE USER &#039;myappuser&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;StrongPassword123!&#039;;\nGRANT ALL PRIVILEGES ON myappdb.* TO &#039;myappuser&#039;@&#039;localhost&#039;;\nFLUSH PRIVILEGES;\nEXIT;<\/code><\/pre>\n<\/div>\n<p>\u26a0 Warning: <code class=\"\" data-line=\"\">GRANT ALL PRIVILEGES<\/code> gives that user full control over the specified database only \u2014 not the whole server. Never grant <code class=\"\" data-line=\"\">GRANT ALL PRIVILEGES ON *.*<\/code> to an application user.<\/p>\n<h3>Step 5: Install PHP<\/h3>\n<p>Ubuntu 22.04 ships PHP 8.1. Ubuntu 24.04 ships PHP 8.3. For most modern PHP apps either is fine, but always check your application&#8217;s documented requirements before installing.<\/p>\n<div class='ht-code-snippet'><button class='ht-code-snippet__copy' onclick='htCopyCode(\"code-block-9\")' type='button' aria-label='Copy code'><svg class='ht-copy-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z'><\/path><path d='M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z'><\/path><\/svg><svg class='ht-check-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M13,24l-9-9,1.414-1.414L13,21.171,26.586,7.586,28,9Z'><\/path><\/svg><\/button><span class='ht-code-snippet__feedback'>Copied to clipboard<\/span><\/p>\n<pre class='ht-code-snippet__code' id='code-block-9'><code class=\"\" data-line=\"\">sudo apt install php libapache2-mod-php php-mysql -y<\/code><\/pre>\n<\/div>\n<p>The three packages here are: the PHP interpreter itself, the Apache PHP module that lets Apache process <code class=\"\" data-line=\"\">.php<\/code> files, and the PHP-MySQL extension your app needs to talk to the database. Skipping <code class=\"\" data-line=\"\">php-mysql<\/code> is a very common mistake \u2014 everything looks installed, but your app throws database connection errors.<\/p>\n<p>You&#8217;ll likely also need some common PHP extensions depending on your application:<\/p>\n<div class='ht-code-snippet'><button class='ht-code-snippet__copy' onclick='htCopyCode(\"code-block-10\")' type='button' aria-label='Copy code'><svg class='ht-copy-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z'><\/path><path d='M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z'><\/path><\/svg><svg class='ht-check-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M13,24l-9-9,1.414-1.414L13,21.171,26.586,7.586,28,9Z'><\/path><\/svg><\/button><span class='ht-code-snippet__feedback'>Copied to clipboard<\/span><\/p>\n<pre class='ht-code-snippet__code' id='code-block-10'><code class=\"\" data-line=\"\">sudo apt install php-curl php-xml php-mbstring php-zip php-gd php-intl -y<\/code><\/pre>\n<\/div>\n<p>Verify the PHP version and confirm Apache picked it up:<\/p>\n<div class='ht-code-snippet'><button class='ht-code-snippet__copy' onclick='htCopyCode(\"code-block-11\")' type='button' aria-label='Copy code'><svg class='ht-copy-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z'><\/path><path d='M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z'><\/path><\/svg><svg class='ht-check-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M13,24l-9-9,1.414-1.414L13,21.171,26.586,7.586,28,9Z'><\/path><\/svg><\/button><span class='ht-code-snippet__feedback'>Copied to clipboard<\/span><\/p>\n<pre class='ht-code-snippet__code' id='code-block-11'><code class=\"\" data-line=\"\">php -v\nphp -m | grep -E &quot;mysqli|pdo_mysql&quot;<\/code><\/pre>\n<\/div>\n<h3>Step 6: Restart Apache and validate the setup<\/h3>\n<p>Restart Apache to load the PHP module:<\/p>\n<div class='ht-code-snippet'><button class='ht-code-snippet__copy' onclick='htCopyCode(\"code-block-12\")' type='button' aria-label='Copy code'><svg class='ht-copy-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z'><\/path><path d='M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z'><\/path><\/svg><svg class='ht-check-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M13,24l-9-9,1.414-1.414L13,21.171,26.586,7.586,28,9Z'><\/path><\/svg><\/button><span class='ht-code-snippet__feedback'>Copied to clipboard<\/span><\/p>\n<pre class='ht-code-snippet__code' id='code-block-12'><code class=\"\" data-line=\"\">sudo systemctl restart apache2<\/code><\/pre>\n<\/div>\n<p>Now create a PHP info file to confirm Apache is serving PHP correctly:<\/p>\n<div class='ht-code-snippet'><button class='ht-code-snippet__copy' onclick='htCopyCode(\"code-block-13\")' type='button' aria-label='Copy code'><svg class='ht-copy-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z'><\/path><path d='M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z'><\/path><\/svg><svg class='ht-check-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M13,24l-9-9,1.414-1.414L13,21.171,26.586,7.586,28,9Z'><\/path><\/svg><\/button><span class='ht-code-snippet__feedback'>Copied to clipboard<\/span><\/p>\n<pre class='ht-code-snippet__code' id='code-block-13'><code class=\"\" data-line=\"\">sudo nano \/var\/www\/html\/info.php<\/code><\/pre>\n<\/div>\n<p>Add this single line:<\/p>\n<div class='ht-code-snippet'><button class='ht-code-snippet__copy' onclick='htCopyCode(\"code-block-14\")' type='button' aria-label='Copy code'><svg class='ht-copy-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z'><\/path><path d='M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z'><\/path><\/svg><svg class='ht-check-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M13,24l-9-9,1.414-1.414L13,21.171,26.586,7.586,28,9Z'><\/path><\/svg><\/button><span class='ht-code-snippet__feedback'>Copied to clipboard<\/span><\/p>\n<pre class='ht-code-snippet__code' id='code-block-14'><code class=\"\" data-line=\"\">&lt;?php phpinfo(); ?&gt;<\/code><\/pre>\n<\/div>\n<p>Save and close (<code class=\"\" data-line=\"\">Ctrl+X<\/code>, then <code class=\"\" data-line=\"\">Y<\/code>, then <code class=\"\" data-line=\"\">Enter<\/code>). Navigate to <code class=\"\" data-line=\"\">http:\/\/your-server-ip\/info.php<\/code> in a browser. You should see the full PHP info page showing your PHP version, loaded modules, and configuration.<\/p>\n<p>\u26a0 Warning: Delete this file when you&#8217;re done testing. Leaving <code class=\"\" data-line=\"\">info.php<\/code> publicly accessible exposes your PHP configuration, installed modules, and server paths to anyone who knows the URL.<\/p>\n<div class='ht-code-snippet'><button class='ht-code-snippet__copy' onclick='htCopyCode(\"code-block-15\")' type='button' aria-label='Copy code'><svg class='ht-copy-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z'><\/path><path d='M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z'><\/path><\/svg><svg class='ht-check-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M13,24l-9-9,1.414-1.414L13,21.171,26.586,7.586,28,9Z'><\/path><\/svg><\/button><span class='ht-code-snippet__feedback'>Copied to clipboard<\/span><\/p>\n<pre class='ht-code-snippet__code' id='code-block-15'><code class=\"\" data-line=\"\">sudo rm \/var\/www\/html\/info.php<\/code><\/pre>\n<\/div>\n<h3>Step 7: Configure Apache virtual hosts (optional but recommended)<\/h3>\n<p>If you&#8217;re hosting a real site, you&#8217;ll want a virtual host config instead of dumping files into <code class=\"\" data-line=\"\">\/var\/www\/html<\/code>. Create a config for your domain:<\/p>\n<div class='ht-code-snippet'><button class='ht-code-snippet__copy' onclick='htCopyCode(\"code-block-16\")' type='button' aria-label='Copy code'><svg class='ht-copy-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z'><\/path><path d='M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z'><\/path><\/svg><svg class='ht-check-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M13,24l-9-9,1.414-1.414L13,21.171,26.586,7.586,28,9Z'><\/path><\/svg><\/button><span class='ht-code-snippet__feedback'>Copied to clipboard<\/span><\/p>\n<pre class='ht-code-snippet__code' id='code-block-16'><code class=\"\" data-line=\"\">sudo nano \/etc\/apache2\/sites-available\/yourdomain.com.conf<\/code><\/pre>\n<\/div>\n<p>Paste in this template, adjusting the domain and document root:<\/p>\n<div class='ht-code-snippet'><button class='ht-code-snippet__copy' onclick='htCopyCode(\"code-block-17\")' type='button' aria-label='Copy code'><svg class='ht-copy-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z'><\/path><path d='M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z'><\/path><\/svg><svg class='ht-check-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M13,24l-9-9,1.414-1.414L13,21.171,26.586,7.586,28,9Z'><\/path><\/svg><\/button><span class='ht-code-snippet__feedback'>Copied to clipboard<\/span><\/p>\n<pre class='ht-code-snippet__code' id='code-block-17'><code class=\"\" data-line=\"\">&lt;VirtualHost *:80&gt;\n    ServerName yourdomain.com\n    ServerAlias www.yourdomain.com\n    DocumentRoot \/var\/www\/yourdomain.com\/public_html\n    ErrorLog ${APACHE_LOG_DIR}\/yourdomain.com-error.log\n    CustomLog ${APACHE_LOG_DIR}\/yourdomain.com-access.log combined\n&lt;\/VirtualHost&gt;<\/code><\/pre>\n<\/div>\n<p>Create the document root directory, enable the site, and reload Apache:<\/p>\n<div class='ht-code-snippet'><button class='ht-code-snippet__copy' onclick='htCopyCode(\"code-block-18\")' type='button' aria-label='Copy code'><svg class='ht-copy-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z'><\/path><path d='M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z'><\/path><\/svg><svg class='ht-check-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M13,24l-9-9,1.414-1.414L13,21.171,26.586,7.586,28,9Z'><\/path><\/svg><\/button><span class='ht-code-snippet__feedback'>Copied to clipboard<\/span><\/p>\n<pre class='ht-code-snippet__code' id='code-block-18'><code class=\"\" data-line=\"\">sudo mkdir -p \/var\/www\/yourdomain.com\/public_html\nsudo a2ensite yourdomain.com.conf\nsudo systemctl reload apache2<\/code><\/pre>\n<\/div>\n<h2>Common Issues &amp; Troubleshooting<\/h2>\n<h3>Apache shows the default Ubuntu page instead of my site<\/h3>\n<p>The default site (<code class=\"\" data-line=\"\">000-default.conf<\/code>) takes priority if it&#8217;s still enabled. Disable it:<\/p>\n<div class='ht-code-snippet'><button class='ht-code-snippet__copy' onclick='htCopyCode(\"code-block-19\")' type='button' aria-label='Copy code'><svg class='ht-copy-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z'><\/path><path d='M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z'><\/path><\/svg><svg class='ht-check-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M13,24l-9-9,1.414-1.414L13,21.171,26.586,7.586,28,9Z'><\/path><\/svg><\/button><span class='ht-code-snippet__feedback'>Copied to clipboard<\/span><\/p>\n<pre class='ht-code-snippet__code' id='code-block-19'><code class=\"\" data-line=\"\">sudo a2dissite 000-default.conf\nsudo systemctl reload apache2<\/code><\/pre>\n<\/div>\n<p>If that doesn&#8217;t fix it, double-check your <code class=\"\" data-line=\"\">ServerName<\/code> directive matches the domain you&#8217;re requesting, and that DNS is actually pointing to your server&#8217;s IP.<\/p>\n<h3>PHP files download instead of executing in the browser<\/h3>\n<p>Apache is serving <code class=\"\" data-line=\"\">.php<\/code> files as plain text instead of passing them to PHP. This means <code class=\"\" data-line=\"\">libapache2-mod-php<\/code> either isn&#8217;t installed or the module isn&#8217;t loaded. Check:<\/p>\n<div class='ht-code-snippet'><button class='ht-code-snippet__copy' onclick='htCopyCode(\"code-block-20\")' type='button' aria-label='Copy code'><svg class='ht-copy-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z'><\/path><path d='M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z'><\/path><\/svg><svg class='ht-check-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M13,24l-9-9,1.414-1.414L13,21.171,26.586,7.586,28,9Z'><\/path><\/svg><\/button><span class='ht-code-snippet__feedback'>Copied to clipboard<\/span><\/p>\n<pre class='ht-code-snippet__code' id='code-block-20'><code class=\"\" data-line=\"\">apache2ctl -M | grep php<\/code><\/pre>\n<\/div>\n<p>If you see nothing, the module isn&#8217;t active. Reinstall and restart:<\/p>\n<div class='ht-code-snippet'><button class='ht-code-snippet__copy' onclick='htCopyCode(\"code-block-21\")' type='button' aria-label='Copy code'><svg class='ht-copy-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z'><\/path><path d='M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z'><\/path><\/svg><svg class='ht-check-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M13,24l-9-9,1.414-1.414L13,21.171,26.586,7.586,28,9Z'><\/path><\/svg><\/button><span class='ht-code-snippet__feedback'>Copied to clipboard<\/span><\/p>\n<pre class='ht-code-snippet__code' id='code-block-21'><code class=\"\" data-line=\"\">sudo apt install --reinstall libapache2-mod-php\nsudo systemctl restart apache2<\/code><\/pre>\n<\/div>\n<h3>ERROR 1698 (28000): Access denied for user &#8216;root&#8217;@&#8217;localhost&#8217;<\/h3>\n<p>This is annoyingly common and the error message isn&#8217;t clear about the real cause. MySQL 8.0 authenticates the root user via the system socket, not a password. You need to prefix your MySQL command with <code class=\"\" data-line=\"\">sudo<\/code>:<\/p>\n<div class='ht-code-snippet'><button class='ht-code-snippet__copy' onclick='htCopyCode(\"code-block-22\")' type='button' aria-label='Copy code'><svg class='ht-copy-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z'><\/path><path d='M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z'><\/path><\/svg><svg class='ht-check-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M13,24l-9-9,1.414-1.414L13,21.171,26.586,7.586,28,9Z'><\/path><\/svg><\/button><span class='ht-code-snippet__feedback'>Copied to clipboard<\/span><\/p>\n<pre class='ht-code-snippet__code' id='code-block-22'><code class=\"\" data-line=\"\">sudo mysql -u root<\/code><\/pre>\n<\/div>\n<p>If you genuinely need password-based root login (for a legacy app or a tool that doesn&#8217;t support socket auth), you can switch the auth plugin, but socket auth is safer and I&#8217;d leave it as-is unless you have a real reason to change it.<\/p>\n<h3>MySQL service won&#8217;t start after install<\/h3>\n<p>Check the actual error, not just the systemctl status:<\/p>\n<div class='ht-code-snippet'><button class='ht-code-snippet__copy' onclick='htCopyCode(\"code-block-23\")' type='button' aria-label='Copy code'><svg class='ht-copy-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z'><\/path><path d='M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z'><\/path><\/svg><svg class='ht-check-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M13,24l-9-9,1.414-1.414L13,21.171,26.586,7.586,28,9Z'><\/path><\/svg><\/button><span class='ht-code-snippet__feedback'>Copied to clipboard<\/span><\/p>\n<pre class='ht-code-snippet__code' id='code-block-23'><code class=\"\" data-line=\"\">sudo journalctl -u mysql -n 50 --no-pager<\/code><\/pre>\n<\/div>\n<p>The most common culprits on VPS servers are a full <code class=\"\" data-line=\"\">\/var<\/code> partition (check with <code class=\"\" data-line=\"\">df -h<\/code>) or a port conflict if something else is already on 3306 (check with <code class=\"\" data-line=\"\">sudo ss -tlnp | grep 3306<\/code>).<\/p>\n<h3>mod_rewrite rules not working (.htaccess ignored)<\/h3>\n<p>If your app uses <code class=\"\" data-line=\"\">.htaccess<\/code> for URL rewriting (WordPress does, Laravel does), Apache needs <code class=\"\" data-line=\"\">mod_rewrite<\/code> enabled and the directory must allow overrides. Enable the module:<\/p>\n<div class='ht-code-snippet'><button class='ht-code-snippet__copy' onclick='htCopyCode(\"code-block-24\")' type='button' aria-label='Copy code'><svg class='ht-copy-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z'><\/path><path d='M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z'><\/path><\/svg><svg class='ht-check-icon' viewBox='0 0 32 32' width='16' height='16' fill='currentColor'><path d='M13,24l-9-9,1.414-1.414L13,21.171,26.586,7.586,28,9Z'><\/path><\/svg><\/button><span class='ht-code-snippet__feedback'>Copied to clipboard<\/span><\/p>\n<pre class='ht-code-snippet__code' id='code-block-24'><code class=\"\" data-line=\"\">sudo a2enmod rewrite\nsudo systemctl restart apache2<\/code><\/pre>\n<\/div>\n<p>Then in your virtual host config, make sure you have <code class=\"\" data-line=\"\">AllowOverride All<\/code> set for your document root directory. Without it, Apache silently ignores your <code class=\"\" data-line=\"\">.htaccess<\/code> file entirely \u2014 no error, just broken URLs.<\/p>\n<h2>FAQ<\/h2>\n<div class='ht-faq-section'>\n<h2>Frequently Asked Questions<\/h2>\n<div class='ht-faq-item'>\n<h3 class='ht-faq-question'>Does LAMP work on Ubuntu 24.04?<\/h3>\n<div class='ht-faq-answer'>\n<p>Yes. The installation process in this guide works on both Ubuntu 22.04 and 24.04. The main difference is the default PHP version \u2014 22.04 ships PHP 8.1, while 24.04 ships PHP 8.3. Check your application&#8217;s PHP requirements before installing to make sure it supports the version your Ubuntu release provides.<\/p>\n<\/div>\n<\/div>\n<div class='ht-faq-item'>\n<h3 class='ht-faq-question'>Do I need LAMP if I&#039;m using managed WordPress hosting?<\/h3>\n<div class='ht-faq-answer'>\n<p>No. Managed WordPress hosting (like our managed plans at Host &#038; Tech) handles the entire server stack for you \u2014 Apache or Nginx, PHP, and MySQL are all pre-configured and maintained. LAMP installation is only necessary if you&#8217;re setting up your own unmanaged VPS or dedicated server.<\/p>\n<\/div>\n<\/div>\n<div class='ht-faq-item'>\n<h3 class='ht-faq-question'>How do I install a specific PHP version on Ubuntu instead of the default?<\/h3>\n<div class='ht-faq-answer'>\n<p>You&#8217;ll need to add the Ondrej PHP PPA, which maintains multiple PHP versions for Ubuntu. Run <code class=\"\" data-line=\"\">sudo add-apt-repository ppa:ondrej\/php<\/code>, then <code class=\"\" data-line=\"\">sudo apt update<\/code>, and install your target version with something like <code class=\"\" data-line=\"\">sudo apt install php8.2 libapache2-mod-php8.2 php8.2-mysql<\/code>. You can then switch the active PHP version using <code class=\"\" data-line=\"\">sudo update-alternatives --config php<\/code>.<\/p>\n<\/div>\n<\/div>\n<div class='ht-faq-item'>\n<h3 class='ht-faq-question'>Can I use Nginx instead of Apache in a LAMP stack?<\/h3>\n<div class='ht-faq-answer'>\n<p>If you swap Apache for Nginx, it&#8217;s technically a LEMP stack (Linux, Nginx, MySQL, PHP). Nginx handles high-concurrency traffic more efficiently than Apache in many scenarios, but it doesn&#8217;t natively support <code class=\"\" data-line=\"\">.htaccess<\/code> files \u2014 so if your app relies on them, you&#8217;ll need to convert those rules to Nginx server block syntax. For a straightforward LAMP setup, Apache is the easier starting point.<\/p>\n<\/div>\n<\/div>\n<div class='ht-faq-item'>\n<h3 class='ht-faq-question'>How do I add HTTPS\/SSL to my LAMP server?<\/h3>\n<div class='ht-faq-answer'>\n<p>Use Certbot with the Let&#8217;s Encrypt certificate authority \u2014 it&#8217;s free and handles renewal automatically. Install it with <code class=\"\" data-line=\"\">sudo apt install certbot python3-certbot-apache -y<\/code>, then run <code class=\"\" data-line=\"\">sudo certbot --apache -d yourdomain.com<\/code>. Certbot will modify your Apache virtual host config and set up auto-renewal. Make sure port 443 is open in your firewall before running it.<\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>LAMP gives you a full web server environment on Ubuntu in under 20 minutes. This guide walks through installing Apache, MySQL, and PHP \u2014 plus the bits most tutorials skip, like securing MySQL and validating your PHP config.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[49],"tags":[51,50,12,52,53,15,11],"class_list":["post-115","post","type-post","status-publish","format-standard","hentry","category-linux","tag-apache","tag-lamp-stack","tag-linux","tag-mysql","tag-php","tag-ubuntu","tag-vps"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Install a LAMP Stack on Ubuntu 22.04 \/ 24.04<\/title>\n<meta name=\"description\" content=\"Step-by-step LAMP installation guide for Ubuntu 22.04 and 24.04. Install Apache, MySQL, and PHP on your Ubuntu server and host your first site.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/hostandtech.com\/kb\/linux\/how-to-install-lamp-stack-ubuntu\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Install a LAMP Stack on Ubuntu 22.04 \/ 24.04\" \/>\n<meta property=\"og:description\" content=\"Step-by-step LAMP installation guide for Ubuntu 22.04 and 24.04. Install Apache, MySQL, and PHP on your Ubuntu server and host your first site.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/hostandtech.com\/kb\/linux\/how-to-install-lamp-stack-ubuntu\/\" \/>\n<meta property=\"og:site_name\" content=\"Host And Tech knowledge base\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/stshostandtech\" \/>\n<meta property=\"article:published_time\" content=\"2026-05-26T16:13:20+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@stshostandtech\" \/>\n<meta name=\"twitter:site\" content=\"@stshostandtech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/linux\\\/how-to-install-lamp-stack-ubuntu\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/linux\\\/how-to-install-lamp-stack-ubuntu\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#\\\/schema\\\/person\\\/b6fa79c48ddaba71af32e395c5b017ee\"},\"headline\":\"How to Install a LAMP Stack on Ubuntu 22.04 \\\/ 24.04\",\"datePublished\":\"2026-05-26T16:13:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/linux\\\/how-to-install-lamp-stack-ubuntu\\\/\"},\"wordCount\":1461,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#organization\"},\"keywords\":[\"Apache\",\"LAMP stack\",\"Linux\",\"MySQL\",\"PHP\",\"Ubuntu\",\"VPS\"],\"articleSection\":[\"Linux Server\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/hostandtech.com\\\/kb\\\/linux\\\/how-to-install-lamp-stack-ubuntu\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/linux\\\/how-to-install-lamp-stack-ubuntu\\\/\",\"url\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/linux\\\/how-to-install-lamp-stack-ubuntu\\\/\",\"name\":\"How to Install a LAMP Stack on Ubuntu 22.04 \\\/ 24.04\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#website\"},\"datePublished\":\"2026-05-26T16:13:20+00:00\",\"description\":\"Step-by-step LAMP installation guide for Ubuntu 22.04 and 24.04. Install Apache, MySQL, and PHP on your Ubuntu server and host your first site.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/linux\\\/how-to-install-lamp-stack-ubuntu\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/hostandtech.com\\\/kb\\\/linux\\\/how-to-install-lamp-stack-ubuntu\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/linux\\\/how-to-install-lamp-stack-ubuntu\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Install a LAMP Stack on Ubuntu 22.04 \\\/ 24.04\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#website\",\"url\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/\",\"name\":\"Host And Tech knowledge base\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#organization\",\"name\":\"Host And Tech knowledge base\",\"url\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/wp-content\\\/uploads\\\/2026\\\/05\\\/logo-dark.png\",\"contentUrl\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/wp-content\\\/uploads\\\/2026\\\/05\\\/logo-dark.png\",\"width\":1134,\"height\":395,\"caption\":\"Host And Tech knowledge base\"},\"image\":{\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/stshostandtech\",\"https:\\\/\\\/x.com\\\/stshostandtech\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/#\\\/schema\\\/person\\\/b6fa79c48ddaba71af32e395c5b017ee\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/aa1edac8bbadb442e059a5b65ad45a3b2e3ce689202373b96e3e567517ae4b39?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/aa1edac8bbadb442e059a5b65ad45a3b2e3ce689202373b96e3e567517ae4b39?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/aa1edac8bbadb442e059a5b65ad45a3b2e3ce689202373b96e3e567517ae4b39?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"sameAs\":[\"https:\\\/\\\/hostandtech.com\\\/kb\"],\"url\":\"https:\\\/\\\/hostandtech.com\\\/kb\\\/author\\\/admin_fjj7qydm\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Install a LAMP Stack on Ubuntu 22.04 \/ 24.04","description":"Step-by-step LAMP installation guide for Ubuntu 22.04 and 24.04. Install Apache, MySQL, and PHP on your Ubuntu server and host your first site.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/hostandtech.com\/kb\/linux\/how-to-install-lamp-stack-ubuntu\/","og_locale":"en_US","og_type":"article","og_title":"How to Install a LAMP Stack on Ubuntu 22.04 \/ 24.04","og_description":"Step-by-step LAMP installation guide for Ubuntu 22.04 and 24.04. Install Apache, MySQL, and PHP on your Ubuntu server and host your first site.","og_url":"https:\/\/hostandtech.com\/kb\/linux\/how-to-install-lamp-stack-ubuntu\/","og_site_name":"Host And Tech knowledge base","article_publisher":"https:\/\/www.facebook.com\/stshostandtech","article_published_time":"2026-05-26T16:13:20+00:00","author":"admin","twitter_card":"summary_large_image","twitter_creator":"@stshostandtech","twitter_site":"@stshostandtech","twitter_misc":{"Written by":"admin","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/hostandtech.com\/kb\/linux\/how-to-install-lamp-stack-ubuntu\/#article","isPartOf":{"@id":"https:\/\/hostandtech.com\/kb\/linux\/how-to-install-lamp-stack-ubuntu\/"},"author":{"name":"admin","@id":"https:\/\/hostandtech.com\/kb\/#\/schema\/person\/b6fa79c48ddaba71af32e395c5b017ee"},"headline":"How to Install a LAMP Stack on Ubuntu 22.04 \/ 24.04","datePublished":"2026-05-26T16:13:20+00:00","mainEntityOfPage":{"@id":"https:\/\/hostandtech.com\/kb\/linux\/how-to-install-lamp-stack-ubuntu\/"},"wordCount":1461,"commentCount":0,"publisher":{"@id":"https:\/\/hostandtech.com\/kb\/#organization"},"keywords":["Apache","LAMP stack","Linux","MySQL","PHP","Ubuntu","VPS"],"articleSection":["Linux Server"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/hostandtech.com\/kb\/linux\/how-to-install-lamp-stack-ubuntu\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/hostandtech.com\/kb\/linux\/how-to-install-lamp-stack-ubuntu\/","url":"https:\/\/hostandtech.com\/kb\/linux\/how-to-install-lamp-stack-ubuntu\/","name":"How to Install a LAMP Stack on Ubuntu 22.04 \/ 24.04","isPartOf":{"@id":"https:\/\/hostandtech.com\/kb\/#website"},"datePublished":"2026-05-26T16:13:20+00:00","description":"Step-by-step LAMP installation guide for Ubuntu 22.04 and 24.04. Install Apache, MySQL, and PHP on your Ubuntu server and host your first site.","breadcrumb":{"@id":"https:\/\/hostandtech.com\/kb\/linux\/how-to-install-lamp-stack-ubuntu\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/hostandtech.com\/kb\/linux\/how-to-install-lamp-stack-ubuntu\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/hostandtech.com\/kb\/linux\/how-to-install-lamp-stack-ubuntu\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/hostandtech.com\/kb\/"},{"@type":"ListItem","position":2,"name":"How to Install a LAMP Stack on Ubuntu 22.04 \/ 24.04"}]},{"@type":"WebSite","@id":"https:\/\/hostandtech.com\/kb\/#website","url":"https:\/\/hostandtech.com\/kb\/","name":"Host And Tech knowledge base","description":"","publisher":{"@id":"https:\/\/hostandtech.com\/kb\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/hostandtech.com\/kb\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/hostandtech.com\/kb\/#organization","name":"Host And Tech knowledge base","url":"https:\/\/hostandtech.com\/kb\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/hostandtech.com\/kb\/#\/schema\/logo\/image\/","url":"https:\/\/hostandtech.com\/kb\/wp-content\/uploads\/2026\/05\/logo-dark.png","contentUrl":"https:\/\/hostandtech.com\/kb\/wp-content\/uploads\/2026\/05\/logo-dark.png","width":1134,"height":395,"caption":"Host And Tech knowledge base"},"image":{"@id":"https:\/\/hostandtech.com\/kb\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/stshostandtech","https:\/\/x.com\/stshostandtech"]},{"@type":"Person","@id":"https:\/\/hostandtech.com\/kb\/#\/schema\/person\/b6fa79c48ddaba71af32e395c5b017ee","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/aa1edac8bbadb442e059a5b65ad45a3b2e3ce689202373b96e3e567517ae4b39?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/aa1edac8bbadb442e059a5b65ad45a3b2e3ce689202373b96e3e567517ae4b39?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/aa1edac8bbadb442e059a5b65ad45a3b2e3ce689202373b96e3e567517ae4b39?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/hostandtech.com\/kb"],"url":"https:\/\/hostandtech.com\/kb\/author\/admin_fjj7qydm\/"}]}},"_links":{"self":[{"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/posts\/115","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/comments?post=115"}],"version-history":[{"count":0,"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/posts\/115\/revisions"}],"wp:attachment":[{"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/media?parent=115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/categories?post=115"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hostandtech.com\/kb\/wp-json\/wp\/v2\/tags?post=115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}