Install Adminer on EC2

User
How to add adminer in amazon ubuntun ec2
Assistant
To add **Adminer** (a lightweight and powerful database management tool) to an **Amazon EC2** instance running **Ubuntu**, follow these steps:

### Step 1: Connect to Your EC2 Instance
1. Open your terminal (or use an SSH client like PuTTY if you're on Windows).
2. Connect to your EC2 instance using SSH:

ssh -i /path/to/your-key.pem ubuntu@your-ec2-public-ip

### Step 2: Update and Upgrade Packages
Once you're connected to your EC2 instance, it's a good practice to update the package lists:

sudo apt update && sudo apt upgrade -y

### Step 3: Install Apache Web Server
If you haven't installed Apache yet, run:

sudo apt install apache2 -y

– **Start** and **enable** Apache to run on boot:

sudo systemctl start apache2
  sudo systemctl enable apache2

### Step 4: Install PHP
Adminer requires PHP. Install PHP and some common extensions:

sudo apt install php php-mysql php-curl php-json php-cgi -y

### Step 5: Download Adminer
Adminer is just a single PHP file. You can download it to the web server's root directory:

sudo mkdir -p /var/www/html/adminer
cd /var/www/html/adminer
sudo wget https://www.adminer.org/latest.php -O index.php

### Step 6: Adjust Permissions
Make sure Apache has permission to access the Adminer files:

sudo chown -R www-data:www-data /var/www/html/adminer
sudo chmod -R 755 /var/www/html/adminer

### Step 7: Configure Apache (Optional)
You can create a virtual host configuration for Adminer (optional but recommended for better organization):

sudo nano /etc/apache2/sites-available/adminer.conf

Add the following configuration:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/adminer
    ServerName your-ec2-public-ip

    <Directory /var/www/html/adminer>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/adminer_error.log
    CustomLog ${APACHE_LOG_DIR}/adminer_access.log combined
</VirtualHost>

– **Enable the site** and **restart Apache**:

sudo a2ensite adminer.conf
  sudo systemctl reload apache2

### Step 8: Allow HTTP Traffic in Security Group
Ensure your **EC2 Security Group** allows incoming traffic on port **80** (HTTP):
1. Go to the **AWS Management Console**.
2. Navigate to **EC2 > Security Groups**.
3. Find the security group attached to your EC2 instance.
4. Edit **Inbound Rules** to add:
– **Type**: HTTP
– **Protocol**: TCP
– **Port Range**: 80
– **Source**: Anywhere (0.0.0.0/0) or your IP (for restricted access).

### Step 9: Access Adminer in Your Browser
Now, open your browser and go to:

http://your-ec2-public-ip/adminer

You should see the **Adminer** login page where you can connect to your database.

### Step 10: Secure Adminer (Optional)
For security, you might want to password-protect the Adminer directory or limit access to certain IPs:
1. **Password Protect Adminer**:

sudo apt install apache2-utils -y
   sudo htpasswd -c /etc/apache2/.htpasswd yourusername

Edit your Apache config to include:

<Directory /var/www/html/adminer>
       AuthType Basic
       AuthName "Restricted Access"
       AuthUserFile /etc/apache2/.htpasswd
       Require valid-user
   </Directory>

Reload Apache:

sudo systemctl reload apache2

2. **Limit Access by IP**:

<Directory /var/www/html/adminer>
       Require ip your.ip.address
   </Directory>

That's it! You've successfully installed Adminer on your Ubuntu EC2 instance.

Leave a Comment

Your email address will not be published. Required fields are marked *