codelyft
By:
codelyft

How do i update my LAMP stack to php7?

December 6, 2015 6.9k views
Apache LAMP Stack PHP DigitalOcean Ubuntu

Hello there i am trying to update my LAMP stack to php7!? I have php5 installed currently.

1 comment
2 Answers

Upgrading to PHP7 can be done quite smooth. Just use the following commands. First add the new repository for PHP7:

$ apt-get install python-software-properties
$ add-apt-repository ppa:ondrej/php-7.0

Now backup any custom config files since we will remove PHP5 and install PHP7 now:

$ apt-get update && apt-get purge php5-fpm && apt-get --purge autoremove && apt-get install php7.0-fpm php7.0-mysql

At this point, php5-fpm should be removed and the php7.0-fpm service is running. It is, however, unlikely that your website is running properly – because the PHP-FPM socket file will have changed. If you’re running Nginx, you must update your fastcgi_pass directive inside your VHOST from:

fastcgi_pass unix:/run/php/php5.0-fpm.sock;

to:

fastcgi_pass unix:/run/php/php7.0-fpm.sock;

Some Nginx instances runs as the user/group nginx, if thats true in your situation you need to change the php-fpm file:

nano /etc/php/7.0/fpm/pool.d/www.conf

edit

listen.owner = nginx
listen.group = nginx

You might also want to change the user and group at the beginning of the file. If you had www-data in php-5, you can just keep this default.
Now restart nginx and php-fpm and it should work properly:"

$ service php7.0-fpm restart
$ service nginx restart
  • This does not work. You will receive the following error while installing PHP7:

    Some packages could not be installed. This may mean that you have
    requested an impossible situation or if you are using the unstable
    distribution that some required packages have not yet been created
    or been moved out of Incoming.
    The following information may help to resolve the situation:
    
    The following packages have unmet dependencies:
     php7.0-fpm : Depends: php7.0-cli but it is not going to be installed
                  Depends: php7.0-common (>= 7.0.2-1+deb.sury.org~trusty+1) but it is not going to be installed
                  Depends: php7.0-json but it is not going to be installed
                  Depends: php7.0-opcache but it is not going to be installed
     php7.0-mysql : Depends: php7.0-common but it is not going to be installed
    E: Unable to correct problems, you have held broken packages.
    
    

    In order to avoid the errors, you will need to do the following:

    sudo apt-get install php7.0
    

    and (if using MySQL):

    sudo apt-get install php7.0-mysql
    

For LAMP, you should be able to just update through apt-get:

apt-get install -y language-pack-en-base
apt-get install python-software-properties
dd-apt-repository ppa:ondrej/php-7.0
sudo apt-get update && sudo apt-get dist-upgrade

This is what worked for me.

  • This does not work. The third line should read:

    add-apt-repository ppa:ondrej/php-7.0
    

    Also, your instructions are incomplete and will not install PHP7. You must also do the following:

    sudo apt-get install php7.0
    

    and (if using MySQL):

    sudo apt-get install php7.0-mysql
    
Have another answer? Share your knowledge.