Again -y says, ‘yes please install all packages without prompting me.’ Yum will run the install for all the dependencies for a web server (Apache) MySQL and PHP which is nice and convenient.

Once Yum has finished doing its thing, we want to install the php-mysql package which doesn’t come as part of the group install.

{% highlight bash %}
sudo yum install -y php-mysql
{% endhighlight %}

Once that’s all done, we can start our newly installed Apache install

{% highlight bash %}
sudo service httpd start
{% endhighlight %}

We should then get confirmation that Apache has started, however, starting Apache manually means that each time the server restarts, we’d have to log in and start Apache ourselves. A better option is to have the server start Apache itself using the config parameters.

To have Apache start on boot, run:

{% highlight bash %}
sudo chkconfig httpd on
{% endhighlight %}

Once Apache’s running you can check everything’s okay by putting your Amazon Public DNS path into a browser, you should see an Amazon Apache test page (providing you’ve not yet put anything in /var/www/html).

Now we’re up and running with Apache, it’s probably best to give some permissions to our ec2-user so that we can copy files into the /var/www directory without any permissions issues.

If you run the following:

{% highlight bash %}
ls -l /var/www
{% endhighlight %}

You’ll see that the root user owns the web root directory. Not ideal as you’d have to have root/su permissions to manipulate files in there which will prevent things like FTP/SFTP transfers.

Now we’re all set up to put some files into the web root directory with the correct permissions, to check every things okay we can put in a quick PHP info file that’ll give us the usual PHP install information. We’ll quickly create a file, drop in the phpinfo statement and go and view the file on the server to check apache and php are both installed and running correctly.

In the same way we set Apache to start on system boot, we can set MySQL to do the same thing, this is good for things like CMS installs that rely on the database to be available (Drupal / WordPress etc).

{% highlight bash %}
sudo chkconfig mysqld on
{% endhighlight %}

That’s everything installed. Apache web server is running with the web root as /var/www/html so you can pop your website file in that directory and MySQL is running so you can install your database too.