How to setup and configure LAMP on ubuntu server?

LAMP stands for Linux Apache Mysql and PHP stack which is the base to run web server and websites based on PHP. I am going to explain how you can set up LAMP on any ubuntu server or ubuntu machine step by step. Like and Share to spread this to people who needs it.
How to install and configure LAMP on ubuntu server? : Intelligent computing

Hello Intelligent people out there, greet from Dheeraj.
If you are a Web developer, or system administrator, you must be having idea what LAMP is, and just like LAMP there are WAMP stands for Windows Apache Mysql and PHP and XAMPP where X stands for Cross platform.
If you are on linux machine and working with command lines only, let's get to know how you can setup LAMP within 10 minute at max, depending on your internet speed for sure.


First thing first

Make sure all your packages are updated on server.
To make sure this, execute this command



sudo apt-get install updates


This should install updates if available for your system. Once done, let’s get started.


  1. Install LAMP Packages

First of all let’s execute command to install all of the required component to install PHP stack along with Apache and mysql
Execute following command into the putty or your terminal window.


sudo apt-get install php apache2 libapache2-mod-php mysql-server php-mysql

This will ask for some hard drive space to be used and installation should begin.


During installation of mysql in between, you will be asked to provide default mysql username and password for your server.
Provide those details, this will be used to login to phpmyadmin and connecting database as well.


Once installation is finished, restart apache2 to save and update the settings. For the same reason, execute following command.


sudo service apache2 restart


2. Check and verify mysql installation

This is simple, you can check mysql installation by following command



mysql -u root -p


Running and check mysql command to confirm installation : Intelligent computing

Followed by password, if you are able to login, type exit command to exit and this makes sure your mysql is been installed as well.


3. Installing phpMyAdmin

Now we’ll install phpmyadmin, to make sure you knows this, your Apache default directory is
/var/www/html
You can check apache installation by visiting IP of your server or any DNS that is associated with it. This will show apache default page located at /var/www/html/


Now to install phpmyadmin, execute following command.



sudo apt-get install phpmyadmin


This will install phpmyadmin and once done, you have to make short link or say shortcut of this to your root directory/phpmyadmin folder so that you can access via web/http


To do so, execute following command.



sudo ln -s /usr/share/phpmyadmin/ /var/www/html/


This will create a shortcut and you can access your phpmyadmin using /phpmyadmin.
You can also rename phpmyadmin folder to anything you want.


To check this, open your root directory/phpmyadmin or folder name you have specified, this will open phpmyadmin and you can login by entering username and password of mysql as stated earlier.


4. Finalizing setup and enabling htaccess

You may be asked to install mbstring or missing mbstring when running phpmyadmin, to fix that thing, simply execute following command to install it.



sudo apt-get install phpmyadmin php-mbstring php-gettext


This will enable mbstring, and to make this setting effective, restart apache services as we have done earlier by executing command



sudo service apache2 restart


Now we’ll enable htaccess by changing configuration setting of apache.
First execute following command to enable rewrite



sudo a2enmod rewrite


Now edit file using your favorite editor. For my case i’ll use vim to edit configuration file by passing following command.


Sudo vi /etc/apache2/apache2.conf


Edit apache configuration file to enable override using htaccess : Intelligent computing


Now look for section where you’ll find
<Directory /var/www/>
       Options Indexes FollowSymLinks
       AllowOverride None
       Require all granted
</Directory>


Edit this section and change AllowOverride None to AllowOverride all
Save and quit editor.


Now again restart apache2.


One more thing, in case you are on AWS and installing LAMP on AWS after creating your own vpc, your default user will be ubuntu and owner of /var/www/html is root and you might not have write permission on this directory.
In that case, you can execute following command to change the owner of html folder to current user i.e. ubuntu.
By executing following command.


sudo chown ubuntu /var/www/html


5. Setting up filezilla connection to your ubuntu server using keyfile.

This is easy too.
  1. Open filezilla
  2. Navigate to File > Sitemanager
  3. Click on New site button.
  4. Provide details as follows:
SFTP filezilla configuration type : Intelligent computing

    1. Hostname : your server’s IP address
    2. Port (leave blank)
    3. Connection type : sftp
    4. Username : ubuntu
    5. Keyfile : browse and select .pem file for AWS ec2 server which you have created during server launch.
    6. Click on connect.
Upon connection, you will be able to connect to your server anytime. Navigate to /var/www/html to upload your php project and directory structure will be started root from this directory only.


Hope these points helped you to setting up server and connecting your server specially on AWS.
If you have any doubt, any bug, or question, please leave comment below.
Share with your friends, group and on social media for sure.
Have great time.

Dheeraj Thedijje

Dheeraj Thedijje

Powered by Blogger.