Wednesday, December 30, 2015

Howto Install PHP 5.4, 5.5 or 5.6 on CentOS 6 and CentOS 7

Check this out : https://www.mojowill.com/geek/howto-install-php-5-4-5-5-or-5-6-on-centos-6-and-centos-7/


I still use CentOS as my distro of choice on any new server and whilst things are getting better CentOS and RHEL still don’t have up to date versions of PHP available inside the default yum repos. A couple of years ago I posted about Howto install PHP Mcrypt on CentOS using EPEL which is one of my sites most popular posts!
So CentOS and PHP, as you can see below (taken from DistroWatch) CentOS is a bit outdated with it’s PHP versions which as a PHP developer can be a pain in the ass!
PHP Current VersionCentOS 7.0-1406CentOS 6.6
5.6.45.4.165.3.3
However there is yet again hope! This time we need 2 additional repos. First up we need EPEL and secondly we need Remia French guy who is king of PHP repos!

Repo Installation

Open up a SSH connection to your server and run the following commands (make sure you run as sudo if you need to):

For CentOS 7 (including EPEL install)

1
2
3
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7*.rpm epel-release-7*.rpm
If you already have EPEL installed:
1
2

For CentOS 6 (including EPEL install)

If you already have EPEL installed:
1
2

Enabling the Repo

Now we need to make sure the repo is enabled and select which version you want to install. We need to head over to/etc/yum.repos.d you should inside see a file called remi.repo.
Open the file in your favourite editor (Nano, Pico, Vi etc), you’ll see a number of sections. We need to make sure that the first section [remi] is enabled:
1
2
3
4
5
6
7
[remi]
name=Les RPM de remi pour Enterprise Linux 6 - $basearch
enabled=1
gpgcheck=1
Note the line enabled=1 make sure this is set! Now technically you can actually go ahead and install PHP, but you will only get PHP 5.4.*. Which might be want to you want is so skip ahead to the next section!
If we want PHP 5.5 or PHP 5.6 we need to do a bit more work, further down in the repo.repo file you will see two additional sections [remi-php55] and [remi-php56], decide which PHP version you want to install and then enable the correct. So for PHP 5.6 we would change to:
1
2
3
4
5
6
7
8
[remi-php56]
name=Les RPM de remi de PHP 5.6 pour Enterprise Linux 6 - $basearch
# WARNING: If you enable this repository, you must also enable "remi"
enabled=1
gpgcheck=1
Once you made your changes save your modified file and quit your editor.

Installing PHP

Now I’m assuming you don’t already have PHP installed, this bit is super simple.
1
sudo yum install php php-gd php-mysql php-mcrypt
So the above assumes you want MySQL, GD and Mcrypt support in your PHP, but you should see something like the below depending on which version of PHP you are trying to install:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
================================================================================================================================
 Package                        Arch                   Version                                 Repository                  Size
================================================================================================================================
Installing:
 php                            x86_64                 5.5.20-2.el6.remi                       remi-php55                 2.6 M
 php-gd                         x86_64                 5.5.20-2.el6.remi                       remi-php55                  72 k
 php-mysqlnd                    x86_64                 5.5.20-2.el6.remi                       remi-php55                 3.6 M
Installing for dependencies:
 php-cli                        x86_64                 5.5.20-2.el6.remi                       remi-php55                 3.7 M
 php-common                     x86_64                 5.5.20-2.el6.remi                       remi-php55                 1.0 M
 php-pdo                        x86_64                 5.5.20-2.el6.remi                       remi-php55                 112 k
 php-pear                       noarch                 1:1.9.5-3.el6.remi                      remi                       375 k
 php-pecl-jsonc                 x86_64                 1.3.6-1.el6.remi.5.5.1                  remi-php55                  47 k
 php-pecl-zip                   x86_64                 1.12.4-1.el6.remi.5.5                   remi-php55                 269 k
 php-process                    x86_64                 5.5.20-2.el6.remi                       remi-php55                  57 k
 php-xml                        x86_64                 5.5.20-2.el6.remi                       remi-php55                 208 k
 
Transaction Summary
================================================================================================================================
Install      11 Package(s)
As you can see PHP is installing version 5.5.20-2.el6.remi from the remi-php55 repo! Once you have hit Y to confirm the install restart apache and magical unicorns you have a better version of PHP!
You can also change your mind in the future by going back into the remi.repo file and enable a different PHP version and then run yum update and if you have moved from 5.5 to 5.6 it will upgrade PHP for you. If you want to downgrade for any reason you will need to remove PHP (sudo yum remove php*) and then reinstall the PHP modules you want.
Hope this helps!

Wednesday, December 2, 2015

Could not reliably determine the server's fully qualified domain name

This is just a friendly warning and not really a problem (as in that something does not work).
If you insert a
ServerName localhost   
in either httpd.conf or apache2.conf in /etc/apache2 and restart apache the notice will disappear.
If you have a name inside /etc/hostname you can also use that name instead of localhost.

And it uses 127.0.1.1 if it is inside your /etc/hosts:
127.0.0.1 localhost
127.0.1.1 myhostname
Troubleshooting Apache
If you get this error:
apache2: Could not determine the server's fully qualified domain name, 
using 127.0.0.1 for ServerName
then use a text editor such as "sudo nano" at the command line or "gksudo gedit" on the desktop to create a new file,
sudo nano /etc/apache2/conf.d/fqdn
or
gksu "gedit /etc/apache2/conf.d/fqdn"
then add
ServerName localhost
to the file and save. This can all be done in a single command with the following:
 echo "ServerName localhost" | sudo tee /etc/apache2/conf.d/fqdn
But on Ubuntu 14.04:
 echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/fqdn.conf
 sudo a2enconf fqdn
Don't forget the ".conf" (without will not work).

How To Install And Configure mod_deflate On CentOS 7

Tuesday, December 1, 2015

How to turn off server signature on Apache web server

Check this out : http://ask.xmodulo.com/turn-off-server-signature-apache-web-server.html
Revealing web server signature with server/PHP version info can be a security risk as you are essentially telling attackers known vulnerabilities of your system. Thus it is recommended you disable all web server signatures as part of server hardening process.

Disable Apache Web Server Signature

Disabling Apache web server signature can be achieved by editing Apache config file.
On Debian, Ubuntu or Linux Mint:
$ sudo vi /etc/apache2/apache2.conf
On CentOS, Fedora, RHEL or Arch Linux:
$ sudo vi /etc/httpd/conf/httpd.conf
Add the following two lines at the end of Apache config file.
1
2
ServerSignature Off
ServerTokens Prod
Then restart web server to activate the change:
$ sudo service apache2 restart (Debian, Ubuntu or Linux Mint)
$ sudo service httpd restart (CentOS/RHEL 6)
$ sudo systemctl restart httpd.service (Fedora, CentOS/RHEL 7, Arch Linux)
The first line 'ServerSignature Off' makes Apache2 web server hide Apache version info on any error pages.
However, without the second line 'ServerTokens Prod', Apache server will still include a detailed server token in HTTP response headers, which reveals Apache version number.

What the second line 'ServerTokens Prod' does is to suppress a server token in HTTP response headers to a bare minimal.
So with both lines in place, Apache will not reveal Apache version info in either web pages or HTTP response headers.

Hide PHP Version

Another potential security threat is PHP version info leak in HTTP response headers. By default, Apache web server includes PHP version info via "X-Powered-By" field in HTTP response headers. If you want to hide PHP version in HTTP headers, open php.ini file with a text editor, look for "expose_php = On", and change it to "expose_php = Off".
On Debian, Ubuntu, or Linux Mint:
$ sudo vi /etc/php5/apache2/php.ini
On CentOS, Fedora, RHEL or Arch Linux:
$ sudo vi /etc/php.ini
1
expose_php = Off
Finally, restart Apache2 web server to reload updated PHP config file.
Now you will no longer see "X-Powered-By" field in HTTP response headers.