Showing posts with label LINUX. Show all posts
Showing posts with label LINUX. Show all posts

Monday, 22 February 2016

How to install PHP and MySQL in LINUX

PHP, MySQL and Apache are most important for web developers. Here i am going to show you how to install all of these in your LINUX machine. So let's start and follow my steps carefully.

Step 1 : First of all we need to install apache or any other web server. here we will install apache. Apache is a free open source software which runs over 50% of the world’s web servers. For installing apache on your machine open the terminal in your LINUX machine and type following commands one by one.

sudo apt-get update
sudo apt-get install apache2

Now open your browser and type "localhost" or "". It will show you the following page.

Step 2 : Now install MySQL on your machine. To install MySQL, open terminal and type in these commands.

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

In the middle of your installation it will ask you set the root password, If you missed then set the password later within the MySQL shell.
Once you have installed MySQL, we should activate it with this command: 

sudo mysql_install_db

Now type the following command:

sudo /usr/bin/mysql_secure_installation

After this a prompt will ask you for entering the current root password. Type the password. Now prompt will ask you to change the password, So type N.
After that type 'Y' in all upcoming prompts. At last MySQL will reload and implement the new changes. 
Now MySQL installed successfully. For checking it open the terminal and type the following command :

sudo mysql root your_password

Step 3 : Now we are going to install PHP. To install PHP, open terminal and type in this command.

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

Type 'Y' in two prompts after it. It will install PHP automatically.
Now add php to the directory index by the following command:

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

Now add the index.php in beginning of the index files. It should be see like this :

<IfModule mod_dir.c>

          DirectoryIndex index.php index.html index.cgi index.php index.xhtml index.htm


Now type the command for adding the libraries and modules:

apt-cache search php5-

The terminal will show you the all modules. Select one of them and type the command:

sudo apt-get install name of the module

Now setup is almost complete. create a new file named "phpinfo.php" in '/var/www' folder and type the following lines.


Save it and open the browser and type "localhost/phpinfo.php"  the following address in address bar. It will show you the following screen.

Good luck guys.