Installing PHP7.2 on Ubuntu 18.04

Installing PHP7.2 on Ubuntu 18.04

sudo add-apt-repository ppa:ondrej/php

sudo apt-get update

sudo apt-get install php7.2 libapache2-mod-php php7.2-curl php7.2-gd php7.2-mbstring php7.2-mcrypt php7.2-xml php7.2-xmlrpc php7.2-mysql


In case, php7.2-xmlrpc gives not found error use:

sudo apt-get install php7.2 libapache2-mod-php php7.2-curl php7.2-gd php7.2-mbstring php7.2-mcrypt php7.2-xml php7.2-mysql

It will install PHP5.6 on your server

sudo systemctl restart apache2

Installing PHP7 on Ubuntu 16.04

Installing PHP7 on Ubuntu 16.04

sudo apt-get update

sudo apt-get install php libapache2-mod-php php-curl php-gd php-mbstring php-mcrypt php-xml php-mysql php-xmlrpc

In case, php-xmlrpc gives not found error use:

sudo apt-get install libapache2-mod-php php-curl php-gd php-mbstring php-mcrypt php-mysql php-xml

It will install PHP7.0 on your server

sudo systemctl restart apache2

How To Find your Server's Public IP Address

If you do not know what your server's public IP address is, there are a number of ways you can find it. Usually, this is the address you use to connect to your server through SSH.

From the command line, you can find this a few ways.

    ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

This will give you two or three lines back. They are all correct addresses, but your computer may only be able to use one of them.

Install Apache in Ubuntu 16.04

We can get started by typing these commands:

    sudo apt-get update
    sudo apt-get install apache2

Since we are using a sudo command, these operations get executed with root privileges.

Open up the main configuration file with your text edit:

    sudo nano /etc/apache2/apache2.conf

Edit the following line replace server_domain_or_Ip with your server domain or IP:

    ServerName server_domain_or_IP

Next, check for syntax errors by typing:

    sudo apache2ctl configtest

Since we added the global ServerName directive, all you should see is:

    Output
    Syntax OK


Restart Apache to implement your changes:

    sudo systemctl restart apache2

Adjust the Firewall to Allow Web Traffic

If you look at the Apache Full profile, it should show that it enables traffic to ports 80 and 443:

    sudo ufw allow in "Apache Full"

    http://your_server_IP_address


Hide Apache ServerSignature / ServerTokens / PHP X-Powered-By

Hiding and modifying Apache server information


Fortunately, such data can easily hide and modify by changing the ServerSignature and ServerTokens directives.

ServerSignature

ServerSignature configures the footer on server-generated documents. Just like example 404 error page. Normal use it’s better hide whole signature and add or modify httpd.conf file or apache.conf file following row:

ServerSignature Off

ServerTokens

Configures the Server HTTP response header. Different ServerTokens directive options are following (add or modify httpd.conf file or apache.conf):

Prod or ProductOnly – Server sends (e.g.): Server: Apache
ServerTokens Prod

Major – Server sends (e.g.): Server: Apache/2
ServerTokens Major

Minor – Server sends (e.g.): Server: Apache/2.2
ServerTokens Minor

Min or Minimal – Server sends (e.g.): Server: Server: Apache/2.2.4
ServerTokens Min

OS – Server sends (e.g.): Server: Apache/2.2.4 (Ubuntu)
ServerTokens OS

Full or not specified – Server sends (e.g.): Server: Apache/2.2.4 (Ubuntu) PHP/5.2.3-1ubuntu6.4
ServerTokens Full

ServerTokens setting applies to the entire server, and cannot be enabled or disabled on a virtualhost-by-virtualhost basis.

Hide PHP version (X-Powered-By)

Hiding PHP version (X-Powered-By) is easy. Add or modify following php.ini file row like following:
expose_php = Off