Enter your domain name here:

This blog post will be parametrized for your case

1. Configuration directory

After you installed LAMP, you are ready to set your application online. To do that, you need to set VirtualHost configuration. Apache2 VirtualHost configuation files are in /etc/apache2/sites-enabled/. A good practice is to put them on /etc/apache2/sites-available/ and then symlink to sites-enabled, so you can remove domains by simply removing symlinks, without deleting the file.

So, go to your sites-available directory:

cd /etc/apache2/sites-available/

2. Create a VirtualHost config file

Create your domain config file, let’s assume, your website files are under /var/www/html/{domain}/

sudo nano {domain}.conf

Then, paste the code:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName {domain}
        ServerAlias *.{domain}
        DocumentRoot /var/www/html/{domain}/
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/html/{domain}/>
                Options -Indexes
                Options FollowSymLinks MultiViews
                AllowOverride All
                Require all granted
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Press ctrl+o to save, and ctrl+x to exit.

Then, create a symlink to sites-enabled directory:

sudo ln -s /etc/apache2/sites-available/{domain}.conf /etc/apache2/sites-enabled/{domain}.conf

3. Check configuration and reload

Run this code to test your Apache2. Coding Cat’s advice is to run this code everytime you make changes to Apache configuration. It may save you a lot of trouble.

sudo apachectl configtest

To reload Apache2 without impact of current website visitors, simply run:

sudo service apache2 reload

4. Done! Let’s check if it works

Open your browser, and go to http://{domain}/

If you get DNS errors, check if your domain points at your server:

dig {domain}

If not, you need to configure DNS records at your domain provider.

 

If you see 404 error, check if you have index file under /var/www/html/{domain}/ directory, like index.html or index.php, and make sure you did not receive any errors at step 3.

 

If you see other errors or a blank page, check out error.log file:

tail -f /var/log/apache2/error.log

 

What is LAMP?

LAMP stands for Linux + Apache + Mysql + PHP. In this blog post the Coding Cat will show how to install ready to use LAMP with newest versions: Apache 2.4, Mysql 5.7 and PHP 7.1.

Preparation

If you are on vanilla Debian 8, first update and upgrade:

sudo apt-get update && sudo apt-get upgrade

 

Install Apache 2.4 on Debian 8

Installing Apache is simple, just run the code:

sudo apt-get install apache2

 

Install PHP 7.1 on Debian 8

By default PHP on Debian 8 is in lower version than 7.1, so we need to add some addresses to the sources:

sudo apt-get -y install apt-transport-https lsb-release ca-certificates
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'

Next, we can use apt-get to install PHP with modules we want:

sudo apt-get update && sudo apt-get install php7.1 php7.1-cli php7.1-fpm php7.1-apcu php7.1-apcu-bc php7.1-common php7.1-curl php7.1-intl php7.1-json php7.1-mbstring php7.1-mcrypt php7.1-mysql php7.1-opcache php7.1-soap php7.1-xml php7.1-xmlrpc php7.1-xsl php7.1-zip php7.1-gd php7.1-imap php7.1-intl php7.1-zip

 

Installing Mysql 5.7 on Debian 8

First we need to install libaio1 package

sudo apt-get install libaio1

Then download deb package from mysql website:

sudo wget http://dev.mysql.com/get/mysql-apt-config_0.8.6-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.6-1_all.deb

When you see this screen below, just use arrows to go to this “Ok” and press enter. This is one of the worst UX the Coding Cat have ever seen..

Mysql installation screen

 

Update and install

sudo apt-get update
sudo apt-get -y install mysql-community-server

Done. Check installed versions.

Now you are all set, check your version of PHP:

php -version

Version of MySQL:

mysql --version

Version of Apache

sudo apache2 -v