Tutorial

How To Upgrade to PHP 7 on Ubuntu 14.04

How To Upgrade to PHP 7 on Ubuntu 14.04

Introduction

PHP 7, which was released on December 3, 2015, promises substantial speed improvements over previous versions of the language, along with new features like scalar type hinting. This guide explains how to quickly upgrade an Apache or Nginx web server running PHP 5.x (any release) to PHP 7.

Warning: As with most major-version language releases, it’s best to wait a little while before switching to PHP 7 in production. In the meanwhile, it’s a good time to test your applications for compatibility with the new release, perform benchmarks, and familiarize yourself with new language features.

If you’re running any services or applications with active users, it is safest to first test this process in a staging environment.

Prerequisites

This guide assumes that you are running PHP 5.x on an Ubuntu 14.04 machine, using either mod_php in conjunction with Apache, or PHP-FPM in conjunction with Nginx. It also assumes that you have a non-root user configured with sudo privileges for administrative tasks.

Adding a PPA for PHP 7.0 Packages

A Personal Package Archive, or PPA, is an Apt repository hosted on Launchpad. PPAs allow third-party developers to build and distribute packages for Ubuntu outside of the official channels. They’re often useful sources of beta software, modified builds, and backports to older releases of the operating system.

Ondřej Surý maintains the PHP packages for Debian, and offers a PPA for PHP 7.0 on Ubuntu. Before doing anything else, log in to your system, and add Ondřej’s PPA to the system’s Apt sources:

  1. sudo add-apt-repository ppa:ondrej/php

You’ll see a description of the PPA, followed by a prompt to continue. Press Enter to proceed.

Note: If your system’s locale is set to anything other than UTF-8, adding the PPA may fail due to a bug handling characters in the author’s name. As a workaround, you can install language-pack-en-base to make sure that locales are generated, and override system-wide locale settings while adding the PPA:

  1. sudo apt-get install -y language-pack-en-base
  2. sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php

Once the PPA is installed, update the local package cache to include its contents:

  1. sudo apt-get update

Now that we have access to packages for PHP 7.0, we can replace the existing PHP installation.

Upgrading mod_php with Apache

This section describes the upgrade process for a system using Apache as the web server and mod_php to execute PHP code. If, instead, you are running Nginx and PHP-FPM, skip ahead to the next section.

First, install the new packages. This will upgrade all of the important PHP packages, with the exception of php5-mysql, which will be removed.

  1. sudo apt-get install php7.0

Note: If you have made substantial modifications to any configuration files in /etc/php5/, those files are still in place, and can be referenced. Configuration files for PHP 7.0 now live in /etc/php/7.0.

If you are using MySQL, make sure to re-add the updated PHP MySQL bindings:

  1. sudo apt-get install php7.0-mysql

Upgrading PHP-FPM with Nginx

This section describes the upgrade process for a system using Nginx as the web server and PHP-FPM to execute PHP code.

First, install the new PHP-FPM package and its dependencies:

  1. sudo apt-get install php7.0-fpm

You’ll be prompted to continue. Press Enter to complete the installation.

If you are using MySQL, be sure to re-install the PHP MySQL bindings:

  1. sudo apt-get install php7.0-mysql

Note: If you have made substantial modifications to any configuration files in /etc/php5/, those files are still in place, and can be referenced. Configuration files for PHP 7.0 now live in /etc/php/7.0.

Updating Nginx Site(s) to Use New Socket Path

Nginx communicates with PHP-FPM using a Unix domain socket. Sockets map to a path on the filesystem, and our PHP 7 installation uses a new path by default:

PHP 5 PHP 7
/var/run/php5-fpm.sock /var/run/php/php7.0-fpm.sock

Open the default site configuration file with nano (or your editor of choice):

  1. sudo nano /etc/nginx/sites-enabled/default

Your configuration may differ somewhat. Look for a block beginning with location ~ \.php$ {, and a line that looks something like fastcgi_pass unix:/var/run/php5-fpm.sock;. Change this to use unix:/var/run/php/php7.0-fpm.sock.

/etc/nginx/sites-enabled/default
server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/html;
    index index.php index.html index.htm;

    server_name server_domain_name_or_IP;

    location / {
        try_files $uri $uri/ =404;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Exit and save the file. In nano, you can accomplish this by pressing Ctrl-X to exit, y to confirm, and Enter to confirm the filename to overwrite.

You should repeat this process for any other virtual sites defined in /etc/nginx/sites-enabled which need to support PHP.

Now we can restart nginx:

  1. sudo service nginx restart

Testing PHP

With a web server configured and the new packages installed, we should be able to verify that PHP is up and running. Begin by checking the installed version of PHP at the command line:

  1. php -v
Output
PHP 7.0.0-5+deb.sury.org~trusty+1 (cli) ( NTS ) Copyright (c) 1997-2015 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies

You can also create a test file in the web server’s document root. Depending on your server and configuration, this may be one of:

  • /var/www/html
  • /var/www/
  • /usr/share/nginx/html

Using nano, open a new file called info.php in the document root. By default, on Apache, this would be:

  1. sudo nano /var/www/html/info.php

On Nginx, you might instead use:

  1. sudo nano /usr/share/nginx/html/info.php

Paste the following code:

info.php
<?php
phpinfo();
?>

Exit the editor, saving info.php. Now, load the following address in your browser:

http://server_domain_name_or_IP/info.php

You should see PHP version and configuration info for PHP 7. Once you’ve double-checked this, it’s safest to to delete info.php:

  1. sudo rm /var/www/html/info.php

Conclusion

You now have a working PHP 7 installation. From here, you may want to check out Erika Heidi’s Getting Ready for PHP 7 blog post, and look over the official migration guide.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the author(s)

Brennen Bearnes
Brennen Bearnes
See author profile

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
50 Comments
Leave a comment...

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Doesn’t work for me on Ubuntu 14.04.3 & Nginx 1.9.7…

I’ve added the PPA and updated the package cache, but got this when trying to install php7.0-fpm:

apt-get install php7.0-fpm

Reading package lists... Done
Building dependency tree
Reading state information... Done
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.0-6+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
E: Unable to correct problems, you have held broken packages.

I tried to install them all, but I keep getting more dependencies and conflicts

The following packages have unmet dependencies:
 php7.0-cli : Recommends: php-readline but it is not installable
              Breaks: php5-cli but 5.5.30+dfsg-1+deb.sury.org~trusty+1 is to be installed
 php7.0-common : Conflicts: php5-common but 5.5.30+dfsg-1+deb.sury.org~trusty+1 is to be installed
E: Unable to correct problems, you have held broken packages.

@bojanrnr I received similar messages. I ran sudo apt-get remove php5-common and then ran from the top of this page again

Have you tried this? http://askubuntu.com/questions/705880/how-to-install-php-7 Purging first, then installing all the PHP packages

@bojanrnr i had same issue but i used the following command to remove PHP 5.6 first

sudo apt-get -y purge php5

I can get PHP 7 running on Ubuntu 14.04 with Nginx, but I can’t get phpmyadmin installed even using the latest version because php-gettext and php-seclib are missing from the PHP 7 install. HAs anyone gotten phpmyadmin to work and willing to post directions?

Brennen Bearnes
DigitalOcean Employee
DigitalOcean Employee badge
December 31, 2015

See my comment here.

thank’s

Got the following error after installing php7.0-mcrypt. Anyone have a solution?

PHP Warning:  Module 'mcrypt' already loaded in Unknown on line 0
Brennen Bearnes
DigitalOcean Employee
DigitalOcean Employee badge
December 16, 2015

This rings a bell. I suspect that mcrypt is already compiled in.

You can kill the error by commenting extension=mcrypt.so in /etc/php/mods-available/mcrypt.ini (which should cover both the CLI and FPM SAPIs), like so:

root@lempet2:/etc/php/mods-available# cat mcrypt.ini 
; configuration for php mcrypt module
; priority=20
;extension=mcrypt.so

Even after doing this, it shows up in the list of compiled modules:

root@lempet2:/etc/php/mods-available# php -m | grep mcrypt
mcrypt

That said, there’s obviously still a problem here if code doesn’t work. I do notice that some mcrypt_* functions seem to have been deprecated in this release.

@bpb Thanks Brennen

Thank you for writing this article.

I’m getting a 500 error code after following the tutorial with a LAMP on Ubuntu 14.04. Replicated every step perfectly but it seems like PHP7 and MySQL won’t work together. Any ideas?

Brennen Bearnes
DigitalOcean Employee
DigitalOcean Employee badge
December 18, 2015

You mention MySQL, so I’m guessing you have some log output pointing that direction? Could you paste any specific errors you’re seeing from /var/log/apache2/error.log?

I thought the socket path was like this:

/run/php/php7.0-fpm.sock;
Brennen Bearnes
DigitalOcean Employee
DigitalOcean Employee badge
December 18, 2015

Interesting. Looks like /var/run symlinks to /run. I confess I haven’t really followed this change, but it sounds like /run has been canonical (or headed that way) for the major distros for a while now.

Thanks for the note. I’ll do a bit of further reading and update the instructions.

I saw that when I was looking into the /etc/php/7.0/fpm/pool.d/www.conf file.

I have just tested this and it refuses to work for me and just goes around in circles with unmet dependencies.

Trying to run this:

sudo apt-get install php7.0

Results in:

The following packages have unmet dependencies:
 php7.0 : Depends: libapache2-mod-php7.0 (>= 7.0.1-2+deb.sury.org~wily+1~) but it is not going to be installed or
                   php7.0-cgi (>= 7.0.1-2+deb.sury.org~wily+1~) but it is not going to be installed or
                   php7.0-fpm (>= 7.0.1-2+deb.sury.org~wily+1~) but it is not going to be installed
          Depends: php7.0-common (= 7.0.1-2+deb.sury.org~wily+1) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

So then I try to install libapache2-mod-php7.0 and get a different unmet dependency:

The following packages have unmet dependencies:
 libapache2-mod-php7.0 : Depends: php7.0-cli but it is not going to be installed
                         Depends: php7.0-common (= 7.0.1-2+deb.sury.org~wily+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
                         Conflicts: libapache2-mod-php5filter but 5.6.11+dfsg-1ubuntu3.1 is to be installed
E: Unable to correct problems, you have held broken packages.

Then finally I try to go back one more stage and install php7.0-cli but this also doesn’t work due to unmet dependencies:

The following packages have unmet dependencies:
 php7.0-cli : Depends: php7.0-common (= 7.0.1-2+deb.sury.org~wily+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
              Recommends: php-readline but it is not going to be installed
              Breaks: php5-cli but 5.6.11+dfsg-1ubuntu3.1 is to be installed
E: Unable to correct problems, you have held broken packages.

If I instead try to purge PHP5 first then it removes Roundcube and PHPMyAdmin and they refuse to install again afterwards due to missing modules.

Is there anything else I can try?

Thanks Robin

Ok I’ve figured out how to get PHP 7.0 installed which involved doing these steps instead (on my server):

sudo apt-get -y purge php5 libapache2-mod-php5 php5 php5-cli php5-common php5-curl php5-gd php5-imap php5-intl php5-json php5-mcrypt php5-mysql php5-pspell php5-readline php5-sqlite

Then remove a few extra things that were left behind:

sudo apt-get autoremove

Then install PHP 7.0:

sudo apt-get install php7.0

Then as PHPMyAdmin was removed Apache2 wouldn’t start so I had to remove the config file (I could have moved it instead):

sudo rm /etc/apache2/conf-enabled/phpmyadmin.conf

Then I had to restart Apache2:

sudo service apache2 restart

PHP 7.0 was then running

However I can’t now figure out how to get PHPMyAdmin installed again as it just says there are unmet dependencies with PHP 5 even though 7.0 is loaded and running (confirmed with PHPINFO();

Brennen Bearnes
DigitalOcean Employee
DigitalOcean Employee badge
December 22, 2015

Thanks for the detailed breakdown. I’ll see what I can figure out with regards to PHPMyAdmin.

I am also having an issue with phpMyAdmin…seems the package still relies on php5 packages so you can’t install through apt-get

Brennen Bearnes
DigitalOcean Employee
DigitalOcean Employee badge
December 31, 2015

For upgrading by way of APT, this PPA looks promising; a quick run-through on an Apache installation appears to work:

sudo add-apt-repository ppa:nijel/phpmyadmin
sudo apt-get install phpmyadmin

It’s somewhat iffier for Nginx, and it’s possible that installing PHPMyAdmin directly from upstream sources is a better idea. I’m still en route home from a holiday visit to family, but I’ll do a bit of digging and a more complete writeup this coming weekend.

Thanks bpb (replying to the post above as there is no option to reply to your post for some reason!)

I have now tested this repository and can confirm it does indeed update to a much newer version of PHPMyAdmin.

I did encounter an issue where it ran an SQL update script which failed but I worked around it by running the .sql update afterwards.

Here are my steps in case it is of use to others:

First I installed the package and tried to upgrade the package:

sudo add-apt-repository ppa:nijel/phpmyadmin
sudo apt-get update
sudo apt-get upgrade

However this said the package had been held back and didn’t update to it but running this forced it to update:

sudo apt-get dist-upgrade

Unfortunately during the upgrade it failed with an error as the PHPMyAdmin SQL upgrade script (upgrade_column_info_4_3_0+.sql) tries to add the following two columns to pma__column_info but they already exist:

input_transformation
input_transformation_options

This generates the following error:

mysql said: ERROR 1060 (42S21) at line 28: Duplicate column name 'input_transformation'

I chose to ignore the warning and then went to /usr/share/phpmyadmin/sql after install and ran the upgrade_column_info_4_3_0+.sql script manually removing this offending part:

ALTER TABLE `pma__column_info`
  ADD `input_transformation` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
  ADD `input_transformation_options` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '';

Finally I had to edit the config file at /etc/phpmyadmin/config.inc.php and add the following two lines:

$cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings';
$cfg['Servers'][$i]['export_templates'] = 'pma__export_templates';

The errors about the extended features then went away.

The next step is to try PHP7 again!

Nice… i will try it when there is time

Kingsley, better chill.

Let Ubuntu release a major update and we will see if it will have provisions for php7

lol,

i hope it will be included in ubuntu 16.04

I am getting on Apache installation

service apache2 restart

  • Restarting web server apache2 [fail]
  • The apache2 configtest failed. Output of config test was: apache2: Syntax error on line 140 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/mods-enabled/php5.load: Cannot load /usr/lib/apache2/modules/libphp5.so into server: /usr/lib/apache2/modules/libphp5.so: cannot open shared object file: No such file or directory Action ‘configtest’ failed. The Apache error log may have more information.
Brennen Bearnes
DigitalOcean Employee
DigitalOcean Employee badge
January 4, 2016

It looks like the upgrade process left /etc/apache2/mods-enabled/php5.load in place, which refers to a no-longer-installed shared library. Give this a shot:

  1. sudo a2dismod php5
  2. sudo apache2ctl configtest

On my test system, I get:

Output
Module php5 disabled.
To activate the new configuration, you need to run:
  service apache2 restart
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
Syntax OK

Your output might be missing the ServerName warning. As long as you see Syntax OK, you can restart Apache:

  1. sudo service apache2 restart

This comment has been deleted

    This worked perfectly for me.

    Thanks a lot!!

    Brennen, could you please change the repositories to ppa:ondrej/php, I will deprecate ppa:ondrej/php-7.0 repository at some point in time as it contains exactly the same PHP 7.0 packages as ppa:ondrej/php.

    Brennen Bearnes
    DigitalOcean Employee
    DigitalOcean Employee badge
    January 14, 2016

    Will do momentarily. Thanks for the heads up. (Not to mention all your hard work on the packages.)

    Edit: Done.

    It will take some time, I will try to hunt all the popular guides around to change the repository URL before killing the old one.

    A PPA is easier of course, but I have resolved a lot of issues to build PHP 7 and configure it on Ubuntu 15.04 and 15.10 if you decide to upgrade from 14.04.

    You may need to choose a particular release branch and run the script instead of building right from master.

    https://gist.github.com/m1st0/1c41b8d0eb42169ce71a

    I’m using Ubuntu. After installing php7.0, server stopped parsing php files. From cli I can run php, but when I run a script from http://XX.XX.XX.XX/info.php I get only "<?php phpinfo(); ?> "

    When I run phpinfo from cli, it shows smth like

    PHP Version => 7.0.3-3+deb.sury.org~trusty+1

    System =>XXXX 3.13.0-57-generic #95-Ubuntu SMP Fri Jun 19 09:28:15 UTC 2015 x86_64 Server API => Command Line Interface Virtual Directory Support => disabled Configuration File (php.ini) Path => /etc/php/7.0/cli Loaded Configuration File => /etc/php/7.0/cli/php.ini Scan this dir for additional .ini files => /etc/php/7.0/cli/conf.d Additional .ini files parsed => /etc/php/7.0/cli/conf.d/10-opcache.ini, /etc/php/7.0/cli/conf.d/20-json.ini, /etc/php/7.0/cli/conf.d/20-readline.ini…

    So, how can I make the server to parse php files by outside, from http://XX.XX.XX.XX/info.php ?

    Thanks

    What web server are you using? Have you installed the appropriate PHP7 processors (mod_php for apache and php_fpm for nginx)?

    Thank you for the article. I had to also run sudo apt-get install libapache2-mod-php7.0 before I got this to work in apache, nginx did work with without any prolems

    I had to do this as well.

    thank you!!!

    This also did it for me.

    I installed PHP 7 on Apache prior removing PHP 5.6.

    Creating config file /etc/php/7.0/apache2/php.ini with new version
    ERROR: php5 module already enabled, not enabling PHP 7.0
    

    $ php -v yield php 7 version, on browser’s phpinfo(), I got php 5.6. So I removed PHP 5.6, and then executed:

    $ sudo a2enmod php7.0 && sudo service apache2 restart
    

    I installed PHP 7.0.3 this way, then I installed php-pear to install some extensions. Upon calling pear or pecl I’d get a long list of errors, all related to the XML extension not being enabled, even though that extension is enabled by default.

    I had the same problem. I solved by installing the php-pear package again

    How come XML is disabled? Do you have any source with XML enabled? Or any ideas how i can get that working? Migrating a few of my web apps went fine, however XML support is missing :(

    I have the same issue. SimpleXML disables after updating to 7.0.3.

    Found the solution. Just run this:

    sudo apt-get install php7.0-xml
    

    @asb isnt the 7.0.4 current stable version? is it safe to install 7.0.4 or should i stick to 7.0?

    can i simply install the latest stable by the following command?

    sudo apt-get install php7.0.4
    
    Andrew SB
    DigitalOcean Employee
    DigitalOcean Employee badge
    March 11, 2016

    The current version in the PPA that this article recommends is 7.0.4. Though the package name is still php7.0 It will only change for major versions, not minor ones like 7.0.x

    Hi there, and thanks for the tutorial. I have upgraded mine droplet to php 7, and so far so good. After upgrade I bumped into a problem: Error 502.

    • PHP 7.0.4
    • Ubuntu 14.04.
    • Nginx 1.9.6

    I figured out that php7.0-fpm.sock in my installation ended up in: /var/run/php/php7.0-fpm.sock (instead of /var/run/php7.0-fpm.sock like suggested in tutorial)

    So I fixed my path in nginx.conf fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;

    After I updated my path in server block, I got error: *143 connect() to unix:/var/run/php/php7.0-fpm.sock failed (13: Permission denied) ...

    So I updated permissions to sudo chmod 666 /var/run/php/php7.0-fpm.sock, and now everything works

    So my question here is about the permissions, is this ok to have it 666? Or anyone could suggest some better solution to my problem.

    And one more thing, php folder in /var/run/php/php7.0-fpm.sock is ownde by www-data: drwxr-xr-x 2 www-data www-data 80 Mar 14 13:41 php

    Should it be owned by root, like all others in same folder?

    Thanks in advanced

    Edit:

    • have chowned php dir to sudo chown -R nginx:nginx php/ which is mine nginx user, and restored permissions to 0644 for /var/run/php/php7.0-fpm.sock

    Again everything works

    When running php -v in my DO terminal, I get PHP 7.0.4, but when I run phpinfo() on my site, it’s still PHP 5.5. And also I cannot run a2enmod php7.0, it says that the module does not exist.

    I am using Apache & Ubuntu 14.04.

    Does someone know what’s wrong?

    Thanks in advance.

    To install GD and Freetype:

    apt-get install php7.0-gd

    Hi! I followed this tutorial and my PHP7 + nginx + php-fpm install is working like a charm… But how can I install the curl package? I tried:

    sudo apt-get install php7.0-curl
    

    But I get these messages:

    almir@Siteecia:~$ sudo apt-get install php7.0-curl
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following NEW packages will be installed:
      php7.0-curl
    0 upgraded, 1 newly installed, 0 to remove and 151 not upgraded.
    Need to get 26.6 kB of archives.
    After this operation, 154 kB of additional disk space will be used.
    WARNING: The following packages cannot be authenticated!
      php7.0-curl
    Install these packages without verification? [y/N] y
    Err http://ppa.launchpad.net/ondrej/php-7.0/ubuntu/ trusty/main php7.0-curl amd64 7.0.3-5+deb.sury.org~trusty+1
      404  Not Found
    E: Failed to fetch http://ppa.launchpad.net/ondrej/php-7.0/ubuntu/pool/main/p/php7.0/php7.0-curl_7.0.3-5+deb.sury.org~trusty+1_amd64.deb  404  Not Found
    
    E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
    

    What can I do?

    Thanks!

    Guys check out this video tutorial about the topic. It’s really clean a straight to the point. Link : Here

    Have a good day.

    Hello,

    I upgraded php version using this tutorial. Before upgrading I was using redis. Should I now update php configuration files accordingly? or everything already working?

    After upgrading to PHP 7.0 on my Linux Mint 17.3 “Rosa” (Ubuntu 14.04.3) successfully, i tried restarting Apache as it still was telling me to use the PHP 5.5.9 package… Well, it didn’t restart and i can’t get it started… but PHP 7.0 runs well in terminal (and when using “screen” to run a self-written PHP IRC bot)

    I created a brand new LAMP droplet, followed these instructions, php7 works for cli but not the web server. Does anyone have an idea what I am missing?

    Hello, I use LEMP stack on Ubuntu 14.04, after edit this file ‘sudo nano /etc/nginx/sites-enabled/mydomain’, my wordpress site is white at all. Please help! Thanks ^_^

    This guide doesn’t work at all. I booted up a fresh LAMP droplet and followed these instructions with the result that info.php still read PHP5. Hmm…

    I dont have a file ** /var/run/php/php7.0-fpm.sock** after install php7-fpm.

    Thanks you.

    :D

    on apache2 you need also to run this bash command:

    sudo a2enmod php7.0
    

    to enable the php7 module

    This worked perfectly for us.

    Thanks a lot!!

    I have just successfully upgraded two servers Ubuntu 14.04 with Apache, but with a third running NGINX i get the following error: Couldn’t find any package by regex ‘php-7.0-fpm’

    add-apt-repository ppa:ondrej/php OK apt-get update OK apt-get upgrade OK apt-get install php7.0-fpm FAIL

    Any ideas

    Thanks Richard

    Is this relevant information?

    Informative, organized, and no filler. This article rocks! Thank You Brennen.

    Quick question, should I concern guard against HTTProxy vulnerability?

    oh yea, everything is working great. Bye Bye Forge…maybe

    smooth! thanks !

    just want to mention, if anyone try to change .ini file and not working (for me was set the short_open_tag=on) , try to start php-fpm not just nginx

    cheers

    This comment has been deleted

      Hi I am facing the issue, phpinfo() and php -v shows different version after Upgrade to PHP 7 . Please help me to resolve that problem.

      This comment has been deleted

        i got up to sites-enable, editing the default file with my server ip then pasted this unix:/var/run/php/php7.0-fpm.sock over this: fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;

        and when trying to restart nginx i get:

        Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
        

        checking the log brings up:

         nginx.service - A high performance web server and a reverse proxy server
           Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
           Active: failed (Result: exit-code) since Wed 2017-01-18 15:43:04 UTC; 34s ago
          Process: 32670 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited
          Process: 32755 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
         Main PID: 2156 (code=exited, status=0/SUCCESS)
        
        Jan 18 15:43:04 XFCE-SERVER systemd[1]: Starting A high performance web server and a reverse proxy server...
        Jan 18 15:43:04 XFCE-SERVER nginx[32755]: nginx: [emerg] unknown directive "unix:/var/run/php/php7.0-fpm.sock" in /et
        Jan 18 15:43:04 XFCE-SERVER nginx[32755]: nginx: configuration file /etc/nginx/nginx.conf test failed
        Jan 18 15:43:04 XFCE-SERVER systemd[1]: nginx.service: Control process exited, code=exited status=1
        Jan 18 15:43:04 XFCE-SERVER systemd[1]: Failed to start A high performance web server and a reverse proxy server.
        Jan 18 15:43:04 XFCE-SERVER systemd[1]: nginx.service: Unit entered failed state.
        Jan 18 15:43:04 XFCE-SERVER systemd[1]: nginx.service: Failed with result 'exit-code'.
        

        file is this:

        server {
            listen 80 default_server;
            listen [::]:80 default_server ipv6only=on;
        
            root /var/www/html;
            index index.php index.html index.htm;
        
            server_name SERVER_IP_PLACED_HERE;
        
            location / {
                try_files $uri $uri/ =404;
            }
        
            error_page 404 /404.html;
            error_page 500 502 503 504 /50x.html;
            location = /50x.html {
                root /usr/share/nginx/html;
            }
        
            location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                unix:/var/run/php/php7.0-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
            }
        }
        

        For my case, I needed to install php7.0-mcrypt before phpinfo() can detect PHP7. My web server is Nginx by the way.

        Hi, thanks for the instruction, however I get this error and find noway around it:

        Reading package lists... Done
        Building dependency tree       
        Reading state information... Done
        E: Unable to locate package php7.0
        E: Couldn't find any package by regex 'php7.0'
        

        Any idea what’s going on?

        I have upgraded successfully. I am getting the following error when I go to add new plugin page. An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums. (WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)

        If you already have php5.x version installed in your LAMP server. In order to make sure Apache2 uses php7.0 you need to do these additional steps:

        sudo a2dismod php5
        sudo service apache2 restart
        sudo a2enmod php7.0
        sudo service apache2 restart
        

        hi i am getting http 500 error please help!

        This didn’t work for me for Apache. There were no errors. php -v on the command line showed version 7. But phpinfo(); still showed 5.6. I figured out that the last steps of the tutorial are missing.

        I had to run sudo a2enmod php7.0 to activate the php7 module. Then run sudo service apache2 restart to restart Apache.

        For everyone visiting this tutorial in 2018:

        • PHP 7 is the default version in Ubuntu 16.04
        • PHP 7.2 is considered stable now

        No that you might also need to tell Apache to start using php7

        sudo a2dismod php5 #disable old php version
        sudo a2enmod php7.0 #activate new php version
        
        Join the Tech Talk
        Success! Thank you! Please check your email for further details.

        Please complete your information!

        Become a contributor for community

        Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

        DigitalOcean Documentation

        Full documentation for every DigitalOcean product.

        Resources for startups and SMBs

        The Wave has everything you need to know about building a business, from raising funding to marketing your product.

        Get our newsletter

        Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

        New accounts only. By submitting your email you agree to our Privacy Policy

        The developer cloud

        Scale up as you grow — whether you're running one virtual machine or ten thousand.

        Get started for free

        Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

        *This promotional offer applies to new accounts only.