Install Apache on AWS Ubuntu
Install Apache on AWS Ubuntu is so clever, Especially the Free tier users can make their Host easily and do php stuffs working online. Initially I had many issues to create a proper EC2 Instance to install Apache server in it. Later i learned it with Amazon docs to know many things about installing Apache2 on EC instance.
Let’s install apache and configure it working on your EC2 Instance. Before that, the required things are listed here.
- Running EC2 Instance
- Public IP Address
- Private Key
- Putty installed if your Local PC is windows, You can install Putty on your linux as well.
And configured Putty with Public IP and Private Key . Once your Putty is ready to work, Use FTP either FileZilla or WinSCP to connect the IP address and check the installed Ubuntu instance.
Just Run Your Putty and follow the below steps.
Update Existing Packages in AWS Ubuntu
First, we are not sure that the system installed all necessary packages properly, because,its created as an instance. So let’s update its all packages with below command.
sudo apt-get update
And Also we have to update the dist to run all the packages working properly.
sudo apt-get dist-upgrade
Installing Apache on AWS
Now, the Server is ready to roar the Apache and our stuffs. So let’s install apache here first.
sudo apt-get install apache2
After that,it will ask you a prompt saying [Y/N], just Type Y and hit enter key,it will install apache2 successfully. After installing apache2 we need to make sure to run the apache with our mode rewrites. So use the following command to make it rewrite the paths.
sudo a2enmod rewrite
If it produces failure error, try this after installing php. After that, you can check the Server is helping you to access apache. Just goto your browser and type your aws Public IP and hit enter to see the apache initial page.
Installing PHP on Ubuntu
Installing PHP helps to run all your php files inside apache2. So let’s use the below command to install PHP inside Apache2.
sudo apt-get install php libapache2-mod-php
This helps to install PHP inside apache Along with mcrypt.Which is one of the needy extension for many php applications. After installing PHP, our root directory will be like this.
/var/www/html/. But I feel to bring it to
/var/www/ to work all my stuffs. If you are interested to remove the
html from the path, you can do the below step otherwise you can skip it.
Open this path
/etc/apache2/sites-enabled and open the file
000-default.conf on editor to update the below code at the end of the file. If you can’t find such a file, try to find
/etc/apache2/sites-available/ folder and here it might be there for you.
<Directory /var/www/> Options Indexes FollowSymLinks MultiViews # changed from None to FileInfo AllowOverride FileInfo AllowOverride All Order allow,deny allow from all </Directory>
After this your root will be changed to
/var/www/. Now, you have to add user permissions and access permission to work on files and folders. Mostly the directory permissions are 775 and file permissions will be 644 to work all in server well. Let’s add user to the directory
sudo adduser ubuntu www-data
Now, grant the user access permissions to the directory view and edit.
sudo chown -R www-data:www-data /var/www sudo chmod -R g+rw /var/www
After that,you need to restart your apache2 to take effect. Let’s restart it again.
sudo service apache2 restart
Now,create a dummy php file on
/var/www/ and write the below code in it.
<?php phpinfo(); ?>
After that, save and type the file name after the Ip Address to check it on your browser. If you really enjoy this article follow me on below social sites and if you are interested to know and read more articles from me,subscribe my news letter channel to get desired article updates.