Installing and configuring Apache+ PHP+Mysql in Debian

Installing and configuring Apache+ PHP+Mysql in Debian

Nataliya Oteir Read 8 minutes

LAMP- is a set of software products widely used for creating web services. This set consists of the Linux operating system, one of the most common Apache web servers, Mysql database, and PHP scripting language. This article is devoted to the procedure of standard installation and configuration of this set for further use for web services.

Debian 8 was chosen as the operating system, as one of the most popular GNU/Linux distributions. The actual process of installing this operating system will not be considered because it is not related to the subject of the article. All installation and configuration operations will be performed under the root user account.

Apache installation

Before you begin the installation, you must run the following command:

apt-get update

Next, you must install the Apache Web server package itself:

apt-get install apache2

Once the installation is complete, the Web server will be ready to go. You can check it simply by opening the IP address of the server on which the Apache package was installed in the web browser. For version 2.4, the page of the plug is as follows:

Apache configuration file, located in/etc/apache2/apache2.conf

The /etc/apache2/sites-enabled/ directory contains the configuration files of the created Web services, and the /etc/apache2/sites-available directory/ symbolic links to the Web service configuration files that are currently included.

With these configuration files, you can configure virtual hosts. Apache Server allows you to host multiple virtual hosts (services) on the same server. By default, all Web Services content is located in the /var/www folder. Content placement can be changed by specifying it in the configuration file of the virtual host, which is the responsibility of the DocumentRoot directive.

Consider creating a simple web page with the inscription "Hello World". First, create a folder where the content will be stored. To do this, run the command:

mkdir /var/www/

In this folder we will create the simplest HTML file index.html as follows:

      <title>Hello World</title> 
      <p>This is a test page.</p>

After the contents of the simplest page are present, you must create a virtual host configuration file. To do this, in the folder/etc/apache2/sites-available/ create the (don’t forget about the conf extension) with the following content:

    DocumentRoot /var/www/
    CustomLog ${ APACHE_LOG_DIR}/ combined
    ErrorLog ${ APACHE_LOG_DIR}/

Here are the options:

  • ServerName – доменное имя виртуального хоста (нашей странички);
  • ServerAdmin – адрес электронной почты администратора;
  • ServerAlias – псевдоним виртуального хоста (доменное имя хоста с добавлением www);
  • DocumentRoot – место, где хранится содержимое самого сервиса;
  • CustomLog - название файла журнала доступа с сервису;
  • ErrorLog – название файла журнала ошибок.

A detailed description of all parameters and their values in the configuration file can be found in the official documentation.

The next step is to enable our virtual host. This can be done simply by creating a symbolic link:

cd /etc/apache2/sites-enabled
ln -s ../sites-available/

You can also enable and disable virtual hosts by using the a2ensite and a2dissite commands, respectively.

To include:


To turn off:


After enabling the host, you must restart the Apache server:

/etc/init.d/apache2 restart

Now you can check the work of the created page.

To check the page, you may need to add a line to the hosts file:

Where is the IP address of the server with Apache installed. The hosts file is:

  • C:\Windows\System32\drivers\etc (в Win7);
  • /etc/hosts (в Debian).

PHP Installation

The next step is to install the PHP scripting language. The installation is done using the following command:

apt-get install php5

Now you need to check PHP. To do this, add test.php. Write the following in this file:


Now open the helloworld . net/test.php link in the browser. Get the next picture.

It should be noted that there is a PHP module for the Apache server. This module allows Apache and PHP to work more efficiently. Check if the module is installed:

dpkg -l | grep libapache2-mod-php5

If there is no module, it should be installed:

apt-get install libapache2-mod-php5.

To check if the module is connected to the Apache server itself, you can do the following:

ls -l /etc/apache2/mods-enabled/ | grep php5

The following should appear:

lrwxrwxrwx 1 root root 27 Sep  2 10:07 php5.conf -> ../mods-available/php5.conf
lrwxrwxrwx 1 root root 27 Sep  2 10:07 php5.load -> ../mods-available/php5.load

If the module is not enabled, you can enable it in the same way as virtual hosts

a2enmod php5

Shuts down the module with the a2dismod command.

Mysql Installation

The last step to preparing the Web Services environment is to install MySQL DBMS. The installation is done by the following command:

apt-get install mysql-server php5-mysql

During the installation process, you will need to enter a password for the root user.

After the installation is completed, you can test MySQL by connecting to the database itself.

mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 43
Server version: 5.5.49-0+deb8u1 (Debian)

This completes the basic preparation of the server. You can still install the PHPMyAdmin utility for database management.

apt-get install phpmyadmin

When installing, you must specify the server you want to work with, which will allow the installer to automatically configure the utility to work with this server.

You can also respond positively to the proposal to configure the database.

And enter the password for the database administrator several times (the one that was specified for the root user when you installed MySQL).

After the PHPMyAdmin installation is completed, you can check it by clicking the http://localhost/phpmyadmin link (if the browser is opened from the same server) or by clicking http://ip-address.example/phpmyadmin from another computer where the IP-ADDRESS is the server’s IP address.

To log in, you have to use the username and password that were provided by you when mysql was installed.

How useful was this post?

Click on a star to rate it!
Рейтинг: 5/5 - 1 голосов