PHP Tutorial: LAMP Installation and configuration

LAMP Installation and configuration

LAMP: Linux, Apache, MySQL, and PHP

LAMP stack is a group of open source software used to get web servers up and running. Since the server is already running CentOS, the linux part is taken care of. Here is how to install the rest.

1.    Install Apache 

  • To install apache, Open up the Terminal (Applications > Accessories > Terminal).
  • The Terminal will then ask you for your password, type it and then press enter.

sudo apt-get update

sudo apt-get install apache2

Testing Apache

To make sure everything installed correctly we will now test Apache to ensure it is working properly.

Open up any web browser and then enter the following into the web address:

http://localhost/

You should see a folder entitled apache2-default/. Open it and you will see a message saying "It works!” congrats to you! Or something like that!

2.    Install PHP

In this part we will install latest version of PHP

  • Again open up the Terminal (Applications > Accessories > Terminal).
  • Copy/Paste or type the following line into Terminal and press enter:

sudo apt-get install php5 libapache2-mod-php5

  • In order for PHP to work and be compatible with Apache we must restart Apache. Type the following code in Terminal to do this:

sudo /etc/init.d/apache2 restart

 

Test PHP

To ensure there are no issues with PHP let's give it a quick test run.

  • In the terminal copy/paste or type the following line:

sudo gedit /var/www/testphp.php

It will open a file testphp.php.

  • Copy/Paste this line into the phptest file:

<?php phpinfo(); ?>

  • Save and close the file.
  • Now open your web browser and type the following into the web address:
  • It will show you the PHP information including version and other packages.

Install MySQL

  • Open Terminal and then copy/paste or type this line:

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. Type it in.

Enter current password for root (enter for none):

 

OK, successfully used password, moving on...

  • 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.

After Installing the Mysql, your system is ready for developing a PHP application. Congratulations

Next Topic