<br />
<b>Warning</b>:  strpos() expects parameter 1 to be string, array given in <b>/home/theserverside/public_html/wp-includes/blocks.php</b> on line <b>20</b><br />
{"id":921,"date":"2015-12-26T20:47:34","date_gmt":"2015-12-26T20:47:34","guid":{"rendered":"http:\/\/www.theserverside.technology\/?p=921"},"modified":"2015-12-26T20:47:34","modified_gmt":"2015-12-26T20:47:34","slug":"","status":"publish","type":"post","link":"https:\/\/www.theserverside.technology\/it\/2015\/12\/26\/how-to-run-php-7-x64-x86-on-windows-azure-pack\/","title":{"rendered":"","raw":""},"content":{"rendered":"","protected":false,"raw":""},"excerpt":{"rendered":"","protected":false,"raw":""},"author":9,"featured_media":922,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_en_post_content":"PHP 7 has been released on December 3rd and its first update (v7.0.1) has been released on December 17th. This new version brings a lot of changes in, including major performance enhancements compared to PHP 5.6 (up to a 2x performance increase!), better (meaning reduced) memory footprint\u00a0plus support for 64bit runtimes. There are of course many other enhancements but those three alone should provide a good reason to update websites to the new version. There could be problems in doing so if you are using deprecated or non-supported code but if your application followed recommendations, you should be able to upgrade to PHP7 and enjoy the enhancements.\r\n\r\nThere are a few handful extensions that bring PHP7 (RC and now RTW) to Azure but those extensions, while providing a good starting point, are not compatible with Windows Azure Pack because of a few hiccups in installation scripts (basically referencing <em>D:<\/em> drive, as in Azure, instead of <em>C:<\/em> as in WAP or using <em>%HOME%<\/em> environment variable to solve this problem and keep the scripts compatible with both). However, this is a good chance to explore once again the flexibility of Windows Azure Pack and configure PHP7 on our own, something useful to update\/upgrade at a later time, if needed, without waiting for someone else to provide a new script for it. Having PHP 7 working could be useful to upgrade compatible applications like Wordpress, which is already compatible with this new version.\r\n\r\nThis tutorial has been tested on <a href=\"http:\/\/www.vaisulweb.com\" target=\"_blank\">VaiSulWeb Cloud Hosting<\/a> services. As our company provides a free account for development and testing, it is easy to start working with PHP7 or ASP.NET 5 by the way. Head up on our website to request your free account.\r\n<h3>[section label=\"Getting started\"]Getting started<\/h3>\r\nAs a first step we need to download PHP7 from its website, taking care to <a href=\"http:\/\/windows.php.net\/download\/\" target=\"_blank\">download Windows binaries<\/a> we need for our tests. Head to download page and look for VC14 x64 <em>Non-Thread-Safe<\/em> (NTS) distribution (<a href=\"http:\/\/windows.php.net\/downloads\/releases\/php-7.0.1-nts-Win32-VC14-x64.zip\" target=\"_blank\">php-7.0.1-nts-Win32-VC14-x64.zip<\/a>) as we want to experience x64 version for our tutorial. Once downloaded, we can unZIP that file and move its contents to our site via FTP. We will upload file contents into <em>\/site\/bin\/php<\/em> folder so our file structure will be like this:\r\n<p style=\"padding-left: 30px;\"><span style=\"color: #008000;\"><em>site\/<\/em><\/span><\/p>\r\n<p style=\"padding-left: 60px;\"><span style=\"color: #008000;\"><em>bin\/<\/em><\/span><\/p>\r\n<p style=\"padding-left: 90px;\"><span style=\"color: #008000;\"><em>php\/<\/em><\/span><\/p>\r\n<p style=\"padding-left: 120px;\"><span style=\"color: #008000;\"><em>dev<\/em><\/span>\r\n<span style=\"color: #008000;\"><em> ext<\/em><\/span>\r\n<span style=\"color: #008000;\"><em> [...]\r\nphp.ini\r\n[...]<\/em><\/span>\r\n<span style=\"color: #008000;\"><em> php-cgi.exe<\/em><\/span>\r\n<span style=\"color: #008000;\"><em> [...]<\/em><\/span><\/p>\r\n<p style=\"padding-left: 30px;\"><span style=\"color: #008000;\"><em>wwwroot<\/em><\/span><\/p>\r\nNow that we uploaded a new PHP distribution to our website, we need to solve two problems before being able to run our own PHP runtime: the first one is telling WAP that we want to use this new version in place of runtimes automatically supported by the platform (v5.3 through v5.5) as shown below:\r\n\r\n[caption id=\"attachment_933\" align=\"aligncenter\" width=\"300\"]<a href=\"http:\/\/www.theserverside.technology\/wp-content\/uploads\/2015\/12\/php7_01.jpg\"><img class=\"size-medium wp-image-933\" src=\"http:\/\/www.theserverside.technology\/wp-content\/uploads\/2015\/12\/php7_01-300x176.jpg\" alt=\"PHP runtimes available through Windows Azure Pack portal\" width=\"300\" height=\"176\" \/><\/a> PHP runtimes available through Windows Azure Pack portal[\/caption]\r\n\r\n&nbsp;\r\n\r\nThe second problem we have is to tell PHP where to find its configuration file, the famous <em>php.ini<\/em>. When using default runtimes, Azure Pack will tell PHP where to find its configuration file but now we want to use a custom runtime so we need to find a way to point PHP to the INI file that we will upload into <em>\/site\/bin\/php\/<\/em> folder. For now, we will just rename <em>php.ini-development file that is shipped with PHP we just downloaded to <\/em><em>php.ini. <\/em><span style=\"text-decoration: underline;\">If you didn't do that earlier, do that now. <\/span>\r\n\r\nNote that we uploaded the runtime outside the <em>wwwroot<\/em> folder that will host our PHP files and all associated assets. While the runtime can be placed everywhere inside our account, including as a subfolder inside <em>wwwroot<\/em>, it's a good habit to place such files outside the Web-accessible folder for security reasons. That's the same folder structure used by the new ASP.NET 5 runtime.\r\n<h3>[section label=\"How to use the new runtime\"]How to use the new runtime<\/h3>\r\nNow that we uploaded the new runtime, we need to switch the handler for PHP websites. Settings for supported runtimes don't appear inside your control panel as the path is automatically injected into the runtime when <em>php-cgi.exe<\/em> is called to run a script\/page. However, default settings know nothing about PHP7 and its files so we need to change that and tell IIS where <em>php-cgi.exe<\/em> actually is.\r\n\r\nThis might look difficult and there are multiple ways to do that, actually, but the simplest way is to add a new entry for PHP files in our <em>handler mappings<\/em> section of our website as shown below:\r\n\r\n[caption id=\"attachment_938\" align=\"aligncenter\" width=\"300\"]<a href=\"http:\/\/www.theserverside.technology\/wp-content\/uploads\/2015\/12\/php7_02.jpg\"><img class=\"size-medium wp-image-938\" src=\"http:\/\/www.theserverside.technology\/wp-content\/uploads\/2015\/12\/php7_02-300x176.jpg\" alt=\"The new handler mappings entry to tell Azure Pack what runtime to use with PHP files.\" width=\"300\" height=\"176\" \/><\/a> The new handler mappings entry to tell Azure Pack what runtime to use with PHP files.[\/caption]\r\n\r\nDon't forget to save settings and restart your website. Now your website will run the new runtime when invoking a PHP file but we have another problem to solve.\r\n<h3>[section label=\"Telling PHP where its configuration file is\"]Telling PHP where its configuration file is - the easy way<\/h3>\r\nThere are a couple of ways to tell PHP where to look for its configuration file. The easiest and quickest way is to explicitly\u00a0tell PHP its full path and file\u00a0name via <em>handler mappings<\/em>\u00a0section of our portal. Each time php-cgi.exe will run, it will load the configuration file that you provided and since those FastCGI processes will be reused, that will happen just once per several thousands requests. Configuring the handler is rather easy, as confirmed by the screenshot below:\r\n\r\n[caption id=\"attachment_946\" align=\"aligncenter\" width=\"300\"]<a href=\"http:\/\/www.theserverside.technology\/wp-content\/uploads\/2015\/12\/php7_03.jpg\"><img class=\"size-medium wp-image-946\" src=\"http:\/\/www.theserverside.technology\/wp-content\/uploads\/2015\/12\/php7_03-300x176.jpg\" alt=\"How to tell PHP where to look for its configuration file\" width=\"300\" height=\"176\" \/><\/a> How to tell PHP where to look for its configuration file[\/caption]\r\n\r\nAs you can see, you just add a path to the <em>php.ini<\/em> file using the \"-c\" argument supported by <em>php-cgi.exe<\/em>. You can also use %HOME% environment variable to avoid having to pass the full physical path to the file, usually located inside the PHP folder itself but that can be located where you want.\r\n\r\nAfter restarting the website, if you now try to run a PHP file, like for example a simple <em>phpinfo()<\/em> call, you will be greeted by the familiar information output, as shown below:\r\n\r\n[caption id=\"attachment_948\" align=\"aligncenter\" width=\"300\"]<a href=\"http:\/\/www.theserverside.technology\/wp-content\/uploads\/2015\/12\/php7_04.jpg\"><img class=\"size-medium wp-image-948\" src=\"http:\/\/www.theserverside.technology\/wp-content\/uploads\/2015\/12\/php7_04-300x204.jpg\" alt=\"PHP 7.0.1 running on Windows Azure Pack\" width=\"300\" height=\"204\" \/><\/a> PHP 7.0.1 running on Windows Azure Pack[\/caption]\r\n\r\nWell done ! But how can we say if we're actually running the 64bit version of PHP 7.0.1 ? There's an easy way to do that thanks to this <a href=\"http:\/\/stackoverflow.com\/questions\/6303241\/find-windows-32-or-64-bit-using-php\" target=\"_blank\">Stackoverflow script<\/a>:\r\n<div style=\"padding-left: 30px; font-size: 0.7em;\"><span style=\"color: #008000;\"><em><span class=\"pun\">&lt;?<\/span><span class=\"pln\">php\r\n<\/span><span class=\"kwd\">switch<\/span><span class=\"pun\">(<\/span><span class=\"pln\">PHP_INT_SIZE<\/span><span class=\"pun\">)<\/span> <span class=\"pun\">{<\/span><\/em><\/span>\r\n<p style=\"padding-left: 60px;\"><span style=\"color: #008000;\"><em><span class=\"kwd\">case<\/span> <span class=\"lit\">4<\/span><span class=\"pun\">:<\/span><span class=\"pln\">\r\necho <\/span><span class=\"str\">'32-bit version of PHP'<\/span><span class=\"pun\">;<\/span><\/em><\/span>\r\n<span style=\"color: #008000;\"> <em> <span class=\"kwd\">break<\/span><span class=\"pun\">;<\/span><\/em><\/span><\/p>\r\n<p style=\"padding-left: 60px;\"><span style=\"color: #008000;\"><em><span class=\"kwd\">case<\/span> <span class=\"lit\">8<\/span><span class=\"pun\">:<\/span><span class=\"pln\">\r\necho <\/span><span class=\"str\">'64-bit version of PHP'<\/span><span class=\"pun\">;<\/span><\/em><\/span>\r\n<span style=\"color: #008000;\"> <em> <span class=\"kwd\">break<\/span><span class=\"pun\">;<\/span><\/em><\/span><\/p>\r\n<p style=\"padding-left: 60px;\"><span style=\"color: #008000;\"><em><span class=\"kwd\">default<\/span><span class=\"pun\">:<\/span><span class=\"pln\">\r\necho <\/span><span class=\"str\">'PHP_INT_SIZE is '<\/span> <span class=\"pun\">.<\/span><span class=\"pln\"> PHP_INT_SIZE<\/span><span class=\"pun\">;<\/span><\/em><\/span><\/p>\r\n<p style=\"padding-left: 30px;\"><span style=\"color: #008000;\"><em><span class=\"pun\">}<\/span><\/em><\/span><\/p>\r\n\r\n<\/div>\r\nIf you simply put this file in your Web root (for example as <em>check64.php<\/em>) you can run it to get a confirmation that you're running 64bit PHP 7.\r\n<h3>[section label=\"Optimizing your PHP7 experience\"]Optimizing your PHP7 experience<\/h3>\r\nNow that PHP7 is running, there are a couple of settings that can be changed to provide better performances. First of all, PHP 5.5+ now provides an internal module to implement OpCache functionalities. Many websites used a PHP accelerator to achieve better performances through various layer of caching. On Windows platform, WinCache has been long used to speed up PHP. Microsoft released a new version of WinCache developed for PHP 7 but (since PHP 5.5) has deprecated its opcode caching and suggests to enable PHP own <em>OpCache<\/em> to implement those functionalities.\r\n\r\nSo, first of all, let's enable PHP own OpCache as recommended\u00a0by adding to our <i>php.ini<\/i> :\r\n<div style=\"padding-left: 30px; font-size: 0.8em;\"><span style=\"color: #008000;\"><em>zend_extension=C:\\home\\site\\bin\\php\\ext\\php_opcache.dll<\/em><\/span><\/div>\r\n<div style=\"padding-left: 30px;\"><\/div>\r\n<div style=\"padding-left: 30px;\"><span style=\"color: #008000;\"><em>[opcache] <\/em><\/span>\r\n<span style=\"color: #008000;\"><em>opcache.enable=1<\/em><\/span><\/div>\r\nright after this line:\r\n<p style=\"padding-left: 30px; font-size: 0.8em;\"><span style=\"color: #008000;\">engine=On<\/span><\/p>\r\nSince that is a Zend module, we need to add it early inside <em>php.ini<\/em> so adding it right after <em>engine<\/em> directive is a good place. Note that we cannot use %HOME% environment variable here so we need to type the physical path.\u00a0There are many settings that can be customized for OpCache but that single directive is enough to enable it using standard settings. Don't forget to restart your website. You should now be able to see OpCache running for your website as shown below:\r\n\r\n[caption id=\"attachment_954\" align=\"aligncenter\" width=\"300\"]<a href=\"http:\/\/www.theserverside.technology\/wp-content\/uploads\/2015\/12\/php7_05.jpg\"><img class=\"size-medium wp-image-954\" src=\"http:\/\/www.theserverside.technology\/wp-content\/uploads\/2015\/12\/php7_05-300x204.jpg\" alt=\"Zend OpCode enabled for your website\" width=\"300\" height=\"204\" \/><\/a> Zend OpCache enabled for your website[\/caption]\r\n\r\nNow we can also add WinCache to the mix. Let's first download it from:\r\n\r\n<a href=\"http:\/\/sourceforge.net\/projects\/wincache\/files\/wincache-2.0.0\/\" target=\"_blank\">http:\/\/sourceforge.net\/projects\/wincache\/files\/wincache-2.0.0\/<\/a>\r\n\r\nRemember to download file <em>wincache-2.0.0.2-7.0-nts-vc14-x64.exe<\/em> to get the 64bit version of that file. Now upload file <em>php_wincache.dll<\/em> to the <em>\/site\/bin\/php\/ext<\/em> folder of your website and let's edit <em>php.ini<\/em> again to include\r\n<p style=\"padding-left: 30px;\"><em><span style=\"color: #008000;\">extension = php_wincache.dll<\/span><\/em><\/p>\r\nSave <em>php.ini<\/em> and restart website to ensure the new directive is active. You should see <em>WinCache<\/em> among loaded modules for your <em>phpinfo<\/em> output. Here again, default settings.\r\n<h3>[section label=\"Summary\"]Summary<\/h3>\r\nThis tutorial aimed at showing how flexible Windows Azure Pack is by even allowing to customize the environment to include runtimes not officially supported yet. We have been able to get control about how to handle PHP files by changing default behavior, deploy a new runtime, switch to 64bit processes, customize <em>php.ini<\/em> and add\u00a0both OpCache and WinCache and we didn't\u00a0need support\u00a0by the hoster for\u00a0any of such operations.\r\n\r\nAt <a href=\"http:\/\/www.vaisulweb.com\" target=\"_blank\">VaiSulWeb<\/a>, we are switching toward this new model for our Web hosting services and we are currently hosting any size of website, from very small personal websites to very big ones (with millions of displayed pages per month) and our customers are enjoying unmatched flexibility and performances. I have to recommend to give our Cloud Hosting services a try by activating a free account that will allow you to test new runtimes like ASP.NET 5 or PHP 7. While such accounts don't provide 64bit support we discussed here, they allow most of the functionalities discussed in this post.\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n&nbsp;","_en_post_name":"how-to-run-php-7-x64-x86-on-windows-azure-pack","_en_post_excerpt":"","_en_post_title":"How to run PHP 7 x64\/x86 on Windows Azure Pack","_it_post_content":"","_it_post_name":"","_it_post_excerpt":"","_it_post_title":"","edit_language":"it"},"categories":[2,91],"tags":[195,167,194],"_links":{"self":[{"href":"https:\/\/www.theserverside.technology\/it\/wp-json\/wp\/v2\/posts\/921"}],"collection":[{"href":"https:\/\/www.theserverside.technology\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.theserverside.technology\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.theserverside.technology\/it\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.theserverside.technology\/it\/wp-json\/wp\/v2\/comments?post=921"}],"version-history":[{"count":38,"href":"https:\/\/www.theserverside.technology\/it\/wp-json\/wp\/v2\/posts\/921\/revisions"}],"predecessor-version":[{"id":965,"href":"https:\/\/www.theserverside.technology\/it\/wp-json\/wp\/v2\/posts\/921\/revisions\/965"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.theserverside.technology\/it\/wp-json\/wp\/v2\/media\/922"}],"wp:attachment":[{"href":"https:\/\/www.theserverside.technology\/it\/wp-json\/wp\/v2\/media?parent=921"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.theserverside.technology\/it\/wp-json\/wp\/v2\/categories?post=921"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.theserverside.technology\/it\/wp-json\/wp\/v2\/tags?post=921"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}