• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • Featured
    • C# Tutorials
      • LinQ Tutorials
      • Facebook C# API Tutorials
    • PHP Tutorials
      • CodeIgniter Tutorials
    • Amazon AWS Tutorials
  • Categories
    • Programming
    • Development
    • Database
    • Web Server
    • Source Control
    • Management
    • Project
  • About
  • Write
  • Contact

CodeSamplez.com

Programming, Web development, Cloud Technologies

You are here: Home / Web Server / How To Install LAMP Stack On Ubuntu Server

How To Install LAMP Stack On Ubuntu Server

March 13, 2013 by Rana Ahsan 4 Comments

Install LAMP On Ubuntu

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 apache2

You should see the installation process running with an output like below:

Install Apache On Ubuntu Ec2 Instance

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 restart

Well, after get it running, you should see a working page if you try with the public DNS url.

apache running on ubuntu ec2

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 php5

You 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.php

now navigate to this page by {ec2_public_dns_url}/test.php you should see a page as below:

ubuntu ec2 running php

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-mysql

It 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&amp;gt; SET PASSWORD FOR 'root'@'localhost' = PASSWORD('mypassword');
//create a database from mysql console
$ mysql&amp;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 phpmyadmin

After 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.conf

Now 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 🙂

Share If Liked

  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to share on Pocket (Opens in new window)

You may also like

Filed Under: Web Server Tagged With: apache, mysql, php, ubuntu

About Rana Ahsan

Rana is a passionate software engineer/Technology Enthusiast.
Github: ranacseruet

Reader Interactions

Comments

  1. Craig Wellman says

    April 28, 2013 at 10:08 am

    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

    Reply
  2. Md Ali Ahsan Rana says

    April 28, 2013 at 9:43 pm

    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.

    Reply
  3. Jim says

    July 26, 2014 at 6:50 am

    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.

    Reply

Trackbacks

  1. Amazon Route 53 Tutorial - CodeSamplez says:
    November 28, 2020 at 10:17 am

    […] As a prerequisite of this tutorial, I assume you can create and EC2 server and test it live on via public DNS server name. If not, you can considering reading about installing LAMP stack on Ubuntu EC2 instance. […]

    Reply

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 3,774 other subscribers

Follow Us

  • Twitter
  • Facebook

Top Posts & Pages

  • PHP HTML5 Video Streaming Tutorial
    PHP HTML5 Video Streaming Tutorial
  • How To Work With JSON In Node.js / JavaScript
    How To Work With JSON In Node.js / JavaScript
  • Using Supervisord Web Interface And Plugin
    Using Supervisord Web Interface And Plugin
  • How To Work With C# Serial Port Communication
    How To Work With C# Serial Port Communication
  • Get Facebook C# Api Access Token
    Get Facebook C# Api Access Token
  • Facebook C# API Tutorials
    Facebook C# API Tutorials
  • Beginning Codeigniter Application Development
    Beginning Codeigniter Application Development
  • LinQ Query With Like Operator
    LinQ Query With Like Operator
  • Beginning With Facebook Graph API C#.NET
    Beginning With Facebook Graph API C#.NET
  • "Facebooksdk" - C#.NET Library For Facebook API
    "Facebooksdk" - C#.NET Library For Facebook API

Recent Posts

  • Building Auth With JWT – Part 2
  • Building Auth With JWT – Part 1
  • Document Your REST API Like A Pro
  • Understanding Golang Error Handling
  • Web Application Case Studies You Must Read

Tags

.net angularjs apache api audio auth authenticatin aws c# cloud server codeigniter deployment docker doctrine facebook git github golang htaccess html5 http javascript jwt linq mysql nodejs oop performance php phpmyadmin plugin process python regular expression scalability server smarty socket.io tfs tips unit-test utility web application wordpress wpf

Popular Tutorials

  • PHP HTML5 Video Streaming Tutorial
  • How To Work With JSON In Node.js / JavaScript
  • Using Supervisord Web Interface And Plugin
  • How To Work With C# Serial Port Communication
  • Get Facebook C# Api Access Token
  • Facebook C# API Tutorials
  • Beginning Codeigniter Application Development
  • LinQ Query With Like Operator
  • Beginning With Facebook Graph API C#.NET
  • "Facebooksdk" - C#.NET Library For Facebook API

Recent Tutorials

  • Building Auth With JWT – Part 2
  • Building Auth With JWT – Part 1
  • Document Your REST API Like A Pro
  • Understanding Golang Error Handling
  • Web Application Case Studies You Must Read
  • Getting Started With Golang Unit Testing
  • Getting Started With Big Data Analytics Pipeline
  • NodeJS Tips And Tricks For Beginners
  • Apple Push Notification Backend In NodeJS
  • Web Based Universal Language Translator, Voice/Text Messaging App

Footer

Archives

Follow Us

  • Twitter
  • Facebook

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 3,774 other subscribers

Copyright © 2023