AWS Documentation

⌘K
  1. Home
  2. Docs
  3. AWS Documentation
  4. AWS LAMP and phpMyAdmin server with PHP 8.2 on Linux 2 Kernel 5

AWS LAMP and phpMyAdmin server with PHP 8.2 on Linux 2 Kernel 5

This AMI is a LAMP Web Server with phpMyAdmin installed on Amazon Linux 2 Kernel 5.

This AMI supports following versions.

  • PHP 8.2
  • Apache 2.4
  • MariaDB 10.5
  • phpMyAdmin 5.2

Web Server

We prepared SSL/TLS so you can access to top page using http:// or https://.

DB Server Password

You can find the password from EC2 management console System Log.

  1. Go to Amazon EC2 console at https://console.aws.amazon.com/ec2/.
  2. Chose your Instance and Click Actions → Instance Settings → Get System log

Get System log

You can also SSH into your instance and find the login credential using the following command.

$ cat /home/ec2-user/credentials 
////////////////////credentials info////////////////////
--- phpMyAdmin
----- Setting  : Success
--- MariaDB
----- User     : root
----- Password : ****************
////////////////////////////////////////////////////////

phpMyAdmin

You can access to phpMyAdmin after creating ssh tunnel.

How to Set up SSH Tunneling (Port Forwarding)

ex.) create ssh tunnel

$ ssh ubuntu@{ipaddress} -i {ssh-key-file.pem} -N -L 8080:localhost:80

http://localhost:8080/phpMyAdmin

For phpMyAdmin please refer to phpMyAdmin User Guide

Troubleshoot

Issue: Turned on http redirect to https results in forbidden access to phpmyadmin/mysql via 8080 ssh tunnel.

If It enabled a global redirect from HTTP to HTTPS, it might be affecting the localhost tunnel like this picture.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
❯ curl -I http://localhost:8080/phpmyadmin/
HTTP/1.1 301 Moved Permanently
Date: Mon, 17 Mar 2025 21:02:40 GMT
Server: Apache/2.4.62 () OpenSSL/1.0.2k-fips
Location: https://localhost:8080/phpmyadmin/
Content-Type: text/html; charset=iso-8859-1

So let’s change redirect setting,

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This setting has no effect on local access.

❯ curl -I http://localhost:8080/phpmyadmin/
HTTP/1.1 200 OK
Date: Mon, 17 Mar 2025 21:08:24 GMT
Server: Apache/2.4.62 () OpenSSL/1.0.2k-fips
X-Powered-By: PHP/8.2.27

If you have added a configuration that redirects all HTTP requests to HTTPS, your SSH tunnel access via localhost:8080 might also be affected.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Try modifying the configuration to exclude localhost (127.0.0.1) from the redirect:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Apache reload after modifying,

$ sudo systemctl reload httpd

This should prevent the redirect from affecting your SSH tunnel access to localhost:8080.

Reference

Tags ,

How can we help?