Tahsin Abrar's WebLog

Think different.. Be Passionate!

Install LAMP Stack on Ubuntu

The acronym of LAMP stands for Linux, Apache, MySQL, and PHP. It’s straight forward to install LAMP on Ubuntu.

To install apache:

sudo apt-get update
sudo apt-get install apache2

To install MySQL:

sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

During the installation, MySQL will ask you to set a root password. If you miss the chance to set the password while the program is installing, it is very easy to set the password later from within the MySQL shell.

Once you have installed MySQL, we should activate it with this command:

 sudo mysql_install_db 

Finish up by running the MySQL set up script:

 sudo /usr/bin/mysql_secure_installation 

The prompt will ask you for your current root password. Then the prompt will ask you if you want to change the root password. Go ahead and choose N and move on to the next steps.

It’s easiest just to say Yes to all the options. At the end, MySQL will reload and implement the new changes.


Now, to install PHP:

 sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt 

Then restart Apache.

 sudo service apache2 restart 

Install PHPMyAdmin

 sudo apt-get install phpmyadmin apache2-utils 

Restart Apache.

 sudo service apache2 restart 


Install PHP and curl

sudo apt-get -y install php5-cli curl

Install mcrypt and php5-mcrypt

sudo apt-get -y install mcrypt php5-mcrypt

Enable php5-mcrypt

sudo php5enmod mcrypt

Install SQLite

sudo apt-get install php5-sqlite

Enable htaccess in Apache

First enable rewrite using this command:

 sudo a2enmod rewrite 

Then restart apache2:

 sudo service apache2 restart 

Then go into the sites-available folder:

 cd /etc/apache2/sites-available 

Edit the file named default.conf and change AllowOverride none to AllowOverride All. Or, if the Directory part is missing, then put this after DocumentRoot line :

<Directory "/var/www/html">
AllowOverride All

This will make .htaccess work in your server VPS.

This worked on an Ubuntu 14.04.3.

Using MySQL database via command line

If you’re a Unix user, and also a developer, then you’re surely love to do stuff with command line interface. It’s fun to work in a command line interface environment.

Don’t be afraid. It’s easy to use MySQL database for basic operation via command line interface.
To start mysql console:

mysql -u username -p

Then write your password when prompt. It will open the mysql console. After that, in mysql console, you can try these to use basic mysql operations:

  1.   To show all databases: show databases;
  2. To select a database from the database list, write: use <database-name>;
  3. To show tables from the selected database, write: show tables;
  4. To create a new table in the selected database, write:
    CREATE TABLE <table-name> (<field-name> <field-type> (length) );


    CREATE TABLE customers ( id INT (11), name VARCHAR(100), age INT(11), birthday DATE );
  5. To view the table structure, write:
    DESCRIBE <table-name>;


    DESCRIBE customers;
  6. To close the mysql console, write: exit; or \q;

These are the basic operations. By the way, you can use all others database queries with the command line.

Now, if you want to backup one of your database with command line, you can mysqldump. Write:

mysqldump -u username -p db_name > new_file_path_with_name


mysqldump -u username -p testdb > ~/Desktop/testdb.sql

And, if you want to import a file to the database, try:

mysql -u username -p db_name < backup_file.sql

That’s it! Happy coding!