Install LAMP stack in Ubuntu 14.04

How to install LAMP in Ubuntu 14.04

I wanted to setup a LAMP stack on my Ubuntu. I was kind of hopin that it would be just a walk in the park as what i did with windows WAMP. I tried googling the steps and did find some nice tutorials. I will walk you through with my installation and hope i’d be successfull with this exercise.

So lets get it on

Step 1 : — Install Apache
First though we need to update our system

sudo apt-get update

Then we can install apache

sudo apt-get install apache2

After the installation you can open your browser and in the address bar just type

http://localhost

You will see the Apache 2 Ubuntu Default Page
mysql root password

And it says “It works!” hehehe, you can take a deep breath for now

Note : After you installed apache2 it will create the document root directory at /var/www/html

Step 2 : Install Mysql

sudo apt-get install mysql-server php-mysql

Notice that we added “php5-mysql” so that php5 and mysql can properly communicate with each other (“some helper tools”).

During installation it will prompt you to enter a root security password for the root access of your mysql database.
mysql install

After the installation you can check if mysql is running by typing:

mysql -u root -p
Enter password: "here you type your password"

then you should see the server verion of your mysql and other stuff. Just type “exit” to go back to command prompt.

We need to execute and tell MYSQL to create its database directory structure where it will store its information.

sudo mysql_install_db

Then secure your mysql installation especially in actual production mode

sudo mysql_secure_installation

You will be ask security questions. I answered “Y” for all of its questions hehehe just bring it on.

Step 3 : Install PHP

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

After installation you can start with a project by creating an html file at “/var/www/html”. By default apache would give priority to index.html file but we all want to give hail to index.php. So to do that we edit dir.conf

sudo nano /etc/apache2/mods-enabled/dir.conf

It should return something like this


        DirectoryIndex index.html index.cgi index.php index.pl index.xhtm$

So change the order, put index.php first on the list like this


        DirectoryIndex index.php index.html index.cgi index.pl index.xhtm$

Then save. Ctrl – X then “Y”

It is important to notice that we change some behavior of apache2 to identify .php prior to .html and others, so we need to restart the service for the change to take effect.

sudo service apache2 restart

Then install php modules ( check for available modules )

apt -cache search php5-

Next step is testing the PHP

create a file named test.php in “/var/www/html” and inside test.php write

phpinfo();

Then open the browser ahd in the address bar type

http://localhost/test.php

php install
You should see PHP Version in your screen and its configuration and lots of information.

Yes we did it! we did it! Time to coooooooooooooooooode! Good day everyone!

Connect to MYSQL Remotely

Edit the my.cnf file

# vi /etc/my.cnf

[mysqld]
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
language        = /usr/share/mysql/English
bind-address    = 65.55.55.2
# skip-networking     <-- make sure to comment out this line

Restart  mysql service

service mysqld restart

———– and that’s it 🙂 enjoy ——————–

GRANTING privileges on a DB for a User MYSQL

GRANT ALL PRIVILEGES ON dbTest.* To ‘user’@’hostname’ IDENTIFIED BY ‘password’;

If you are running the code/site accessing MySQL on the same machine, hostname would be localhost.

Now, the break down.

GRANT – This is the command used to create users and grant rights to databases, tables, etc.

ALL PRIVILEGES – This tells it the user will have all standard privileges. This does not include the privilege to use the GRANT command however.

dbtest.* – This instructions MySQL to apply these rights for the use onto the full dbtest database. You can replace the * with specific table names or store routines if you wish.

TO ‘user’@’hostname’ – ‘user’ is the of the user account you are creating. Note: You must have the single quotes in there. ‘hostname’ tells MySQL what hosts the user can connect from. If you only want it from the same machine, use localhost

IDENTIFIED BY ‘password’ – As you would have guessed, this sets the password for that user.

Backup/REstore MySQL database in Command Line Using mysqldump

Back up From the Command Line (using mysqldump)

If you have shell or telnet access to your web server, you can backup your MySQL data by using the mysqldump command. This command connects to the MySQL server and creates an SQL dump file. The dump file contains the SQL statements necessary to re-create the database. Here is the proper syntax: Continue reading “Backup/REstore MySQL database in Command Line Using mysqldump”

Up ↑

%d bloggers like this: