# How to emulate package.php?

Sep 19, 2011 at 10:14 AM

Hi,

I was following this blog post here which explains how to utilize "Windows Azure Command-line Tools for PHP Developers" in order to create a package of a sample PHP file.

That project seems now deprecated with a followup link to this project.  Therefore I have downloaded the latest of  PHPAzure project here and hoped to continue where I had left off.

According to the blog this command line should create the PHPInfo sample page:

php package.php --project=PHPInfo --phpRuntime="C:\Program Files\PHP" --source="%TMP%\PHPInfo" --runDevFabric

However most of this parameters don't exist anymore.

I tried to follow up the help and came up with this:

package create --InputPath="C:\projects\PHPInfo" --RunDevFabric

However I get now the error message:

Error: Could not locate ServiceDefinition.csdef at C:\projects\PHPInfo/ServiceDefinition.csdef.

With the former tool this step was not required. Since I am new to this, may you please be so kind and explain to me how I would create a Service definition file in order to host my small PHP sample page?

FYI, my final goal is to host WordPress on Azure, hence I was following the Blog above in first place.

Houman

Editor
Sep 19, 2011 at 4:55 PM

Houman,

Indeed the other project has been deprecated. A new set of command line tools has been built which is much more powerful than the single package.php from the deprecated project. Due to an entirely revamped PHP SDK the new command line tools have necessarily made some changes over the previous package.php. The article you refer to above should have also been deprecated and you should use the following article:

http://azurephp.interoperabilitybridges.com/articles/build-and-deploy-a-windows-azure-php-application

Since you are interested in WordPress you may also want to take a look at these articles:

http://azurephp.interoperabilitybridges.com/articles/how-to-deploy-wordpress-using-the-windows-azure-sdk-for-php-wordpress-scaffold
http://azurephp.interoperabilitybridges.com/articles/how-to-deploy-wordpress-multisite-to-windows-azure-using-the-wordpress-scaffold

If you have any other questions let me know.

Ben Lobaugh

Sep 20, 2011 at 12:01 AM
Edited Sep 20, 2011 at 12:05 AM

Hi Ben,

I really appreciate your help on this.  Your blog has been extremely helpful and got me finally going forwards.

I have in fact been able to go through all Wordpress steps until deployment.

Just to be sure I have done everything correctly, when running the scaffolder:

scaffolder run -s="C:\temp\WordPress.phar" -out="C:\temp\WordPress" -DB_NAME=**** -DB_USER=****@**** -DB_PASSWORD=**** -DB_HOST=****.database.core.windows.net -sync_account=**** -sync_key=****

1) is sync_account simply the name of my storage? or rather the Blob url? Thats not very clear, I chose the name.
2) Same goes with sync_key; is primary key or secondary key required? (I chose the primary one)
3) DB_HOST is meant to be the Fully Qualified DNS name, correct?
4) DB_USER is the administrator login on the database? Or do I have to create a different user?

After packaging and deploying it through the portal successfully,  I get this error message, when browing to the DNS name:

# Error establishing a database connection (HTTP 500 Internal Server Error)

So I wonder what went wrong and couldnt find a clue.

You also had mentioned " NOTE: Inside of this storage account you will need to create a public container called 'wpsync'"

5) I didn't know how to do this in portal.  There is no way to create any container. Could that have been the issue?

Houman

Editor
Sep 20, 2011 at 12:45 AM

Houman,

I do not think there is currently a way in the portal to add containers. I use the Azure Storage Explorer and it seems to work fairly well. Just put in your storage credentials and you can work with blobs, queues and tables. http://azurestorageexplorer.codeplex.com/

So the good news is that if you used the WordPress scaffold from the article it uses the service configuration in the Portal for configuration information, so you should not have to wait to redeploy. For the rest of this log into the Portal and try everything from there.

First off, WordPress does not create a database itself. Have you created the database to connect to?

1) sync_account is your storage endpoint, so if you chose 'fabrikam' as your name then your blobs, for example, would be at 'fabrikam.blob.core.windows.net'. In this instance you need just the endpoint of 'fabrikam'

2) sync_key is usually the primary key, however I believe your secondary key should work as well. It is more of a security feature to have the secondary key but either can provide access.

3) DB_HOST is the FQDN to your database server, E.G. myfabrikamdbserver.database.windows.net (I see that I have .core. in the article and this could be the source of your issues if you have it in your command as well)

4) DB_USER should be a new user account simply for security reasons. And take note that unlike MySQL you must supply not only the username, but also the name of the database server, E.G. houmie@myfabrikamdbserver

5) You can use the Azure Storage Explorer to create the 'wpsync' container. Make sure you do not set the container as private. As of when the WP article was written the sync tool did not automatically create this container and it would cause your deployment to fail to start. It may create the container itself now, but better safe than sorry.

Let me know if you need anything else.

Ben Lobaugh

Sep 20, 2011 at 8:01 AM

Hi Ben,

Many thanks for your detailed answer. I was able to pinpoint the problem.  It was the missing @DBHOST right behind the DB_USERNAME. You had indeed mentioned it in your blog, however I thought you had specified your username with an @ on purpose and didn't think about it any further. It is unusual since the DB_HOST is asked for separately anyway.

Thanks for the tip with Azure Explorer, it seems like a great tool. The good news is the wpsync is already created automatically, and I didn't need to do anything. I can now see the welcome Wordpress screen and it feels great seeing this after 2 weeks of tinkering with it. :)

I have continued with your blog and have also setup the Windows Azure Storage Plugin.  I could see you have created a new container there called assets and use that instead of wpsync in the plugin settings.

1) I have tried to do something similar like you and created in Azure Explorer a new container called 'assets'. Right after I was asked to choose the type for it. Which one shall I choose -> Public Container, Public Blob or Private?  I chose public container for the time being.

Right after I tried to upload a theme in Appearance and got this error message though:

2) Do you have any idea what could have caused this?

3) I remember in the blog you had mentioned that everything needs to be done to the folders before packaging it, otherwise whenever the instance or webrole is updated or simply restarted, the entire direct changes would be lost, which is very scary.  I thought the Windows Azure Storage Plugin would actually be a remedy to the problem, unless I have misunderstood it.  If I have misunderstood it and I have to include the theme right before packaging, do you know if its straight forward to integrate this into the php installation from start? I have yet to google this...

Again many thanks for helping me getting that far,

Houman

Editor
Sep 20, 2011 at 6:44 PM

You will generally want to use public containers for anything related to WordPress.

As far as the theme installation, I tried installing a theme through the theme browser and by uploading a zip archive. Both ways worked perfectly. I am going to guess that the location is not working because \0 is a special character. Which version of the Windows Azure SDK are you using? 1.5 is available, but if you update you will also need to update your PHP SDK. There are two things I would try at this point, first try clicking on the ReImage button after highlighting your deployment in the Portal. Possibly something corrupted during deployment. The other would be to setup Remote Desktop and get in there to see what is going on. Brian Swan has a great RDP tutorial at http://blogs.msdn.com/b/silverlining/archive/2011/09/01/windows-azure-remote-desktop-connectivity-for-php-applications.aspx

The storage plugin will not actually copy your themes to Windows Azure Storage. It is designed to make sure that any media files you upload will be on Windows Azure Storage and available to all running instances, and that they will live between instance restarts. The file sync tool can be used to do what you are wanting to accomplish, but not very efficiently as it is supposed to only make sure the Azure specific database files are kept up to date.

It is very easy to install themes and plugins before deploying your WordPress site. Simply unzip the theme or plugin archive to wp-content/themes or wp-content/plugins and you are done.

Sep 21, 2011 at 7:40 AM
Edited Sep 21, 2011 at 7:59 AM

Hi Ben,

Many Thanks for your tips.  Yes I do have the latest Azure SDK 1.5 installed and PHP 5.8.3 Non thread safe + PHP Azure 4.0.3

I have reimaged it as you suggested without any change.  Then I tried to add the RDP to it as you had suggested to see whats happening there. For that I needed to re-deploy it. And since then I am experiencing some problems.

Whenever I try to scaffold WordPress again I get this error message now out of nowhere:

Extracting resources...
Extracted resources.
Applying transforms...
Applied transforms.
Creating temporary build directory: C:\Projects\VC\WordPress\tmp
8: Error in phar://C:/Projects/VC/WordPress.phar/index.php:297 - Use ofundefined constant CURLOPT_RETURNTRANSFER - assumed 'CURLOPT_RETURNTRANSFER'
8: Error in phar://C:/Projects/VC/WordPress.phar/index.php:298 - Use ofundefined constant CURLOPT_HEADER - assumed 'CURLOPT_HEADER'
8: Error in phar://C:/Projects/VC/WordPress.phar/index.php:299 - Use ofundefined constant CURLOPT_FOLLOWLOCATION - assumed 'CURLOPT_FOLLOWLOCATION'
8: Error in phar://C:/Projects/VC/WordPress.phar/index.php:300 - Use ofundefined constant CURLOPT_ENCODING - assumed 'CURLOPT_ENCODING'
8: Error in phar://C:/Projects/VC/WordPress.phar/index.php:301 - Use ofundefined constant CURLOPT_USERAGENT - assumed 'CURLOPT_USERAGENT'
8: Error in phar://C:/Projects/VC/WordPress.phar/index.php:302 - Use ofundefined constant CURLOPT_AUTOREFERER - assumed 'CURLOPT_AUTOREFERER'
8: Error in phar://C:/Projects/VC/WordPress.phar/index.php:303 - Use ofundefined constant CURLOPT_CONNECTTIMEOUT - assumed 'CURLOPT_CONNECTTIMEOUT'
8: Error in phar://C:/Projects/VC/WordPress.phar/index.php:304 - Use ofundefined constant CURLOPT_TIMEOUT - assumed 'CURLOPT_TIMEOUT'
8: Error in phar://C:/Projects/VC/WordPress.phar/index.php:305 - Use ofundefined constant CURLOPT_MAXREDIRS - assumed 'CURLOPT_MAXREDIRS'

Fatal error: Call to undefined function curl_init() in phar://C:/Projects/VC/WordPress.phar/index.php on line 308

One other weird issue I kept having before this problem started was that whenever I tried to test package it on my local cloud, my PHP installation would somehow get corrupted.

package create -in="C:\Projects\VC\WordPress" -out="C:\Projects\VC\Test" -dev=true

I kept getting a red error popup with the title PHP.exe, saying in the message body "Diagnostics.dll" was not registered. The only way getting rid of it was to restart the PC and reinstall PHP 5.8.3 non-tread safe again. In case you came ever across that...

UPDATE:

I have reinstalled PHp 5.8.3 again and now the scaffolding works.  How comes my PHP installation keeps getting corrupted? Perhaps I shouldnt run the Azure SDK CMD in Admin mode?

Thank you,

Houman

Editor
Sep 21, 2011 at 4:02 PM

Houman,

I am guessing from that error when you reinstalled PHP you did not enable curl. As to why you are needing to reinstall PHP each time, that is new to me. I am running 5.3.5 right now and will upgrade to 5.3.8 and report back if I have the same issue.

Ben

Coordinator
Sep 23, 2011 at 8:45 AM

The reason for your PHP getting corrupted is that when you "package create .... -dev=true", the scaffolded package wil be run in development fabric. Development fabric will reconfigure your PHP.ini based on the settings from the WordPress scaffolder (check /php/php.ini). Best thing to do there is to verify your own PHP.ini, near the end you can clearly see what's been added by running in dev fabric.

Best regards,
Maarten

Sep 25, 2011 at 2:58 PM
Edited Sep 25, 2011 at 2:58 PM

Hi Ben,
Hi Maarten,

Many Thanks for your help. I have finally made it work. Microsoft Azure Technical Support were so helpful getting me up to speed. It turned out the Theme I had purchased was somehow compressed in a non-standard way.  I have unzipped the Theme and zipped it back with 7Zip -> Deflat32 and then I could simply upload it and it would work.

@Maarten, thanks for explaining why my PHP gets corrupted, I will keep an eye on that next time.

The last bit that I still haven't got around to fix is that I can't post any page or comment on my page despite being logged in as an admin.

I keep getting

"You are not allowed to edit this post."

I have done some reseach and some claim these were bad entires in the database, which I couldn't replicate. I wonder if its a Azure thing.

Have you guys had similar issues?

Many Thanks,

Houman

Sep 25, 2011 at 8:46 PM

Guys,

I have excellent news.  I have deleted all instances and even the database.  When I was about to create a new database I noticed a checkbox for the firewall rules:

Allow other Windows Azure Services to access this server.

Last time I had forgotten to tick this, and without that it wouldn't work.

Now that I have it ticked, it all works smoothly. Thanks again for all your kind help.

I am so surprised how fast it is on the cloud. My current instance with GoDaddy is crawling compared to this.

Regards,

Houman

Editor
Sep 26, 2011 at 3:30 AM

Houman,

Excellent. I am glad you got it working and that checkbox is good to know about for future troubleshooting!

Happy blogging

Ben

Sep 26, 2011 at 11:14 PM

Thank you Ben.

I have a few more questions that are Azure Cloud related:

1) Once WordPress is installed on the Azure and I make changes to the PermaLinks Settings, WordPress tells me "Remove write access on web.config file now!"  Do I simply RDP into the instance and make web.config readonly over the Windows Explorer's right click? Or how should this be done?

2) What is the best way to link my domain url to my cloud application? Is Forwarding the whole domain better or rather just setting the CNAME in DNS entry as described in here: http://blog.smarx.com/posts/custom-domain-names-in-windows-azure  Keeping SEO optimizations in mind, what is your recommendation here?

3) Now when I start setting up my website, adding Posts, new Pages, a Forum and users being able to add a new posts etc. What will happen to all these data if my cloud instance crashes for any reason and I had to restart it? Would all the data be wiped or is it still safely saved in the storage despite a server outage and restart? Do I have to backup it myself or can I trust Microsoft taking care of that?

4) What happens if I had to update the next WordPress patch? I couldn't just Scaffold it from scratch and wipe the existing stuff, right?  Is there a way to backup the data before doing such updates, in case anything goes wrong?

Many Thanks for clarification,
Houman

Editor
Sep 26, 2011 at 11:51 PM

Houman,

Good to see you really digging into Azure.

1) RDP is how I would do it. FTP is not enabled by default so I think RDP is probably the only method you have available. Make sure it is still readable when you change permissions ;)

2) I believe a CNAME is currently the only option you have with Windows Azure. I tried looking for A records but all the documentation I found keeps pointing to CNAME. Using a CNAME is not supposed to hurt your SEO, and even though it can be used as a sort of forward it is transparent to users who will still see your domain in their URL bar. Something you need to be aware of is that WordPress is setup to use a specific domain and your site will break if you change it without letting WordPress know. There is an excellent article in the codex on moving a WP site you should read at http://codex.wordpress.org/Changing_The_Site_URL#Relocate_method. The relocate method looks simple, though I have not tried it yet. Editing the database is an easy route that has always worked for me.

3) Did you setup the storage plugin? If so as long as you have not installed themes or plugins you should not lose anything. All your post text content will be stored in SQL Azure and the storage plugin lets you put all your media files into Azure Storage, which is durable and will not go away if your instance gets rebooted or the deployment is deleted.

4) You _could_ update inside of WP Admin, but that brings issues when your instance is rebooted. You should definitely create a new package and deploy that. As long as your database and storage connection strings are accurate all your data will still be there. That said, it might actually be a good idea to run the updater inside of WP before redeploying with the new package. This will allow WP to run the upgrade scripts that may need to alter tables and such. Though it may, I am not aware if WordPress will detect there is an existing database and automatically run the upgrade scripts on a new deployment.

Anything else just let me know,

Ben

Sep 28, 2011 at 1:26 PM
Edited Sep 28, 2011 at 1:26 PM

Hi Ben,

I have now set a CNAME on my domain pointing to the Staging URl of my cloud app.  It works fine.  The next thing I need to keep in mind - as you suggested - is editing the database entry to update the staging url to the production url. That should hopefully go smoothly once my site is ready.

Yes, I have activated the storage plugin. Now that you have explained it this way, I feel more comfortable not loosing any data.  The only thing is that the plugin is set within the config file by default to update the storage every 7200 seconds (2 hours). Is this recommended?

Bullet point 4 is very tricky.  I remember when I tried once to re-install a package for a second time without having the database wiped before hand, the cloud instance got never installed properly and kept hanging. Maybe I did something wrong though as it was in the beginning and I was even less experienced. But it felt as if the database was already populated the re-deployment of a new package would cause the system to hang, since it wouldn't know what to do with the existing tables.

However if its indeed able to update the existing tables right after the new deployment of a new package, then nothing needs to be done and an upgrade would be very easy.  Unless its best to update it first from WP-admin so that the tables are correctly updated - as you had suggested - and then re installing the new package. I just wonder if this would still hang or actually recognize the existing updated db and get along with it.

I wonder; is there a way to edit the config of Azure-PhP to download an older version of WordPress? Then I could scaffold a new package with the older version and try this scenario on my cloud and see how the updating behaves, and report the results back here for everyone. :)

Many Thanks,
Houman

Editor
Sep 28, 2011 at 2:44 PM

Houman,

Glad you got the CNAME working. Just remember that the staging URI will change when you delete the deployment. As long as you are simply pushing out upgrades it will stay the same.

The storage plugin is set to 7200 seconds to cut down on the amount of transactions with Windows Azure Storage. At the current setting (assuming you do not have a ton of plugins and themes installed) the cost of all the transactions is negligible. You can make is shorter if you want, but keep in mind that the general idea is not to install plugins, etc while the service is running so there should not be a need for it to be shorter.

When you get ready to update and deploy again you should not have to wipe your database at all. When I was building and testing the scaffolder I deployed many times using the same database that contained data already with no issues. It would be a pain to wipe the database and fill it with all your data each time :S

If you would like to try with an older version of WordPress that is certainly possible. You will need to download the full source of the scaffolder from Github (https://github.com/Interop-Bridges/Windows-Azure-PHP-Scaffolders/tree/master/WordPress). Inside the WordPress folder, open index.php and on line 217 you will find the link to the zip archive the scaffold uses. From there you will need to build a new WordPress.phar file with this command (Assuming you put the WordPress scaffold sources in C:\temp\WordPress)

scaffolder build -in="C:\temp\WordPress" -out="C:\temp\WordPress.phar"
Cheers,
Ben
https://github.com/Interop-Bridges/Windows-Azure-PHP-Scaffolders/tree/master/WordPress
scaffolder build -in="C:\temp\HelloAzureScaffold" -out="C:\temp\HelloAzureScaffold.phar"
Sep 29, 2011 at 9:19 PM

Hi Ben,

Your solution sounds very promising. I have successfully built the phar file. However when I try to run the scaffolding against my new phar file, I get this error message:

Error: Could not locate a class named  in the given scaffolder: C:\Temp\WordPressOld.phar. Make sure the scaffolder package contains a file named index.php and contains a class named Scaffolder.

I have extracted the content of the source file into C:\Temp and moved the folder WordPress back up in C:\TEMP.
Therefore my structure is like the following:

C:\TEMP\WordPress --> resources
index.php
Params.class.php

Then I have changed the path in index.php to Wordpress 2.9.2 with NotePad++.

Then I try to build it like this:

scaffolder.bat build -in="C:\Temp\WordPress" -out="C:\Temp\WordPressOld.phar"

It builds and the size of the phar file is exactly the same as before -> 2,748 KB

When I try to run like this, I get the error message shown at top of my post:

scaffolder.bat run -s="C:\Temp\WordPressOld.phar" -out="C:\Temp\WordPressOld" -DB_NAME=** -DB_USER=*@*.database.windows.net -DB_PASSWORD=* -DB_HOST=*.database.windows.net -sync_account=* -sync_key=***

What am I doing wrong please?

Many Thanks,
Houman

Editor
Sep 29, 2011 at 9:32 PM

Houman,

You have run into an idiosyncrasy of the scaffold code. There is an issue with the class name needing to line up with a comment above the class declaration. If you want to use WordPressOld:

• Open the scaffold index.php file
• Find "@command-handler WordPress" near line 43
• Change it to "@command-handler WordPressOld"
• Save index.php
• Remove the existing WordPressOld.phar
• Build the new WordPressOld.phar file

The error should now be gone.

Cheers,
Ben

Sep 30, 2011 at 10:40 PM
Edited Sep 30, 2011 at 10:42 PM

Hi Ben,

Many Thanks for your help.  I have sorted out this problem and successfully created the phar file.

I have picked WordPress 3.1 (As the older versions didn't work at all on Azure). Once it was successfully installed and I had setup the Storage plugin and could even post a new post and a test comment. I went back to the dashboard - under the Update tab - to update WordPress to the latest version.

But then I got a failed error message shown, when attempting to update it automatically.

So I went to dashboard of Azure and clicked on Staging Deployment and clicked on "Upgrade".  Then I picked the latest 3.2.1 package and its config file and uploaded it.

This is the screenshot of what happened.

http://i.imgur.com/HzUxz.png

That's worrying me... Do you have any idea how I could proceed from here?

Many Thanks,

Houman

Editor
Sep 30, 2011 at 11:51 PM

Houman,

I need to research this and will get back to you ASAP

Ben

Oct 2, 2011 at 6:22 PM
Edited Oct 2, 2011 at 6:24 PM

Thanks Ben.

I have been poking around a bit myself and would like to share my findings.

As I had mentioned before automatic update of Wordpress within dashboard comes with the error message

Update package not available.

Installation Failed

Upgrade of the actual Azure Staging Deployment wouldn't work as mentioned above, but then I tried to give it another go with less version differences by upgrading WordPress 3.1.4 to 3.2.1.

It still fails saying:

This error (HTTP 500 Internal Server Error) means that the website you are visiting had a server problem which prevented the webpage from displaying.

It seems the Azure Deployment upgrade option is not really an option and causes this problem.

So I decided to put a fresh 3.1.4 Wordpress on it by deleting the deployment first and re-deply it from scratch. I also made the Remote Desktop active on it.

Once in 3.1.4 WordPress Dashboard I posted some comments and new posts.  Then I went into the Remote Desktop and did a manual update of WordPress to 3.2.1.

As explained here http://codex.wordpress.org/Updating_WordPress  (Manual Update Section)

It worked fine.  Only caveat is that the update nag screen keeps appearing on the dashboard, but the version number is now 3.2.1. Which is great!

Problems with this approach:

1) I have simulated the case when the WebRole Instance needs to be rebootet.  After the reboot my WordPress is back to version 3.1.4. So the whole manual installation (mainly copying files around) has to take place again. This is a bit unexpected, why?

2) Then I have simulated the case when re-Imaging the Webrole instance.  After the succesful re-image, not only the WordPress was reverted back to 3.1.4 but also the downloaded files in "My Downloads" such as the latest 3.2.1 Wordpress version were gone.  As expected, since thats the whole point of re-image.  But why is WordPress installation data lost in step 1)?

All in all, its possible, but its a bit worrying.  As I need this case for a Business WordPress. I am a bit worried applying these updates in a manual way, and not be able to update the whole image to the latest version.  The moment I upgrade the Deployment, I get those nasty HTTP 500 Internal Server Error messages.

I wonder, if this could be improved.

Many Thanks,

Houman

Editor
Oct 3, 2011 at 5:42 AM

Houman,

I tried an update on mine and it worked. Have you checked the permissions to see if the 500 is coming from not being able to write/update files?

As for the files going back to 3.1.4 from 3.2.1 on a manual upgrade, that is expected. Any new/changed files directly on the instance will be erased in a reboot. It currently does not matter how you change them (e.g. downloading through WordPress or Remote Desktop). The proper way to ensure that they stay is to update the local development source, repackage, and deploy the update.

I have been thinking about a way to ease packaging and updating while allowing for local development. If I have time I will test it out and do a writeup tomorrow for you.

Cheers,
Ben

Oct 5, 2011 at 9:01 PM

Hi Ben,

Updating the deployment keeps failing for unfortunately.  Its kind of random. Now I got again the error I had initially:

I am still waiting for MS support to check this out for me why this is happening.

Most of the times the error is less critical and gives only a 500 error.  You have suggested that perhaps it is not able to write/update files, but why shouldn't it? Where do I have to go to verify the settings please?

WoW, if you could do a writeup how to test this under local development, that would be fantastic.  Local development keeps breaking my PHP.ini and I dont get it to work. If I was able to deploy this locally, it would be so much faster and I could actually test everything locally without having to upload it each time.

Many Thanks Ben,

Houman

Editor
Oct 5, 2011 at 9:23 PM

Houman,

I think MS support will do a better job of troubleshooting that error that I can. They should have access to log files that are not available to me.

You said you had enabled RDP? RDP to your instance and go to E:\approot and see if the permissions are set to read only. The scaffold should have taken care of that for you, but it could have hiccuped.

As far as the local development is concerned, I am reworking the scaffold today to utilize the newest features in the Windows Azure 1.5 SDK. I am almost to the point of testing local deployments. Hopefully this new version will have eliminated any bad behaviors :)

Ben

Editor
Oct 10, 2011 at 3:44 AM

Houman,

I updated the WordPress scaffold on Github. Could you try out the new version?

https://github.com/Interop-Bridges/Windows-Azure-PHP-Scaffolders/tree/master/WordPress

Cheers,

Ben

Oct 10, 2011 at 4:30 PM

Hi Ben,

Thank you very much my friend. I will definitely try this and let you know.  Microsoft coudnt help me on this matter. They said I had to delete and re-install the deployment.  Since the result of the deployment upgrade was each time slightly different, it couldnt have been indeed a bug.  I am so glad you have rewritten it and ironed it out for SDK 1.5.  In good hope I will try it again.

I am unfortunately until 21 Oct outside Europe for holidays. Internet connection is a bit slow and restricted where I am. My laptop with all Cloud based tools is with me though, and I will definitely give it a shot these days and let you know.

Many Thanks,
Houman

Editor
Oct 10, 2011 at 11:19 PM

Houman,

Another cool feature of the scaffold! I added a -source parameter that will allow you to specify the source of an existing WordPress codebase to use. To use it you will need to add the -source parameter to the command line like so:

-source path/to/WordPress

If you give it a path that is not a folder the scaffold will simply download a fresh copy of WordPress for you.

This should help ease pains when developing in IIS locally. Take a try at it and let me know what you think.

Cheers,

Ben

Oct 11, 2011 at 11:31 AM

Hi Ben,

1) This -source flag sounds promising. But where do I use it?  So you are saying you have created an extension to the existing "C:\Program Files (x86)\PHPAzure-4.0.3\bin\scaffolder.bat build -source" ?
I can see in your PHP code that you have added a source variable to the index, but I have trouble to understand how this source is injected into the phar file.

2) Now to your main changes, I finally have my internet setup and was about to try it. I have changed the index.php to download the old 3.1.4 version of wordpress.  Then I created a phar file from it as usual.
Then I tried to run the scaffold against the phar file but I keep getting this error message:

C:\>scaffolder run -s="C:\projects\VC\WordPress.phar" -out="C:\projects\VC\WordPress" -DB_NAME=VCDB -DB_USER=VC@xxx.database.windows.net -DB_PASSWORD=xxx -DB_HOST=xxx.database.windows.net -sync_account=vcstorage -sync_key=xxx

DB_NAME - Name of database to store WordPress data in
DB_USER - User account name with permissions to the WordPress database
DB_HOST - URL to database host
sync_account - Windows Azure Storage account endpoint
sync_key - Windows Azure Storage account key

I have definitely given the DB_NAME, but it keeps ignoring it. I even tried to run the build.bat file, within your source code that contains (I hope voluntarily) a sample. I even ran that and it failed with the same error:

call scaffolder run -out="%PWD%\build\WordPress" -s="%PWD%\build\WordPress.phar" -DB_NAME=wordpress_ben -DB_USER="satish@ltkw9g5pq3" -DB_PASSWORD="p7HmRW9Tp6FK" -DB_HOST="ltkw9g5pq3.database.windows.net" -AUTH_KEY="ASDF" --SECURE_AUTH_KEY="ASDF" --LOGGED_IN_SALT="ASDF" --NONCE_KEY="ASDF" --AUTH_SALT="ASDF" --SECURE_AUTH_SALT="ASDF" --LOGGED_IN_SALT="ASDF" --NONCE_SALT="ASDF" -sync_account="belobastor" -sync_key="x9dwLT6jaNgLvqVDhkQ24ZQtPeedoJqKobxkaOAjPc5/+jpI8IFUsaCiowyhKu69UWl70IdHsv2vCfRqiCPkiA=="

Could the phar file become corrupted after the latest version? Or am I doing something wrong?

Thanks,
Houman

Editor
Oct 11, 2011 at 2:43 PM

Houman,

The syntax has changed slightly on the command line. Parameters are not differentiated from the scaffolder tool and the scaffold itself by the =. The scaffold parameters do not use =

scaffolder run -s="C:\projects\VC\WordPress.phar" -out="C:\projects\VC\WordPress" -DB_NAME VCDB -DB_USER VC@xxx.database.windows.net -DB_PASSWORD xxx -DB_HOST xxx.database.windows.net -sync_account vcstorage -sync_key xxx -source path/to/WordPress

Cheers,

Ben

Oct 11, 2011 at 5:40 PM

Hey Ben,

Many Thanks for clarification. You may like to update the build.bat in source code to reflect this. Also the actual WordPress.phar file is not accessible for those who only wish to download the phar file and not the whole source code. :)

So from my understanding, the -source is helpful to pinpoint to an existing WordPress folder, so that there is no need to download the required version from web everytime the scaffolder is running correct? This is indeed very useful.

I have successfully packaged it as well with dev=false flag.

However when I tried to create the same by setting the dev=true, I get the following error. I think this is because of the two new variables you have introduced in the index.php

C:\Projects\VC\WordPress>package create -in="C:\Projects\VC\WordPress" -out="C:\Projects\VC\Out" -dev=true

Windows(R) Azure(TM) Packaging Tool version 1.5.0.0
for Microsoft(R) .NET Framework 3.5

Windows(R) Azure(TM) Desktop Execution Tool version 1.5.0.0
for Microsoft(R) .NET Framework 3.5

Starting the storage emulator...
Windows(R) Azure(TM) Desktop Execution Tool version 1.5.0.0
for Microsoft(R) .NET Framework 3.5

Starting the compute emulator...
Windows(R) Azure(TM) Desktop Execution Tool version 1.5.0.0
for Microsoft(R) .NET Framework 3.5

Using session id 1
Windows(R) Azure(TM) Desktop Execution Tool version 1.5.0.0
for Microsoft(R) .NET Framework 3.5

C:\Projects\VC\Out\WordPress.cspkg\ServiceDefinition.csdef: Error CloudService102 : The setting 'FileSystemDurabilityPlugin.FileNameIncludesToSync' for
role WebRole is specified in the service configuration file, but it is not declared in the service definition file.
C:\Projects\VC\Out\WordPress.cspkg\ServiceDefinition.csdef: Error CloudService102 : The setting 'FileSystemDurabilityPlugin.ExcludeSubDirectories' for role WebRole is specified in the service configuration file, but it is not declared in the service definition file.
C:\Projects\VC\Out/WordPress.cspkg

Hope this helps to pinpoint the problem.
Many Thanks,

Houman

Editor
Oct 11, 2011 at 6:07 PM

Houman,

Oh yes, I forgot to tell you that you will need to update your file durability plugin. The newest plugin has the ability to only sync the config file that is created. I set that as the default, this means the entire wp-content directory is now NOT sync'd automatically, only the dynamically created database file.

You can get the new plugin here:

Cheers,

Ben

Oct 11, 2011 at 6:44 PM
Edited Oct 11, 2011 at 8:08 PM

Ben,

Thanks for the hint. I have now downloaded the new version and got further.

Using session id 1
Warning : Remaping public port 80 to 82 to avoid conflict during emulation.
Warning : Remaping private port 80 to 83 in role 'WebRole' to avoid conflict during emulation.
Created: deployment(1)Started: deployment(1)Deployment input endpoint HttpEndpoint of role WebRole at http://127.0.0.1:82/.
C:\Projects\VC\Out/WordPress.cspkg

But once its finished and it goes on the address, I get this error message:

Fatal error: Call to undefined function sqlsrv_connect() in C:\Projects\VC\WordPress\WebRole\wp-content\mu-plugins\wp-db-abstraction\drivers\sqlsrv.php on line 275

Any idea what I might have missed?

Many Thanks,

Houman

Editor
Oct 11, 2011 at 6:48 PM

Houman,

That message means it worked! Well...sorta. You successfully deployed to your local dev environment, however you do not have the SQL Server extension installed on your machine is my guess from that error. You can either install it from the Web Platform Installer (you should have this if you installed the PHP pre-reqs automatically) or from the project at http://sqlsrvphp.codeplex.com/

Cheers,

Ben

Oct 11, 2011 at 7:56 PM
Edited Oct 11, 2011 at 8:08 PM

Hi Ben,

Thanks again for the tip.  I have utilized Web Platform Installer 3.1 to install the latest sqldrv for PHP 5.3.  The two files php_sqlsrv.dll and php_pdo_sqlsrv.dll have now been copied to the ext folder of my PHP folder and have also been added to the PHP.ini file. So far so good.

Then I have restarted the laptop to be sure the web server (IIS) has picked it up.

Packaging it again as dev I get this successful message:

Using session id 1
Warning : Remaping public port 80 to 82 to avoid conflict during emulation.
Warning : Remaping private port 80 to 84 in role 'WebRole' to avoid conflict during emulation.
Created: deployment(3)
Started: deployment(3)
Deployment input endpoint HttpEndpoint of role WebRole at http://127.0.0.1:82/.
C:\projects\VC\WordPress\Out/WordPress.cspkg

But once it tries to route to the address I still keep getting this

-> http://127.0.0.1:82/
Fatal error: Call to undefined function sqlsrv_connect() in C:\Projects\VC\WordPress\WebRole\wp-content\mu-plugins\wp-db-abstraction\drivers\sqlsrv.php on line 275

Is there any other way to debug this or get further information what I might have missed here?
I know I am getting closer hehe ;)

Thanks mate,
Houman

Editor
Oct 11, 2011 at 9:55 PM

Houman,

run phpinfo() in your local deployment somewhere and check the path of the PHP runtime and the php.ini file to make sure it is picking up the correct locations. Also look to see if sqlsrv is show on that page, though I am guessing at this point it will not be. Usually in the past when I have seen this behavior there is some sort of path misalignment.

Cheers,
Ben

Oct 11, 2011 at 10:36 PM

Hey Ben,

I have the results for you:

As you suggested I have run a php phpinfo.php >>more.txt

It looks alright to me, even though I am just a PHP beginner. :)

http://dl.dropbox.com/u/44307777/more.txt

The sqlsrv seems correctly registered and the path to PHP 5.3.8 seems correct as well. I am still investigating...

The other news is I have now deployed a new installation of 3.1.4 WordPress on Azure Cloud. Postet some comments and a post. The I did an upgrade of the Deployment with a 3.2.1 WordPress.

Unfortunately I still get the

This error (HTTP 500 Internal Server Error) means that the website you are visiting had a server problem which prevented the webpage from displaying.

Tomorrow I will try to redeploy the 3.1.4 with Remote Desktop and hopefully I may be able to change the permission as you had once suggested, provided my deployment upgrade with RDP would be a success after all.

If everything fails, the last resort is to delete the deployment everytime and install the new version from scratch. Then I have to change the DB entries to point to the old links. (This is a must when using staging mode with all those random numbers in front of .cloudapp.net, which do change with every redeployment. Perhaps this wouldn't be an issue with production, when the link is fixed for good)

Thanks again for all your help,

Houman

Editor
Oct 11, 2011 at 10:43 PM

Houman,

What does phpinfo() say from inside the emulator.

You also might be interested in the manual upgrade process. You would still repackage here, but you would run a couple extra scripts once your deployment has updated:
http://codex.wordpress.org/Updating_WordPress#Manual_Update

Cheers,
Ben

Oct 11, 2011 at 11:26 PM

Ben,

You are the star! PhpInfo() on emulator revealed that I had been using C:\Program Files (x86)\PHP\v5.2\php.ini instead my version 5.3

I am still investigating, how to change this. However just to see if it works I have also installed sqlsrv for PHP 5.2 thorugh the Web Plattform Installer and finally it gets another step closer.

Now i get this error message:

Multisite only works without the port number in the URL.

lol. Its kind of weird, since WordPress 3+ always supports Multisite. In my case I dont even need it. But it seems the local deployment is having a problem with it.

Did you come across that, or was your port 80 free in first place, and hence you didnt have the auto remapping during deployment to avoid any conflict as in my case?

Warning : Remaping public port 80 to 82 to avoid conflict during emulation.
Warning : Remaping private port 80 to 83 in role 'WebRole' to avoid conflict during emulation.

Cheerio,

Houman

Editor
Oct 12, 2011 at 6:25 PM

Houman,

Hmm, I have not tried a local multisite deployment. I do not think there is a way to get around that issue without hacking the WordPress core. Port 80 will already be taken on your machine by IIS as IIS is used in the emulator. I will do some more research, but I think to play with multisite you will have to deploy it to WAZ.

Cheers,

Ben

Editor
Oct 12, 2011 at 6:31 PM

Open your IIS Manager and check which PHP is being used there. It could be that your system path points to 5.3 but your IIS setting point to 5.2

Oct 12, 2011 at 6:43 PM
Edited Oct 12, 2011 at 6:45 PM

Hi Ben,

I was surprised by that message in first place, as I am not even intending to use a multi site. Nonetheless to get it rolling, I have disabled my Default Webpage on IIS to free up the port 80.
It seems it got me going forward as I am now getting a "can't connect to database" error message like this:

Notice: Undefined index: SQLSTATE in C:\Projects\VenusCloud\WordPress\WebRole\wp-content\mu-plugins\wp-db-abstraction\drivers\sqlsrv.php on line 283
Notice: Undefined index: message in C:\Projects\VenusCloud\WordPress\WebRole\wp-content\mu-plugins\wp-db-abstraction\drivers\sqlsrv.php on line 283
Notice: SQLSTATE: - in C:\Projects\VenusCloud\WordPress\WebRole\wp-content\mu-plugins\wp-db-abstraction\drivers\sqlsrv.php on line 283

Error establishing a database connection

This either means that the username and password information in your wp-config.php file is incorrect or we can't contact the database server at y6sf7bz2m3.database.windows.net. This could mean your host's database server is down.



I have some great news on the other front. I have created a new staging deployment with 3.1.4 WordPress, made some changes and added some posts. Then I deleted the deployment and installed a new staging deployment with WordPress 3.2.1. Then I switched to the database into the wp_options table and changed 'siteurl' and 'home' both to the new URL.

It works like a charm. Only caveat is that the update nagging screen still is showing as if it was still not updated to 3.2.1. But it is 100% as I checked the database and dashboard version and both are showing 3.2.1

I like this way much better than RDP into the instance and manually downloading and upgrading the WordPress. Since if there was a need for a restart of the image, I had to do the whole manual upgrade again. This isn't so nice. On top of it, manual upgrade requires merging the wp-config.php between the two versions, which could end up to be error prone and risky.

I have now much more confidence in using WordPress on Azure with this new way. I wished only there was a way to get rid of the little caveat above. Otherwise very happy with it. :) Thanks for the cool tool. Please keep it up to date.

Thanks,

Houman

Oct 17, 2011 at 8:20 PM

Hey Ben,

I have received the invoice for last month and it seems all the test deployments were running on a SmallCompute VM instead of ExtraSmall.

I have made an enquiry this regarding and Microsoft Support claims, it is only possible if deployed thorugh VS.  Have you come across this? Is there a trick to deploy WordPress on an ExtraSmal VM after all?

Many Thanks,

How to change the size of the VM in Visual Studio?:

•  Open your Windows Azure project in Microsoft Visual Studio.
•  In Solution Explorer, expand the Roles node of your project and then double-click the role to open its properties window.
•    In the Configuration page, locate the VM Size setting under the Instances category and choose the size from the drop down list.

For the extra-small instances, there are some pre-requisites as mentioned below:

1.       You should have the Azure SDK V1.3 or later installed.

2.       Visual studio tools should be installed.

3.       And you should be using VS 2010.

Editor
Oct 19, 2011 at 3:49 PM

Houman,

Heh, they just want you to buy VS ;). It is entirely possible to change it. Before you package open up the ServiceDefinition.csdef package and look for the <WebRole tag. Change vmsize="Small" to vmsize="ExtraSmall"

I am out of the office for the week so apologies if I do not respond in a timely manner.

Cheers,
Ben

Oct 19, 2011 at 4:03 PM

Hey Ben,

Thank you so much.  Thats fantastic news and would reduce my running costs by half.   :)

Have a great week off,

Houman

Nov 1, 2011 at 8:58 AM

Hi Ben,

There are a couple things:

2) You have now two files on GitHub, WordPress.zip and WordPressUpdate.zip  What does the latter do please?

Thanks,

Houman

Editor
Nov 1, 2011 at 5:25 PM

Houmie,

1) I do not understand. Out of sync how?

2) Use WordPressUpdate.zip. For some reason the original got corrupt and I have been unable to figure out how to fix it

Ben

Nov 9, 2011 at 10:03 PM

Hi Ben,

Apologies for late replay.

The date of your latest release on COdePLex is Thu Sep 15 2011 at 8:00 AM.  But on GitHub the latest version is from October 15, 2011.

One more thing Ben.  I have a Silverlight Application that I would like to deploy to the same instance as the WordPress package.

Would I be able to combine two packages? One from to contain the PHP WordPress package and another one from Visual Studio that contains the silverlight app?

Many Thanks for clarification,
Houman

Editor
Nov 9, 2011 at 10:20 PM

Houmie,

The releases of the Windows Azure SDK for PHP are not in lock step with the releases of the scaffolds. Unless it the scaffold breaks for some reason we probably will not update it.

Yes you can use Silverlight apps inside your WordPress install. You will need to do some digging on this because I have not played with Silverlight. You may be able to simply keep the files inside the WordPress directory and call them, you could add another site to the deployment, or you could run a new role just for the Silverlight app.

Ben

Nov 9, 2011 at 10:41 PM

Fantastic. Thats exactly what I needed.

When it says:

Now, simply add the source code for your Web Role to the WebRole1 directory and the source code for your Worker role to the WorkerRole1 directory.

1) Do I literally copy the whole Visual Studio solution file and project files right under the WebRole1 folder?

2) And once I do the "package create", it would simply combine both WebRoles into the same package?

3) Once its deployed, I could then access each WebRole via a different URl? Is this correct?

If that works, that would be very impressive and cost efficient for the time being.

Oh and why do I need a Worker Role? Brian says more to that in the next post, but there is no next post. :) I need to ask him I guess.

Thank you for your great tips as usual,

Houman

Nov 9, 2011 at 11:25 PM

Houmie-

I'm jumping into this long thread having only read the last few posts, so apologies in advance if I don't have full context.

I've never deployed a PHP app and a Silverlight app in the same Webrole. Thinking about doing so raises a lot of questions for me (in part because I have a very limited understanding of how Silverlight works).

I'm assuming your VS solution has some C# or VB code, which could not simply be added to the Webrole directory. The .NET code would have to be compiled first, whereas PHP code is just interpreted. This makes me think it is not easy to go this route. One alternative would be to add WordPress to your VS solution, but this would also mean modifying the startup tasks to pull in PHP and configure IIS to handle requests for PHP pages (the scaffolds take care of all this for you). Again, this doesn't sound easy.

I'll do some more homework and see if I can get some answers.

BTW, here one example of why you might need a web role: http://blogs.msdn.com/b/silverlining/archive/2011/10/05/an-auto-scaling-module-for-php-applications-in-windows-azure.aspx

-Brian

Nov 10, 2011 at 8:05 AM

Brian,

Many Thanks for your response. Thanks for the link, so you suggest a Worker Role for scaling the app. Nicely done!

Now to the other problem, let me elaborate about what I am trying to achieve to be sure we are on the same page..

I would like to share the WordPress Database between my Silverlight app and the WordPress itself to access the users. One way to do it would be to have two deployments
accessing the same database. In the long run I would probably do this anyway, as if one service is maintained the other one won't be affected.
However this is expensive as I need to pay for two deployments.

For the time being I would prefer having only one deployment hosting both above services.  I don't think its possible having two Webroles within the same deployment (Unless I am wrong)
Hence I came up with the idea of having both apps within the same single webrole.

Hope this clarifies it,

Many Thanks,
Houman

Editor
Nov 11, 2011 at 12:26 AM

Houmie,

I am pretty sure you are looking for the sites feature. It will take some hacking to do it but multiple sites in one web role are definitely possible with PHP.

http://msdn.microsoft.com/en-us/library/windowsazure/gg433110.aspx

Ben

Nov 12, 2011 at 2:56 PM

Many Thanks Ben,

I will be looking into the website how to setup multi <Sites/>.  It looks promising..

I was just about to use the source and create my own wordPress.phar. But there seems to be a bug with the -source parameter.

When I run this, it doesn't download the older version 3.1 as expected but it creates a phar file instead. It does't make sense.

call scaffolder build -in="%CD%\WordPress" -out="%CD%\build\WordPress.phar" -source="http://wordpress.org/wordpress-3.1.zip"

Any idea why it goes wrong?  The condition with Source seems alright:

if($this->p->get('source') != '' &&$fs->exists(\$this->p->get('source'))) {

Thanks,

Houman

Nov 13, 2011 at 9:01 PM

Hi Ben,

I have just realized my mistake.  It has to be a local copy and cant get it off web.  Thats fine I got the copy manually and added -source "%PWD%/wordpress-3.1/wordpress" to the end of the "Call scaffolder run..." line.

This works but I get an error:  2: Error in phar://C:/Projects/VC/WordPressSource/build/WordPress.phar/FileSystem.class.php:35 - mkdir(): No such file or directoryUpdating wp-config.php

Cleaning up previous WordPress scaffolder filesThe system cannot find the file specified.Building scaffold .phar fileC:\Projects\VC\WordPressSource\build\WordPress.pharCreating project directoriesExtracting resources...

Extracted resources.
Updating ServiceConfiguration.cscfg
Creating temporary build directory: C:\Projects\VC\WordPressSource\build\WordPress\tmpCopying WordPress from C:\Projects\VC\WordPressSource/wordpress-3.1/wordpressDownloading Database Abstraction LayerWriting file C:\Projects\VC\WordPressSource\build\WordPress\tmp/wordpress-database-abstraction.1.1.1.zipExtracting Database Abstraction LayerMoving Database Abstraction Layer files to C:\Projects\VC\WordPressSource\build\WordPress\WebRole\wp-content\mu-pluginsDownloading Azure Storage PluginWriting file C:\Projects\VC\WordPressSource\build\WordPress\tmp/windows-azure-storage.zipExtracting Azure Storage PluginMoving Azure Storage Plugin files to C:\Projects\VC\WordPressSource\build\WordPress\WebRole\wp-content\plugins2: Error in phar://C:/Projects/VC/WordPressSource/build/WordPress.phar/FileSystem.class.php:35 - mkdir(): No such file or directoryUpdating wp-config.php

NOTE: Do not forget to install the FileSystemDurabilityPlugin before packaging your application!
Congratulations! You now have a brand new Windows Azure WordPress project at C:\Projects\VC\WordPressSource\build\WordPressWordPress finished at location: C:\Projects\VC\WordPressSource\build\WordPress

This error doesn't happen if source parameter remains unset and it has to download the latest from the internet. It is definitely a bug, I am afraid :(

Many Thanks,

Houman

Nov 19, 2011 at 10:38 PM

Hi Ben,

I really hope you would read this. I have got around the bug above by just modifying the index.php to download the version I want rather than using the source.

But now I am stuck at this major problem and don't know what to do without your advice:

Remember we were talking about having multiple sites within the same Webrole?  I have succeeded and created this page on the cloud:

http://2b827b67573d47b994e77c18945a4e48.cloudapp.net/

And an virtual directory: http://2b827b67573d47b994e77c18945a4e48.cloudapp.net/ds

I have tried the same strategy with having a wordpress installation on main and a virtual directory as my silverlight app.

However as my silverlight is written against .NET 4.0 and your wordpress seems not to target the same .NET environment, it can't work.

The error message is:

Parser Error Message: Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive.
<compilation targetFramework="4.0">

I did some research and they say a nested virtual application can't be in a different .NET version.

My question is now how to solve this? For which .NET version is Azure PHP creating the WordPress and how could I make it to target .NEt 4.0 please?

Your help on this would be highly appreciated, because then I could run both sites on same WebRole. :)

Many Thanks,

Houman

Nov 26, 2011 at 11:04 AM

For anyone having the same issue, I have found the solution. :)

RDP into the VM and open Control Panel -> IIS Manager. You should see now two sites, your wordpress site and silverlight site.

Click on your Silverlight Site and change the Basic Binding on the right Action pane.  There change the .NET TargetFramework to 4.0 from xxxxx.