How To Install LAMP Linux, Apache, MySQL, PHP stack on Debian 7 ‘Wheezy’

Debian LAMP is a combination of operating system and open-source software stack. The acronym LAMP is derived from first letters of Linux, Apache HTTP Server, MySQL database, and PHP, Perl or Python.

In this tutorial, let us install LAMP server on Debian 7 ‘Wheezy’. It is a straight forward process

Set Up

Before running through the steps of this tutorial, make sure that all of your repositories are up to date:

apt-get update
apt-get upgrade

Apache Installation

Apache is a free open source software which is still the top option for web servers.

To install Apache, enter the following command from your terminal::

apt-get install apache2

That’s it. To check if Apache is installed on your VPS, direct your browser to your server’s IP address (eg. http://181.57.64.32). The page should display the words “It works!”.

Now days most popular web applications and frameworks make use of Apache’s “rewrite” capabilities. Issue the following command to make sure this functionality is enabled:

a2enmod rewrite

MySQL Installation

MySQL is a widely-deployed database management system (RDBMS) that runs as a server providing multi-user access to a number of databases.

To install MySQL, open terminal and type in these commands:

apt-get install mysql-server mysql-client

During the installation, MySQL will ask you to set a root password.

Finish up by running the MySQL set up script:

mysql_secure_installation

The prompt will ask you for your current root password.

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.

By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y … Success! Normally, root should only be allowed to connect from ‘localhost’. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y … Success! By default, MySQL comes with a database named ‘test’ that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y – Dropping test database… … Success! – Removing privileges on test database… … Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y … Success! Cleaning up…

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]
... Success!

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]
... Success!

By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]
... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

PHP Installation

PHP is an open source web scripting language that is widely use to build dynamic webpages.

To install PHP, open terminal and type in this command:

apt-get install php5 php-pear php5-mysql libapache2-mod-php5

After you answer yes to the prompt twice, PHP will install itself.

Finish up by restarting apache:

service apache2 restart

Congratulations! You now have LAMP stack on your server!

Test PHP on your Server

LAMP is now installed, but we can still take a look and see the components online by creating a quick php info page

To set this up, first create a new file:

nano /var/www/info.php

Add in the following lines:

<? phpinfo(); ?>

Then Save and Exit. (Ctrl+O , Ctrl+X)

Finish up by visiting your php info page (make sure you replace the example ip address with your correct one): http://server-ip/info.php

You could see all the details about php such as version, build date and commands etc.:

In the next Tutorial we are going to discuss how to set up the Virtual Hosts

Leave a Reply

Your email address will not be published. Required fields are marked *