CodeSamplez.com

Programming, Web development, Cloud Technologies

  • Facebook
  • Google+
  • RSS
  • Twitter
  • 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
Home Web Server How To Install LAMP Stack On Ubuntu Server

How To Install LAMP Stack On Ubuntu Server

Rana Ahsan March 13, 2013 3 Comments


 How To Install LAMP Stack On Ubuntu Server    

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 🙂

Related

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

About Rana Ahsan

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

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

Leave a Reply Cancel reply

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

Email Subscription

Never miss any programming tutorial again.

Popular Tutorials

  • How To Work With JSON In Node.js / JavaScript
  • PHP HTML5 Video Streaming Tutorial
  • Utilizing Config File In C#.NET Application
  • LinQ Query With Like Operator
  • Facebook C# API Tutorials
  • Few Important Basic Git Commands Examples
  • How To Work With C# Serial Port Communication
  • Using Supervisord Web Interface And Plugin
  • Getting Started With Smarty Template Engine
  • How To Use Hotkeys/Keyboard Events In WPF Application Using C#

Recent Tutorials

  • 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
  • How To Dockerize A Multi-Container App From Scratch

Recent Comments

  • S. Chalisque on PHP HTML5 Video Streaming Tutorial
  • Armorik on Generate HTTP Requests using c#
  • iswaps on PHP HTML5 Video Streaming Tutorial
  • TAKONDWA on PHP HTML5 Video Streaming Tutorial
  • rorenzo on PHP HTML5 Video Streaming Tutorial

Archives

Resources

  • CodeSamplez.com Demo

Tags

.net apache api audio aws c# cache cloud server codeigniter deployment doctrine facebook git github golang htaccess html5 http image java javascript linq mysql nodejs oop performance php phpmyadmin plugin process python regular expression scalability server smarty ssh tfs thread tips ubuntu unit-test utility web application wordpress wpf

Copyright © 2010 - 2022 · CodeSamplez.com ·

Copyright © 2022 · Streamline Pro Theme on Genesis Framework · WordPress · Log in