PHP is a component responsible for the dynamic content. All scripts and database connections work due to PHP.

Requirements

  • A VPS or a dedicated server
  • An ability to connect to them via SSH

If you need only PHP, then follow this manual. If you need the whole LAMP (Linux, Apache, MySQL and PHP) — go to the LAMP Installation chapter.

PHP Installation

If you need the latest PHP version (PHP 7 at the moment), then connect to the server via SSH and run:

apt-get install php

If you need an older PHP version, it’s a little more complicated:

  1. Connect to the server via SSH.
  2. Install the tools, necessary for PHP installation:
    apt-get install software-properties-common python-software-properties
  3. Add a repository with older PHP versions to the system:
    add-apt-repository ppa:ondrej/php
  4. Update the repository list:
    apt-get update
  5. Install the necessary PHP version:
    apt-get install php5.6

Necessary modules installation

Apache Module installation:

  1. Execute:
    sudo apt-get install libapache2-mod-php
  2. Reboot Apache:
    sudo service apache2 reload

Configuration files are at /etc/php/7.0/apache2:

conf.d — directory with active PHP extensions.

php.ini — PHP settings file.

FPM module installation:

  1. Execute:
    sudo apt-get install php-fpm
  2. Reboot the module:
    sudo service php7.0-fpm reload

Configuration files are at /etc/php/7.0/fpm:

conf.d — directory with active PHP extensions;
pool.d — directory with FPM settings;
php-fpm.conf — FPM settings file;
php.ini — PHP settings file.

MSQL module installation:

  1. Execute:
    sudo apt-get install php-mysql
  2. Reboot the module:
    sudo service php-mysql reload

Configuration files are at /etc/php/7.0/mods-available.

Mcrypt module installation:

  1. Execute:
    sudo apt-get install php-mcrypt
  2. Reboot the module:
    sudo service php-mcrypt reload

Configuration files are at /etc/php/7.0/mods-available.

LAMP Installation

LAMP stands for Linux, Apache, MySQL and PHP. You do not need to install LAMP, if you do not want to. It is not necessary for PHP itself to function, but provides an easier and cleaner way to install all the tools necessary to start a web server.

Install tasksel:

sudo apt-get install tasksel

Now install LAMP:

sudo tasksel install lamp-server

Removing LAMP

In order to remove LAMP, you need to delete every module separately. List of modules included with LAMP:

apache2
apache2-mpm-prefork 
apache2-utils 
apache2.2-common 
libapache2-mod-php5 
libapr1 
libaprutil1 
libdbd-mysql-perl 
libdbi-perl 
libmysqlclient15off 
libnet-daemon-perl 
libplrpc-perl 
libpq5 
mysql-client-5.0 
mysql-common 
mysql-server 
mysql-server-5.0 
php5-common 
php5-mysql