The following commands require super user access. If you're not currently logged in as root, you may need to run the following command:
$ sudo su
Installing Apache 2
Once you have sudo access, install the Apache Web Server:
# yum -y install httpd
Once apache is installed, you'll have to manually start the service:
# service httpd start
To ensure that Apache is started automatically when your server reboots, run the following command:
# chkconfig httpd on
Once Apache is started, check that it's running properly by navigating to the default web page included with the Apache install.
If you don't know your public IP address, find it first. The following command will show your public IP address:
# wget http://ipecho.net/plain -O - -q; echo
Note: You must have wget installed for this command to work. If you get an error about the wget command not being recognized, you can install wget with the following command:
# yum -y install wget
Once you have your public ip address, go to your internet browser and visit http://123.45.67.8/ (of course you'll substitute 123.45.67.8 for the actual IP address returned by the previous command). This website should show you the Apache 2 Test Page. Once you see this test page, your Apache installation is completed, and you can move the the next step of installing MySQL.
Installing MySQL
# yum -y install mysql-server
Once MySQL has been installed, start the service:
# service mysqld start
To ensure that MySQL is started automatically when your server reboots, run the following command:
# chkconfig mysqld on
Once the MySQL service starts, setup MySQL security:
# /usr/bin/mysql_secure_installation
You'll be prompted for the current MySQL root password. Since the MySQL root password is not yet set, just press the enter key (denoted below as [enter]).
# [enter]
You'll be asked "Set root passoword?".
# y [enter]
You'll be asked "New password" twice. Type a password that you want to be used for the MySQL root user, and press enter, then retype the same password, and press enter.
You'll be asked "Remove anonymous users?":
# y [enter]
You'll be asked "Disallow root login remotely?":
# y [enter]
You'll be asked "Remove test database and access to it?":
# y [enter]
You'll be asked "Reload privilege tables now?":
# y [enter]
At this point, the MySQL installation is complete, and you can move on to install php
Installing PHP
# yum -y install php php-mysql
Once the php installation is complete, restart the Apache service to ensure that all changes take effect:
# service httpd restart
Now that php is installed, test that it's working properly:
Install the nano text editor:
# yum -y install nano
Naviate to the default Apache web directory:
# cd /var/www/html
Create a new page called test.php:
# nano test.php
This will create a new file called test.php (assuming one doesn't already exist), and allow you to edit the file. Type the following text:
<?php phpinfo(); ?>
To write this text to the test.php file, hold the Ctrl key and then press the O key. Then press the Enter key.
To exit nano, hold the Ctrl key and press the X key.
To test the new php page, pull up the page in your Internet browser: http://123.45.67.8/test.php (Of course you'll substitute 123.45.67.8 for the actual public ip address found in the first step (Installing Apache)).
You should see the php page, which shows the version of PHP installed, as well as all the configuration details.
This completes the process of installing the LAMP stack. You can now add web pages to the apache directory at /var/www/html/