How to Install Apache/PHP on an AWS Instance

OK, this is pretty easy. Once you have your Amazon Linux AMI based Instance and you’ve SSHed to the box:

# install php, mysql connectivity and apache
yum -y install php php-mysql httpd
# start apache
service httpd start
# set apache to start on boot
chkconfig --levels 235 httpd on

You’ll need to open up port 80 inbound in your AWS Security Group. Then point your browser to the Public IP of the instance and you will see the Apache ‘It Works’ page.

Some useful commands:

# not most of these commands have to be run as root
# don't listen to the 'sudo su' naysayers, it's hip to be root!

# show the latest errors
tail /var/log/httpd/error_log

# show the latest accesses
tail /var/log/httpd/access_log

# move to the webroot
cd /var/www/html

# edit the httpd.conf config file
vi /etc/httpd/conf/httpd.conf

# edit the php.ini config file
vi /etc/php.ini

# restart apache (after any config changes or yum updates)
service httpd restart

# if you're not using monit (which you should be)
# this sets apache to autostart on boot
chkconfig --levels 235 httpd on

Leave a Reply

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