{"id":1993,"date":"2015-12-30T11:01:16","date_gmt":"2015-12-30T10:01:16","guid":{"rendered":"http:\/\/denbeke.be\/blog\/?p=1993"},"modified":"2015-12-30T11:05:18","modified_gmt":"2015-12-30T10:05:18","slug":"migratingupdating-from-php-5-to-php-7-on-os-x-macports","status":"publish","type":"post","link":"https:\/\/denbeke.be\/blog\/servers\/migratingupdating-from-php-5-to-php-7-on-os-x-macports\/","title":{"rendered":"Migrating\/updating from PHP 5 to PHP 7 on OS X (MacPorts)"},"content":{"rendered":"<p><a href=\"http:\/\/denbeke.be\/blog\/servers\/migratingupdating-from-php-5-to-php-7-on-os-x-macports\/attachment\/php-7-logo\/\" rel=\"attachment wp-att-1996\"><img loading=\"lazy\" class=\"alignright wp-image-1996 size-medium\" src=\"http:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/12\/PHP-7-logo-300x151.png\" alt=\"PHP 7 logo\" width=\"300\" height=\"151\" srcset=\"https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/12\/PHP-7-logo-300x151.png 300w, https:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/12\/PHP-7-logo.png 727w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a>PHP 7 was released earlier this month,\u00a0time for me to upgrade my development environment to keep up to date with this new version. I had already installed PHP 5.6 using MacPorts, so this guide is about upgrading a PHP 5 installation to a PHP 7. If you need help for actually installing PHP\/Apache\/MySQL, read this blogpost:\u00a0<a href=\"http:\/\/denbeke.be\/blog\/webdevelopment\/installing-mamp-mac-os-x-apache-mariadb-php-using-macports\/\">Installing MAMP (Mac OS X Apache MariaDB PHP) using MacPorts<\/a>.<\/p>\n<h3 id=\"install-php-7\">Install PHP 7<\/h3>\n<p>Install PHP 7, and the extensions you need:<\/p>\n<pre><code>$ sudo port install php70\r\n$ sudo port install php70-cgi php70-gd php70-curl php70-intl php70-iconv php70-gettext php70-mbstring php70-imap php70-mcrypt php70-xmlrpc php70-mysql php70-openssl php70-sockets php70-zip php70-tidy php70-opcache php70-xsl php70-sqlite<\/code><\/pre>\n<p>Install the Apache handler for PHP 7:<\/p>\n<pre><code>$ sudo port install php70-apache2handler<\/code><\/pre>\n<h3 id=\"activating-php-7\">Activating PHP 7<\/h3>\n<p>Once installed you must activate the handler:<\/p>\n<pre><code>$ cd \/opt\/local\/apache2\/modules\r\n$ sudo \/opt\/local\/apache2\/bin\/apxs -a -e -n php7 mod_php70.so<\/code><\/pre>\n<p>This may lead to two PHP modules being loaded in the Apache configuration file. If <code>phpinfo()<\/code> still uses PHP 5.6 (or any other PHP version), you need to uncomment the PHP 5 module in <code>\/opt\/local\/apache2\/conf\/httpd.conf<\/code>.<\/p>\n<pre><code>#LoadModule php5_module        modules\/mod_php56.so\r\nLoadModule php7_module        modules\/mod_php70.so<\/code><\/pre>\n<p>At the bottom of the same file, you need to add this line for PHP 7 (and possibly delete the same line for PHP 5):<\/p>\n<pre><code>Include conf\/extra\/mod_php70.conf<\/code><\/pre>\n<p>Now we have configured PHP 7 and Apache, we need to restart Apache:<\/p>\n<pre><code>$ sudo port unload apache2; \\\r\n  sudo port load apache2<\/code><\/pre>\n<p>or<\/p>\n<pre><code>$ sudo \/opt\/local\/etc\/LaunchDaemons\/org.macports.apache2\/apache2.wrapper restart<\/code><\/pre>\n<p>Select PHP 7 as the current PHP version:<\/p>\n<pre><code>$ sudo port select php php70<\/code><\/pre>\n<p>You can verify this by executing <code>$ sudo port select --list php<\/code>:<\/p>\n<pre><code>Available versions for php:\r\n    none\r\n    php55\r\n    php56\r\n    php70 (active)<\/code><\/pre>\n<h3 id=\"verifying-the-php-version\">Verifying the PHP version<\/h3>\n<p>Verify the executable using PHP cli:<\/p>\n<pre><code>$ php -v\r\nPHP 7.0.1 (cli) (built: Dec 29 2015 19:22:02) ( NTS )\r\nCopyright (c) 1997-2015 The PHP Group\r\nZend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies<\/code><\/pre>\n<p>Now create a test PHP file on your webserver and verify in the browser if Apache uses the correct PHP version:<\/p>\n<pre><code>&lt;?php phpinfo(); ?&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>PHP 7 was released earlier this month,\u00a0time for me to upgrade my development environment to keep up to date with this new version. I had already installed PHP 5.6 using MacPorts, so this guide is about upgrading a PHP 5 installation to a PHP 7. If you need help for actually installing PHP\/Apache\/MySQL, read this [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[227],"tags":[213,251,149,215],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v15.6.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Migrating\/updating from PHP 5 to PHP 7 on OS X (MacPorts) &ndash; DenBeke<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/denbeke.be\/blog\/servers\/migratingupdating-from-php-5-to-php-7-on-os-x-macports\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Migrating\/updating from PHP 5 to PHP 7 on OS X (MacPorts) &ndash; DenBeke\" \/>\n<meta property=\"og:description\" content=\"PHP 7 was released earlier this month,\u00a0time for me to upgrade my development environment to keep up to date with this new version. I had already installed PHP 5.6 using MacPorts, so this guide is about upgrading a PHP 5 installation to a PHP 7. If you need help for actually installing PHP\/Apache\/MySQL, read this [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/denbeke.be\/blog\/servers\/migratingupdating-from-php-5-to-php-7-on-os-x-macports\/\" \/>\n<meta property=\"og:site_name\" content=\"DenBeke\" \/>\n<meta property=\"article:published_time\" content=\"2015-12-30T10:01:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2015-12-30T10:05:18+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/12\/PHP-7-logo-300x151.png\" \/>\n<meta name=\"twitter:card\" content=\"summary\" \/>\n<meta name=\"twitter:creator\" content=\"@MthsBk\" \/>\n<meta name=\"twitter:site\" content=\"@MthsBk\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\">\n\t<meta name=\"twitter:data1\" content=\"2 minutes\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/denbeke.be\/blog\/#website\",\"url\":\"https:\/\/denbeke.be\/blog\/\",\"name\":\"DenBeke\",\"description\":\"Mathias Beke\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/denbeke.be\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/denbeke.be\/blog\/servers\/migratingupdating-from-php-5-to-php-7-on-os-x-macports\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"http:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/12\/PHP-7-logo-300x151.png\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/denbeke.be\/blog\/servers\/migratingupdating-from-php-5-to-php-7-on-os-x-macports\/#webpage\",\"url\":\"https:\/\/denbeke.be\/blog\/servers\/migratingupdating-from-php-5-to-php-7-on-os-x-macports\/\",\"name\":\"Migrating\/updating from PHP 5 to PHP 7 on OS X (MacPorts) &ndash; DenBeke\",\"isPartOf\":{\"@id\":\"https:\/\/denbeke.be\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/denbeke.be\/blog\/servers\/migratingupdating-from-php-5-to-php-7-on-os-x-macports\/#primaryimage\"},\"datePublished\":\"2015-12-30T10:01:16+00:00\",\"dateModified\":\"2015-12-30T10:05:18+00:00\",\"author\":{\"@id\":\"https:\/\/denbeke.be\/blog\/#\/schema\/person\/386878f712fe3fe22227216f087772dc\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/denbeke.be\/blog\/servers\/migratingupdating-from-php-5-to-php-7-on-os-x-macports\/\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/denbeke.be\/blog\/#\/schema\/person\/386878f712fe3fe22227216f087772dc\",\"name\":\"Mathias Beke\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/denbeke.be\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/015ba35e6ce4f5859e3888ca99807575?s=96&d=mm&r=g\",\"caption\":\"Mathias Beke\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts\/1993"}],"collection":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/comments?post=1993"}],"version-history":[{"count":3,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts\/1993\/revisions"}],"predecessor-version":[{"id":1997,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts\/1993\/revisions\/1997"}],"wp:attachment":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/media?parent=1993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/categories?post=1993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/tags?post=1993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}