
OK, As we now know how to connect to amazon EC2 instance remotely, it’s time for us to go ahead one step ahead to install LAMP stack on Ubuntu EC2 server instance. We will install Apache, PHP and MySQL separately and will bind them together and get working by ourselves. Those who need help installing LAMP Stack on CentOS 7 may use the guide found on this page https://www.linode.com/docs/guides/how-to-install-a-lamp-stack-on-centos-7/.
I will like to make it clear to my beloved readers that, though this tutorial is being released as a part of the amazon web service tutorials series, you can use instructions of this tutorial on other VPS and dedicated Ubuntu server as well, without changing anything.
Why Not Use LAMP-Server Package?
Well, yes, there is a bundle package also available for ubuntu. It is possible to get it installed and working as well. However, personally I don’t prefer this because of the following reasons:
- Less possibility to upgrade: php mysql and apache updates are released from their vendor frequently. If we use the bundle package, we will have to wait when a ubuntu bundle package update for lamp server is ready and then can update it. Rather installing them separately gives us room to get more frequent updates for latest versions for each of them.
- I don’t want mysql installation: If you are using a separate database server, most likely you won’t need mysql instance installed on this same server at all. So, separate installation gives us such flexibility, otherwise we will be using some extra space/memory for an unnecessary mysql instance.
- Learn a bit in-depth: Well, I do think that, it’s better to know it a little more in-depth. Because of that will greatly help with troubleshooting your application errors like compatibility issues and so on.
Installing Apache – First Step To LAMP Stack On Ubuntu :
We should start with installing Apache on our Ubuntu EC2 instance first. Because this is the main core module. To install a software package on Linux system, you do required to have root permission, but it’s not mandatory to login as root, at all. using ‘sudo’ is enough (if you don’t know, adding ‘sudo’ before any command gives the power to run the command under root user privilege). By default the user ‘ubuntu’ already has this permission and we can start without doing anything extra. Just connect to your instance and run the following command:
sudo apt-get install apache2You should see the installation process running with an output like below:
Now you can start/stop/restart the Apache with the following commands:
#start apache $sudo /etc/init.d/apache2 start #stop apache $sudo /etc/init.d/apache2 stop #restart apache $sudo /etc/init.d/apache2 restartWell, after get it running, you should see a working page if you try with the public DNS url.
By default, the root directory for apache is ‘/var/www’.
Installing PHP On Ubuntu Server:
Similar as Apache, Ubuntu server also comes up with PHP package. To install it, run the following command
sudo apt-get install php5You should see several output on the terminal mentioning each details. Just get a glance at those to see if installation was successful or not. After success,restart Apache server again.
Now, as we have installed php, we need to verify that, it will work properly. Lets run the simplest example, see the ‘phpinfo()’ details.
Lets navigate to apache root directory (‘/var/www’), create a new file named ‘test.php’ enter the line “<?php echo phpinfo(); ?>” in it and save it.ubuntu@ip-10-249-43-104:~$ cd /var/www ubuntu@ip-10-249-43-104:/var/www$ ls index.html ubuntu@ip-10-249-43-104:/var/www$ sudo vi test.phpnow navigate to this page by {ec2_public_dns_url}/test.php you should see a page as below:
Installing MySQL On Ubuntu EC2:
Now, we will go ahead to install mysql server on our EC2 instance. Here, I will like to mention that, if you are working with a large-scale application that might need large database, you should think to use amazon RDS service instead of using database server on same ec2 instance. But, firs to test/development purpose or small-scale application, you can keep it installed here as well.
Run the following command on terminal:
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysqlIt will install the mysql server, its Apache extension and PHP extension as well.
After successful installation, you should be able to run the following commands and test that the installation was OK.
//open mysql console $mysql -u root //change password $ mysql&gt; SET PASSWORD FOR 'root'@'localhost' = PASSWORD('mypassword'); //create a database from mysql console $ mysql&gt; CREATE DATABASE mydatabase;Well, so far we are OK and already have our LAMP stack on ubuntu EC2 instance. But, for make our work easier, we should install a database management system as well.
Installing PHPMyAdmin:
To manage MySQL databases and tables, phpmyadmin is one of the best web-based script that provides this facility very nicely. Lets install it on our Ubuntu ec2 instance. Run the following command on terminal:
sudo apt-get install phpmyadminAfter it get installed, navigate to the apache2 config file and add the phpmyadmin’s configuration there as like below:
$sudo vim /etc/apache2/apache2.conf # add this line at the end Include /etc/phpmyadmin/apache.confNow you should be able to load phpmyadmin on your server with “{public_dns_url}/phpmyadmin” url.
After finishing all the described steps above, you should be pretty much ready with your basic LAMP server. You can write php codes, test, create mysql database/tables through phpmyadmin, connect to this database from php etc well. We will see more details in the coming amazon aws tutorials. Keep in touch 🙂
Hi, I’m going to install Ubuntu for LAMP purposes on a Dell Poweredge R300. Will it make much difference its performance if I install the server based O/S instead of Desktop? I like the option of a GUI as well as the command line
actually, performance won’t matter much, I guess, as actually Ubuntu don’t have very much differences in server vs desktop version. Real differences are in the software. If you install the server version, you won’t get the GUI by default, though you will be able to get it installed yourself later. You can setup the development environment on the desktop version without any issue and what which run on this environment will run on server version OS environment as well. Hope this make sense. Thanks.
Thanks for the tutorial – I used it to successfully install LAMP on a EC2 instance on AWS. I have just one suggestion: just before the line “Now you should be able to load phpmyadmin on your server…”, you should mention that Apache needs to be restarted for the change in the config file to be activated.