Upgrade Php and Apache w ppa:ondrej

Posted under » PHP » Ubuntu » Apache on 16 Dec 2024

Normally this is not crucial when your OS is on LTS unless if you just completed a pentest and you are required to upgrade your apache or php.

I've tried using dockers but ppa:ondrej is the best way.

Since you can't upgrade further after apt update, you have to add a new repository (while on sudo). Installing apache and php from source is too tough for me. You can upgrade your ubuntu version which is risky because many things will not work anymore.

If you want to do this, do a comprehensive backup before starting anything. You have been warned.

For apache, it is easier.

$ add-apt-repository ppa:ondrej/apache2
$ apt update
$ apt upgrade

Apache version update are normally incremental. When upgrading, just make sure you keep your old settings. It should work without much changes.

For php, this is a bit complex.

$ add-apt-repository ppa:ondrej/php

If you get "command not found" error, install this first

$ apt-get install software-properties-common

In case you've not sure if the repo is already added... go this directory to see.

/etc/apt/sources.list.d/

FYI, the story below of this Php upgrade was done years ago, and it goes like this...

You may wish to clean or get rid of your old php 5.5. apt-get purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "`

After which SUDO update and upgrade.

Ok the moment of truth. Install the new version of PHP.

$ apt-get install php5.6

Unfortunately, you will have to install the missing PHP libraries since it doesn't install it for you.

$ apt-get install php5.6-mbstring php5.6-mcrypt php5.6-mysql php5.6-xml php5.6-gd

Stop and restart Apache and when you check for the new version,

php -v
PHP 5.6.36-1+ubuntu14.04.1+deb.sury.org+1 (cli)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

My experience is that some old codes will not work anymore.
 

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS data