Installing LAMP (Linux, Apache, MySql & Php) Stack on Debian 8 Server
What is a LAMP server?
Basically it is a server installed with Apache, Mysql and PHP to serve websites and web applications for public consumption. This is in the background of every websites you visit, every app you open on your phone, your laptop, your desktop and even your tv.
It serves data that can be used by your phone applications, it processes information that will be shown in your desktop applications. In short, a webserver installed with LAMP can be called part of the building blocks of the internet.
In this guide we will show you how to install and configure a LAMP server based on Debian 8.
The tutorial will assume that:
- You have a Debian 8 vps server from vpsserver.com. If you dont have one, you can get one from https://www.vpsserver.com/plans/.
- You have an ssh terminal ready available.
- You should have an open command prompt.
- You have knowledge in the basic command for Debian or linux.
The apache web application is an open source software that allows your server to display web contents requested by the user. It is also used to serve web applications and information required by an application whether it be on mobile or on your desktop.
First, we will need to upgrade our Debian installation. We can do this by running the below command:
sudo aptitude safe-upgrade
A safe upgrade is done to update the currently installed software on your Debian 8 installation.
After the upgrade we need to install our apache server.
sudo aptitude install apache2 apache2-doc
The command above will install the basic configuration for our Apache webserver as well as installing the latest documentation for Apache.
You can verify if Apache is installed properly by going to your web browser and entering the ip address of your server. You should see the below webpage:
Knowing your Server's IP address
To get your ip address we run the ifconfig command:
This will return a list of network interface available on the vps server. The ip address of the servers immediately comes after inet addr.
$ /sbin/ifconfig eth0 eth0 Link encap:Ethernet HWaddr 8c:70:5a:92:f6:e0 inet addr:10.1.1.78 Bcast:10.255.255.255 Mask:255.0.0.0 inet6 addr: fe80::8e70:5aff:fe92:f6e0/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:24557 errors:0 dropped:0 overruns:0 frame:0 TX packets:18095 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:17493073 (17.4 MB) TX bytes:3226275 (3.2 MB)
From the example above we can see that the ip address of our server is 10.1.1.78.
After verifying that Apache is up and running we can now start the installation of our Mysql server.
A Mysql server stores valuable information from your website using a file called a database. This database consist of a table which then consist of rows and columns of data that can be retrieved by our webpage to be shown to users or for use by an application.
To install Mysql server we will need to run the following commands:
sudo aptitude install mysql-server php5-mysql
During the installation, the server will ask you to select and confirm your administrator or root password, This root password will be used when you would like to add or make changes to the database and Mysql server configuration. Make sure to set a good password with uppercase, lowercase and alphanumeric characters.
Afterwards, run the following script to secure your mysql server installation. This will lock down access to the server and avoid security and performance issues.
During the configuration you will be asked for the root password that you entered earlier. It will also ask you if you want to change this password or not. If you can happy with your password you can skip this step. You can just simply hit ENTER for the rest of the questions.
To check if the mysql server is running login to mysql server using:
mysql -u root -p
And enter your root password then run the following command:
Now that your database and Apache server is already up and running we can now move on to installing PHP.
PHP is a software that processes dynamic content for your webpage and, depending on your needs, it can communicate with our Mysql server to provide realtime, dynamic results and data to our users.
Some use of PHP is to provide information on user accounts, traffic updates, location information and many more. To install PHP we will execute the following commands.
sudo aptitude install php5-common libapache2-mod-php5 php5-cli
The command above will install php and we will test it later on to check if our configuration and installation is fine.
Installing other PHP modules
To further enhance the capabilities of php we can optionally install some modules. A reason to add modules is that it may be required by our application or webpage.
To check for available modules type the following commands:
apt-cache search php5-
The modules available will then be shown to you like below:
php5-dev - Files for PHP5 module development php5-gd - GD module for php5 php5-common - Common files for packages built from the php5 source ...
To get an information on what the module does, you can get the name of the module and use the following command below. Alternatively, you can search thru the internet as well.
apt-cache show php5-gd
To install a module, you can execute the command below:
sudo aptitude install php5-gd
Or to install multiple modules just add it into the existing command:
sudo aptitude install php5-gd php5-common
In order to check if our PHP installation is working and that all installed modules are properly configured we will have to create a php file containing our php information.
To do this we will creat a file in our /var/www/html directory called info.php.
sudo nano /var/www/html/info.php
Open the file and paste the following php script inside the file:
<?php phpinfo(); ?>
Save and close the file. Afterwards, open your web browser and enter your server ip address followed by the filename we just created.
You should see the same page as below. The data in your info page may be different from mine since some of the modules I have may not be installed on your server. What is important at this time is that your page is properly processing php information.
Now that your LAMP server on Debian 8 is all set-up and configured we can now install applications that we will need.If you have any questions or suggestions you can always comment below.