Install and configure Apache, Mysql, PhpMyAdmin, FTP, CMS wordpress on Redhat 6.00 amazon EC2


You can take VPS from amazon. If you have credit card you can open an account. Amazon will charge you 1 dollar and give you many feature. You can use amazon EC2 for 1 year. It’s better if you take it from oregon.
I want to say you about how to open a vps on amazon ec2. First go to service- EC2. then instances – Lunch instances.



Red Hat Enterprise Linux 6.5 (PV)- select


Select on Micro instances -



Click on next-configure instance details
No need to change anything on here. If you have knowlegde you can change.



 You can take more storage. But free tier user can use 30 gb.


next – add storage . Then tag instance.
Here you can see security group. Be careful when you are changing anything.
Click create a new security group and write Security group name => “mashpygroup”. Add rule. Now look at the picture and write as like as this.
 To enlarge click on the image,


Click on review and lunch.
Select create new key pair.  key pair name is “newmashpy”. Then download key pair.



Please keep this newmashpy.pem file carefully. It’s very important. If you want to login on your vps using ssh, you need this file.
Now go again ec2 – instances. It will take 5 minutes to configure all things. Amazon will give you public dns and public IP. You can say public dns is our domain name. You can check your site using this name. Now we will login our server using ssh.
You can login ssh using putty software on windows. On ubuntu you get a terminal. Open the terminal. Put the newmashpy.pem file on home folder. If you put this another folder you have to change the directory on Terminal. Now write command – $ sudo chmod 600 newmashpy.pem

$ ssh -i newmashpy.pem ec2-user@54.187.244.182
(54.187.244.182 is your public IP)

You are now logged in on user mood. we will enter the root mode. write command – $ sudo -i
we will install apache and to install package we will install yum.

$ yum install httpd
 $ service httpd start

Check your public dns. Can you see a apache page or not? My public dns is – http://ec2-54-187-244-182.us-west-2.compute.amazonaws.com
I can see apache default page.

To test more you can put index.php file on this directory – /var/www/html and write some php code. Then check the public dns on browser. PHP will execute and you can see the output.

Now we will install php and other library. Before than we will update the package list.

$ wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
$ wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
$ sudo rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm
$ yum update (It will take time, be paitent)
$ yum install php libmcrypt libmcrypt-devel php-mcrypt php-mbstring php5-gd

After installing we will create a test file.

$ cd /var/www/html

$ vim mashpy.php <?php
echo “hello world”;
?>

save it and check on public dns to see “hello world.”

http://ec2-54-187-244-182.us-west-2.compute.amazonaws.com/mashpy.php

Now we will install mysql.

$ yum install mysql mysql-server php-mysql
$ service mysqld start

We will set password for mysql. For this write command –
$ mysql_secure_installation

Terminal will request you to input the root password. As we will set password newly, so no need to write anything, just press the enter button. Then it will say you to input the password. Now input your password. Question will be something like this -

Remove anonymous users? [Y/n] => Y
Disallow root login remotely? [Y/n] => N
Remove test database and access to it? [Y/n] =>Y
Reload privilege tables now? [Y/n] => Y

We will install phpmyadmin. So write command –
$ cd /usr/share
$ wget http://kent.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/4.2.1/phpMyAdmin-4.2.1-all-languages.tar.bz2

We will extract the file and to extract tar.bz2 write command like this –

$ tar -xjvf phpMyAdmin-4.2.1-all-languages.tar.bz2 -C /usr/share

I have renamed the file -
$ mv phpMyAdmin-4.2.1-all-languages phpmyadmin

Removed the downloaded file -
$ rm -rf phpMyAdmin-4.2.1-all-languages.tar.bz2

I have given right permission –
$ cd phpmyadmin
$ chown -R apache:apache .
$ chmod -R 755 .
$ cd /etc/httpd/conf.d
$ vim phpMyAdmin.conf

এই ফাইলে লিখি – <Directory “/usr/share/phpmyadmin”>
Order Deny,Allow
Deny from None
Allow from All
</Directory>
Alias /phpmyadmin /usr/share/phpmyadmin
Alias /phpMyAdmin /usr/share/phpmyadmin

Save it and restart the service –
 $ service httpd restart

we will configure phpmyadmin manually and restart the apache –
$ cd /usr/share/phpmyadmin/
$ mv config.sample.inc.php config.inc.php
$ vi config.inc.php

Write something on blowfish_secret, save it.
cfg[‘blowfish_secret’] = ‘mashpy';

$ rm -rf setup
$ service httpd restart

Now go to the public_dns/phpmyadmin/. In this case we are going to this link – http://ec2-54-187-244-182.us-west-2.compute.amazonaws.com/phpmyadmin
Username is root and password is mysql (which password you have give to configure mysql)

Now we will set the permission. Most of the time we fall problem on wordpress because of permission.

This part is very important.
$ groupadd www
$ usermod -a -G www apache
$ chgrp -R www /var/www/html
$ setfacl -Rdm g:www:rwx /var/www/html
$ setfacl -Rm g:www:rwx /var/www/html

Sometimes we fall problem because of .htaccess. In this case we will do somethng like that –
$ cd /etc/httpd/conf/
$ vim httpd.conf

In this file we have to edit. Scroll down. You can see. Make all none to all.
AllowOverride none
=>
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>

Again you will see same text. make it none to all. Remember you have to do this twince.
$ service httpd restart

As we want to upload the photo it’s important to install the ftp. To support ftp we will use vsftpd package.
$ yum install vsftpd
$ vim /etc/vsftpd/vsftpd.conf

Please edit this file carefully. Please check what i have written.
anonymous_enable=NO ( Make yes to NO.)
chroot_local_user=YES (Remove the #)

Scroll down and add these line -
userlist_file=/etc/vsftpd/vsftpd.userlist
userlist_deny=NO
pasv_enable=YES
pasv_min_port=1024
pasv_max_port=1048
pasv_address=54.187.244.182 (Here you have to put the public IP)

Save the file.
Now we need to create ftp user and give the right access -
sudo useradd -d /var/www/html -s /usr/sbin/nologin mashpy
sudo passwd mashpy

We will create a file. write command=>
$ vim /etc/vsftpd/vsftpd.userlist

Write the ftp user –
mashpy
Save and exit.

$ vim /etc/shells

Add this line on this file-
/usr/sbin/nologin
Save and exit.

Add the mashpy username to www group. Write command-
$ usermod -G www mashpy

give the full access to ftp user -
$ setsebool -P allow_ftpd_full_access 1

restart the apache –
$ service vsftpd restart

we will test it using filezilla –
hostname: Public DNS
username: mashpy
password: what we have input for ftp password

Now I want to say an important topic. If we restart our server, our site will not load again. Cause if we restart, then apache, mysql and ftp service will turn off automatically. To solve this problem we have to set this service will automatically on when we restart our server.
$ ntsysv

You can see graphical mood. * means check mark. So we will set check mark on httpd, mysqld, vsftpd. If we press space it will be selected.
From now if we restart our server again, no service will turned off.
Now we will install wordpress. Write command -

$ cd /var/www/html/
I have downloaded the latest wordpress-

$ wget http://wordpress.org/latest.tar.gz
$ tar -xzvf latest.tar.gz -C /var/www/html
$ cp -avr /var/www/html/wordpress/* /var/www/html
$ rm -rf /var/www/html/wordpress
$ chmod 2775 /var/www/html
$ find /var/www/html -type d -exec sudo chmod 2775 {} +
$ find /var/www/html -type f -exec sudo chmod 0664 {} +

Create database from phpmyadmin. Then check the site using public dns. Hope you can see wordpress site. If you face any problem, please don’t hasitate to comment here. Thanks all.



Comments

Popular Posts

Install and configure Network simulator (ns3) on Ubuntu 14.04