Skip to content

Instantly share code, notes, and snippets.

@aronwoost
Created July 25, 2011 19:46
Show Gist options
  • Save aronwoost/1105007 to your computer and use it in GitHub Desktop.
Save aronwoost/1105007 to your computer and use it in GitHub Desktop.
How to install LAMP on a EC2 Amazon AMI

Launch the instance and connect with ssh.

##Update the server

sudo yum update

##Install php and MySQL packages

sudo yum install https mod_ssl mysql mysql-server php php-mysql php-xml

##Install phpMyAdmin

Get the RPMforge repo (32-bit, for 64-bit use http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm)

wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
sudo rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.i386.rpm

Install

sudo yum install phpmyadmin

##Start MySQL service

cd /etc/rc.d/init.d/
sudo ./mysqld start
sudo /usr/bin/mysql_secure_installation //follow instructions

##Setup startup scripts for apache and MySQL

cd /etc/rc.d/rc3.d
sudo rm K15httpd
sudo rm K36mysqld
sudo ln -s ../init.d/mysqld S30mysql
sudo ln -s ../init.d/httpd S85httpd

##Setup phpMyAdmin

Allow access from external IP's

sudo chmod 0700 /etc/httpd/conf.d/phpmyadmin.conf
sudo nano /etc/httpd/conf.d/phpmyadmin.conf
#  Web application to manage MySQL
#  #
#  Order Deny,Allow
#  Deny from all
  Allow from 127.0.0.1
#
Alias /phpmyadmin /usr/share/phpmyadmin
Alias /phpMyAdmin /usr/share/phpmyadmin
Alias /mysqladmin /usr/share/phpmyadmin

Set blowfish_secret to make it work with cookie auth

sudo chmod 0700 /usr/share/phpmyadmin/config.inc.php
sudo nano /usr/share/phpmyadmin/config.inc.php 
...
$cfg['blowfish_secret'] = 'put-a-magic-string-here'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
...
sudo chmod 0755 /usr/share/phpmyadmin/config.inc.php

##Make mod_rewrite (.htaccess) work in subdirectories

cd /etc/httpd/conf
sudo nano httpd.conf

Find <Directory "/var/www/html"> Replace AllowOverride none with AllowOverride all

(optional if apache is running already, restart it)

sudo service httpd restart

##Start apache

sudo /etc/rc.d/init.d/httpd start

##Sources

@christianramsey
Copy link

Fixed, I also updated to httpd24 so one of it's defaults is:

AllowOverride none
Require all denied

which is applied to phpmyadmin, so what you have to do is add to phpmyadmin.conf in the Directory tags as so:

Options All
AllowOverride All
Require all granted

@nikitabe
Copy link

OMG. Dude, I totally <3 you. Extremely helpful. Thank you!

@jeromev
Copy link

jeromev commented Jun 5, 2013

Thank you.

@paptom
Copy link

paptom commented Jun 9, 2013

Great work! Thank you!

@ernestbofill
Copy link

Works fine, Thanks!
btwen, using this do we get updated packages?

@tommymarshall
Copy link

I'm getting a request timeout error when trying to visit my public DNS? I associated an IP and visited that, but same result.

@JEAxero
Copy link

JEAxero commented Jul 3, 2013

Great work! Thanks for making this available. For others like me who went through the setup too quickly to be paying attention the first time, I'll leave 2 notes here: (1) when this is done, you can access the phpmyadmin page at http:///myphpadmin and (2) the login information is the login information you created for mySQL in the mysql_secure_installation step (that is: root and whatever you set up the root password to be).

Perhaps these are dumb newbie observations but when I got to the end, I did have to stop and think about what to do to see if it worked.... Thanks again!

@stormy4000
Copy link

I'm stuck on the Forbidden page to the PHP Myadmin. I've been through the whole process twice, with fresh instances installed on EC2 with apache installed. Security settings are correct... I've been through the whole httpd.conf file and changed any 'Allowoveride none' to 'Allowoveride all'.

The only step I'm unsure of is what to do here:

Allow access from external IP's

sudo chmod 0700 /etc/httpd/conf.d/phpmyadmin.conf
sudo nano /etc/httpd/conf.d/phpmyadmin.conf

Web application to manage MySQL

Order Deny,Allow

Deny from all

Allow from 127.0.0.1

Alias /phpmyadmin /usr/share/phpmyadmin
Alias /phpMyAdmin /usr/share/phpmyadmin
Alias /mysqladmin /usr/share/phpmyadmin

...
I can open up the phpmyadmin.conf file and it looks the same as shown here already. so I'm not sure what to change??

.... the steps after with the blowfish secret seem fine.

and the steps with the httpd.conf seem fine.

I've tried clearing my cache, restarting appache (a thousand times) and restarted my instance... kinda completely stuck after hours of trying to get access to the phpmyadmin page... but its still forbidden .. any help would be much appreciated.

@maragh
Copy link

maragh commented Feb 7, 2014

thanks very much!

@stagleton
Copy link

Will this section allow users to browse all directories?: Find <Directory "/var/www/html"> Replace AllowOverride none with AllowOverride all

I am able to get to my subdirectories by ec2urletc.com/php

I also changed the permissions on the directory and subdirectories (http://stackoverflow.com/questions/11268486/aws-ec2-ftp-html), so maybe this caused the problem as well.

@thewinterwind
Copy link

Instead of using PHPmyadmin you guys can SequelPro or other software that SSH into your server and authenticates with your ssh keys instead of using a password. That will be more secure because there's no phpmyadmin entry point which can be brute forced into.

@myzhou
Copy link

myzhou commented Jun 13, 2014

I am totally agree with "AnthonyVipond", never use "PHPmyadmin" on your live server. If you don't believe, check your server access log to see how many people are trying to scan or brute force your install. Our company use this LAMP stack AMI with everything pre-installed, configured and secured, and it only take us less than two hours to get everything running on EC2. https://aws.amazon.com/marketplace/pp/B00KSGVT9C

@gldixon
Copy link

gldixon commented Feb 22, 2015

Yep followed this but like others I also got

Forbidden
You don't have permission to access /phpmyadmin on this server.

I'm trying to migrate a site here so I need a way to import database tables in here. phpmyadmin is the logical way to do this. I'm completely stuck. Please anyone can help why? What can I do to get it working?

@kendantinio
Copy link

when i run sudo service httpd restart

[root@ip-address conf]# sudo service httpd restart
Stopping httpd: [FAILED]
Starting httpd: [Sun May 24 11:38:23.414527 2015] [alias:warn] [pid 3332] AH00671: The Alias directive in /etc/httpd/conf.d/phpmyadmin.conf at line 11 will probably never match because it overlaps an earlier Alias.
[Sun May 24 11:38:23.414611 2015] [alias:warn] [pid 3332] AH00671: The Alias directive in /etc/httpd/conf.d/phpmyadmin.conf at line 12 will probably never match because it overlaps an earlier Alias.
[ OK ]

is this ok? Stopping httpd: [FAILED]

when i access http://54.152.126.19/phpmyadmin
its says:
Forbidden

You don't have permission to access /phpmyadmin on this server.

@rbtmarshall
Copy link

This was a top result when searching for a way to set up phpMyAdmin on amazon EC2.

Thanks. but...

I guess this distro has not been updated in awhile
once I got it working after about 4 hours of looking for workarounds with errors, etc.. and reading through them to try and understand what the issue was, I finally got it working, buit its an old version, and doing sudo yum update shows no newer version from this repository.

"Version information: 4.0.10.10, latest stable version: 4.4.9"

Now I need to figure out how to upgrade, and not lose the settings, since it seems to be working. I just dont want to have an older version that may have vulnerabilities.

@atorresbr
Copy link

Por favor, este tutorial para instalar phpmyadmin não funciona mais com AMI Linux 2015

Please, this tutorial to install phpmyadmin no longer works with Linux AMI 2015

Here the updated tutorial:

1 - Enter in the folder
cd /var/www/html

2 - Download the updated phpMyAdmin
wget https://files.phpmyadmin.net/phpMyAdmin/4.4.13.1/phpMyAdmin-4.4.13.1-all-languages.tar.bz2

3 - Unzip
tar -jxf phpMyAdmin-4.4.13.1-all-languages.tar.bz2 -C /var/www/html

4- Rename the directory by typing:
mv phpMyAdmin-4.4.13.1-all-languages.tar.bz2 phpmyadmin

5 Make a config directory in the phpmyadmin main folder:
cd /var/www/html/phpmyadmin

mv config.sample.inc.php config.inc.php

sudo nano config.inc.php /* find the code below and past you key - ache o código abaixo e cole sua key */

/*

Exit and save.

Thats it.

http://jafty.com/blog/tag/install-phpmyadmin/

@azazqadir
Copy link

You could also use some managed PHP MySQL hosting platform that lets you host lamp stack on aws ec2 in one click. This will save you a lot of time that could have gone into setting up a server and then managing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment