# Step-by-Step LAMP Stack Installation on Ubuntu

Follow these steps to set up a LAMP (Linux, Apache, MySQL, PHP) stack on your Ubuntu server. Copy commands directly and get started quickly! 😎

---

### **🛠️ Step 1: Update and Upgrade System**

```bash
sudo apt update && sudo apt upgrade -y
```

📌 **What to Do**: Keep your system up to date with this single command.

---

### **🌐 Step 2: Install Apache**

```bash
sudo apt install apache2 -y
```

📌 **What to Do**: Install Apache, the web server.

* **Check Apache Status**:
    

```bash
sudo systemctl status apache2
```

* **Test Apache**:  
    Open your browser and navigate to `http://your-server-ip` to see the Apache default page.
    

---

### **🐬 Step 3: Install MySQL**

```bash
sudo apt install mysql-server -y
```

📌 **What to Do**: Install MySQL for database management.

* **Secure MySQL**:
    

```bash
sudo mysql_secure_installation
```

👉 **Detailed Guide**: [MySQL Secure Installation](https://gist.github.com/Rishiyaduwanshi/06c3594322bd50678b0447d78c86ff67)


* **Login to MySQL**:
    

```bash
sudo mysql
```

---

### **💻 Step 4: Install PHP**

```bash
sudo apt install php libapache2-mod-php php-mysql -y
```

📌 **What to Do**: Install PHP and its modules.

* **Test PHP**:
    
    * Create a test file:
        
        ```bash
        sudo nano /var/www/html/info.php
        ```
        
    * Add the following code:
        
        ```php
        <?php
        phpinfo();
        ?>
        ```
        
    * Visit `http://your-server-ip/info.php` in your browser to confirm PHP installation.
        

---

### **🛡️ Step 5: Adjust Firewall (Optional)**

```bash
sudo ufw allow in "Apache Full"
```

📌 **What to Do**: Allow Apache through the firewall for proper access.

---

### **🔄 Step 6: Enable Modules and Restart Apache**

```bash
sudo a2enmod rewrite  
sudo systemctl restart apache2
```

📌 **What to Do**: Enable Apache modules for better functionality.

---

### **✅ Step 7: Verify Installation**

* **Apache**: Navigate to `http://your-server-ip` in your browser.
    
* **PHP Info**: Navigate to `http://your-server-ip/info.php` in your browser.
    

---

### **📊 Optional: Install phpMyAdmin**

```bash
sudo apt install phpmyadmin -y
```

📌 **What to Do**: Install phpMyAdmin to manage MySQL databases via a web interface.

* **Configure**: Follow the installation prompts and integrate it with Apache.
    
* **Access**: Visit `http://your-server-ip/phpmyadmin` in your browser.
    

---

### **🎉 Congratulations! Your LAMP stack is ready to use.**
