Installing PHP and Mysql Database on Amazon EC2 Cloud Server

Installing PHP and Mysql from Linux command line

Here are the command line commands to get PHP and Mysql onto a Linux server without any software installed yet but basics. I did this on an Amazon Linux AMI:

TIP: Commands are in purple

sudo yum install php-mysql php php-xml php-mcrypt php-mbstring php-cli mysql httpd

sudo yum install mysql-server

sudo /etc/init.d/mysqld start

mysqladmin command to change root password:
mysqladmin -u root password admin

mysql -u root -p

type in password of “admin”



CREATE USER ‘MYSQL_admin’@’localhost’ IDENTIFIED BY ‘mypass’;


CREATE USER ‘MYSQL_user’@’localhost’ IDENTIFIED BY ‘mypass’;


sudo chown ec2-user /var/www/html

sudo vim /var/www/html/index.php

Now you should have a server set up with mysql

Test by opening VI editor and making a test index.html or .php page here is how to open vi and start a new file:

sudo chown e2c-user /var/www/html

sudo vim /var/www/html/index.php

press i and insert some test text then hit esc and type :wq to save the file.

Now start the httpd server using the following command in Putty:
sudo service httpd start

if you got a green “ok” then you are good, if not go over the last several steps and find out what you did wrong.

Go to your Amazon admin console and click on instances to view your instances. Put a check next to the one you just made and copy the url that looks like this:
you can shorten the url by just using the ip that starts after the ec2- and ends at the first period. Just replace the dashes with periods like this:
That is the short URL or IP you can use to access your web server. Type or copy and paste that into your web browser’s address bar and see if you can see your test text you entered with the VI editor a moment ago. If so, you are doing great.

Install phpmyadmin

Next, you can follow the below instructions if you want to install the popular phpmyadmin databaes GUI:

From the server command prompt, type:

cd /var/www/html

tar -jxf phpMyAdmin-3.4.1-all-languages.tar.bz2 -C /var/www/html

mv phpMyAdmin-3.4.1-all-languages phpmyadmin

cd /var/www/html/phpmyadmin

mkdir config

cp /var/www/html/phpmyadmin/ /var/www/html/phpmyadmin/config/

sudo vim /var/www/html/phpmyadmin/config/

change  blowfish_secret to any other word and change allownopassword to true

go to: your server’s URL that looks something like
and enter user of root and the root password or one of the other users and passwords you created in this exercise. If you get the phpmyadmin interface, you did good.



2 Replies to “Installing PHP and Mysql Database on Amazon EC2 Cloud Server”

  1. Usually I do not read article on blogs, but I would like to say that this write-up very pressured me to check out and do so! Your writing taste has been amazed me. Thank you, quite nice article.

Leave a Reply

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