July 16, 2019 / Nirav Shah
<strong>EXTRACT</strong> We are going to share the steps to be performed to sort of compile and Install MySQL, PHP and Apache Web Server on Ubuntu Linux individually instead of using pre-set LAMP stacks.
<strong>In the Instance</strong>
<strong>Step 1:</strong>
We will gain ssh access into the Instance and start configuring the Instance for Installation. We are going to ssh into the Instance through command-line.
<strong>$</strong> ssh -i private-key.pem ubuntu@ (ip-address)
And we are able to connect to the Instance.
Now, the first thing we need to do is update the packages installed on the Instance as well as install some basic packages as per the requirements. First, we will update and clean the system by entering :-
<strong>$</strong> sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y && sudo apt autoclean
<img class=”alignnone wp-image-4668 size-full” src=”https://www.eternalsoftsolutions.com/blog/wp-content/uploads/2019/07/bh_Screenshot-2.png” alt=”” width=”1354″ height=”739″ />
<strong>Step 2:</strong>
Now, we will setup a lamp environment by manually installing all the required components 1 by 1 instead of installing the lamp stack packages as a whole. We will do this to be able to update the latest stable versions of different packages instead of feeling limited by the versions provided by lamp stack packages. This will also result in it becoming easier to update your lamp environment in the future instead of waiting for the lamp stack package maintainers to compile and provide the updated versions.
<strong>Step 3:</strong>
We will start by installing apache web server at first :-
<strong>$</strong> sudo apt-get install apache2
And press enter and then press “y”
<img class=”alignnone wp-image-4672 size-full” src=”https://www.eternalsoftsolutions.com/blog/wp-content/uploads/2019/07/bk_Screenshot-1.png” alt=”” width=”1353″ height=”739″ />
Now, apache has been installed.
<strong>Step 4:</strong>
Now, we will install php and its dependency packages :-
At the time of writing, php-7.3 is the latest and stable version and so it will be installed.
<strong>$</strong> sudo apt-get install software-properties-common
<strong>$</strong> sudo add-apt-repository ppa:ondrej/php
<img class=”alignnone wp-image-4678 size-full” src=”https://www.eternalsoftsolutions.com/blog/wp-content/uploads/2019/07/bm_Screenshot-2.png” alt=”” width=”1908″ height=”826″ />
<strong>$</strong> sudo apt-get update
<img class=”alignnone wp-image-4680 size-full” src=”https://www.eternalsoftsolutions.com/blog/wp-content/uploads/2019/07/11-blg.png” alt=”” width=”813″ height=”161″ />
<strong>$</strong> sudo apt-get install php7.3 libapache2-mod-php7.3 php7.3-cli php7.3-mysql php7.3-gd php7.3-imagick php7.3-recode php7.3-tidy php7.3-xmlrpc php7.3-common php7.3-curl php7.3-mbstring php7.3-xml php7.3-bcmath php7.3-bz2 php7.3-intl php7.3-json php7.3-readline php7.3-zip
<img class=”alignnone wp-image-4693 size-full” src=”https://www.eternalsoftsolutions.com/blog/wp-content/uploads/2019/07/22.png” alt=”” width=”1910″ height=”384″ />
Now, php has been installed with its dependencies.
We will need to restart apache service for this multiple packages to reflect in the server.
<strong>$</strong> sudo systemctl restart apache2
<strong>Step 5:</strong>
Now, we will install and setup mysql server on the instance to handle backend database requests that will be sent to the server.
MySQL is a database management system. Basically, it will organize and provide access to databases where our site can store information.
<strong>$</strong> sudo apt-get install mysql-server
<img class=”alignnone wp-image-4689 size-full” src=”https://www.eternalsoftsolutions.com/blog/wp-content/uploads/2019/07/66-blg.png” alt=”” width=”1906″ height=”1048″ />
When the installation is complete, we want to run a simple security script that will remove some dangerous defaults and lock down access to our database system a little bit. Start the interactive script by running:
<strong>$</strong> mysql_secure_instrallation
You will be asked if you want to configure the <strong>VALIDATE PASSWORD PLUGIN</strong>. Answer <strong>y</strong> for yes;
We will choose <strong>1</strong> to strike a balance between security and complexity.
Type in your random password which should contain; numeric, mixed case, and special characters
<img class=”alignnone wp-image-4684 size-full” src=”https://www.eternalsoftsolutions.com/blog/wp-content/uploads/2019/07/111.png” alt=”” width=”910″ height=”431″ />
For the rest of the questions, you should press <strong>Y</strong> and hit the <strong>Enter</strong> key at each prompt. This will remove some anonymous users and the test databases, disable remote root logins, and load these new rules so that MySQL immediately respects the changes we have made.
<img class=”alignnone wp-image-4682 size-full” src=”https://www.eternalsoftsolutions.com/blog/wp-content/uploads/2019/07/1333.png” alt=”” width=”1909″ height=”709″ />
At this point, your database system is now setup.
We need to flush the privileges so that the current instance of MySQL knows about the recent changes we’ve made:
<strong>mysql></strong> FLUSH PRIVILEGES;
<strong>mysql></strong> EXIT;
<img class=”alignnone wp-image-4681 size-full” src=”https://www.eternalsoftsolutions.com/blog/wp-content/uploads/2019/07/1444.png” alt=”” width=”934″ height=”467″ />
Your base setup with Linux, Apache, MySQL, PHP is now ready.
<style type=”text/css”>
<p> ul.listing li {<br /> list-style-type: disc !important;<br /> }<br /> ul.listing-new li {<br /> list-style-type: disc !important;<br /> }<br /> .blog-portion-one ul li.list-none {<br /> list-style-type: none !important;<br /> list-style: none !important;<br /> }<br />.bulletremoved {<br /> list-style-type: none !important;<br />}<br />ul.listing li {<br /> list-style-type: disc !important;<br />}<br />.listing img {<br />width:100%;<br />}<br />ul.awsul li {<br />list-style-type: square !important;<br />}<br />ul.subul li {<br />list-style-type: disc !important;<br />}<br /></style>
<strong>Also Read: <a style=”color: #0b5f9e;” href=”https://www.eternalsoftsolutions.com/blog/run-command-remotely-on-ec2-instance/ ” target=”_blank” rel=”noopener”> <span style=”font-weight: 400;”>Run Command Remotely on EC2 instance</span></a></strong>

Nirav Shah is the Director of Eternal Web Pvt Ltd, an AWS Advanced Consulting Partner and certified Odoo Partner based in the UK. With over a decade of experience in cloud computing, digital transformation, and ERP implementation, Nirav helps enterprises adopt the right technology to solve complex business challenges. He specialises in AWS infrastructure, Odoo ERP, and web development solutions for businesses across the UK and beyond.
Have queries about your project idea or concept? Please drop in your project details to discuss with our AWS Global Cloud Infrastructure service specialists and consultants.