Many thanks to aronwoost for his great EC2 Lamp gist that this is forked from. I've modified parts of it, specifically around phpmyadmin configuration.
This gist additionally covers installing Phusion Passenger, Ruby Gems, all dependencies and the final configuration to get you up and running ASAP.
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
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
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
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
Note: Leaving the default path to phpmyadmin is not generally a good idea. Feel free to change this to whatever you like to help thwart script kiddies looking for vulnerabilities, and I recommend you disable this completely in a production environment just to be on the safe side.
Alias /happily_hidden_phpmyadmin /usr/share/phpmyadmin #Alias /phpmyadmin /usr/share/phpmyadmin #Alias /phpMyAdmin /usr/share/phpmyadmin #Alias /mysqladmin /usr/share/phpmyadmin
#Alias /phpmyadmin /usr/share/phpmyadmin #Alias /phpMyAdmin /usr/share/phpmyadmin #Alias /mysqladmin /usr/share/phpmyadmin
I've commented them out for visual effect, you could just delete them completely but useful to leave one in place for easy switching later if you need access.
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
AllowOverride none with
(optional if apache is running already, restart it)
sudo service httpd restart
sudo /etc/rc.d/init.d/httpd start
##Install many dependencies
cd ~ sudo yum install ruby-devel sudo yum install mysql-devel sudo yum install sqlite-devel //You might not need this but I installed as part of my process sudo yum install make sudo yum install gcc46 sudo yum install curl-devel sudo yum install openssl-devel sudo yum install httpd-devel sudo yum install gcc-c++
If you get an error like:
* Zlib development headers... not found
Make sure gcc-c++ installed correctly.
##Install Ruby Gems
sudo yum install rubygems
If this fails, do this:
wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.24.tgz tar xvzf rubygems-1.8.24.tgz sudo ruby rubygems-1.8.24/setup.rb
##Install Passenger and Apache module
sudo gem install passenger sudo passenger-install-apache2-module
Follow the on screen instructions to configure Apache, but it goes a little something like this. Open up httpd.conf for editing:
sudo nano /etc/httpd/conf/httpd.conf
And add the following lines to the end of file:
LoadModule passenger_module /usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/ext/apache2/mod_passenger.so PassengerRoot /usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17 PassengerRuby /usr/bin/ruby
Find the following separate lines in your conf:
... DocumentRoot "/var/www/html" ... <Directory "/var/www/html"> ... Options Indexes FollowSymLinks ...
And amend respectively:
... DocumentRoot "/var/www/html/public" ... <Directory "/var/www/html/public"> ... Options -Indexes FollowSymLinks -MultiViews ...
Note: I've disabled indexes for security reasons and because it's good practice. You can enable / disable them as you wish; it won't impact Passenger.
##Create your public directory and reload httpd
sudo mkdir /var/www/html/public sudo /etc/rc.d/init.d/httpd restart
Finished. Happy coding.
If you're new to Ruby, I can't recommend Sinatra enough as an easy to use framework.