Flex and PHP - configure ZendFramework the easy way.

QUICK UPDATE

Here are samples of the two critical files you need to make the Flex Data Management Service files work on your remote server. I am using a standard linux server on hostgator for this example.

1. amf_config.ini - change samples to your directory name and don’t forget the forward slash at the end or it won’t work. Make sure you create a services directory underneath the "samples directory" so you can copy the services file that Flex creates. You can find that in the "services" folder within your project. This has to be copied manually from your local project folder over to your samples/services folder. This is CRITICAL!!! Flex DOES NOT do this for you. 

[zend]

webroot = /home/yeswedoservers/public_html/samples/

[zendamf]

amf.production = false

amf.directories[]=services

 

2.Your Services file – something like "ZipsService" or YourService- this is found in the root directory of your flex project in the services directory. This file is totally case sensitive. DON’T RENAME IT! Copy it up to your "samples/services" folder and change the information below to match your server settings. Remember, these settings have nothing to do with your local wamp or mamp settings. Comment var $port = "3306"; out if you have trouble. You likely won’t need this on your server.

var $username = "your username";

var $password = "your password";

var $server = "localhost";

var $port = "3306";

var $databasename = "your database name";

var $tablename = "zips";

var $connection;

 I will post a way to trash the entire Flex Data Management "cluster-f&@k" in a couple of weeks and use something much easier and faster. There is absolutely no reason to use Zend or Flex Data Management services. You can do the same thing in regular PHP with 20% of the code. It’s Total junk!

Paul Chavaux

—–old article starts here.

Remote Webhost setup – Hostgator, etc.

1.Setup your php webservice in flex locally. i.e. wamp or xampp, whatever…

2. Don’t build an mxml page yet.

3. Export a release build.

4. Make sure there is a ‘services’ folder in the release folder, i.e., c:\wamp\www\myReleaseBuild\services

5. Make sure there is a php file in this folder that matches the service name you created.

6. Open Filezilla (download this at filezilla if you don’t have it) and log into your ftp host on your webhosting site., i.e., hostgator, etc.

7. create a folder under the root, i.e., /home/public_html/myNewFolder

8. upload the release build under this new folder. make sure you only upload the files UNDER your local release build folder like this.

c:\wamp\www\myReleaseBuild\allYourFiles

just upload the "allYourFiles" and not myReleaseBuild\allYourFiles

(you are doing this for a reason I will explain later.

9. You will now need to edit two files because they need to include your webhosting information instead of your local server info.

10. If you have cpanel in your webhosting package open up the file manager and go to the new directory you just created that now contains a copy of the files of your release build.

11. go to the services directory and open the php service file., i.e., myService.php which has the php class with all the stuff flex needs to communicate with your php/mysql server/database, etc.

12. find the following lines.

this is connection info for your local installation., i.e., wamp, xampp, whatever.

    var $username = "root";
    var $password = "";
    var $server = "localhost";
    var $port = "3306";
    var $databasename = "yourLocalDatabase";
    var $tablename = "tableWithYourRecords";

 

change it to something like this for your hostgator account or whatever hosting account you have. you can find this stuff in your cpanel under the databases or just use the ftp login and password for your ftp which usually works, if not, create a new one in the databases area of cpanel or your webhost panel.

    var $username = "probablyYourFTPLoginName";
    var $password = "probablyYourFTPPassWord";
    var $server = "localhost";
    var $port = "3306";
    var $databasename = "yourWebDatabaseName";
    var $tablename = "tableWithYourRecordsInIt";

sometimes "localhost’ won’t work and you will need to put your NON-www address, for instance, instead of www.yourDomainName.com it would be yourDomainName.com without the www. Or if this fails, open up a cmd window on your computer and ping your domain name, i.e., ping yourDomainName.com and get the ip address and put it in the $server variable. If none of that works contact your webhost and ask, but normally, localhost works fine.

sometimes port 3306 can be left blank, too.

This is really easier than I am making it.

13. Save that puppy – remember, this stays in the services folder. There shouldn’t be anything else in it but this service file (php file,oh yeah, a service is just a php file).

14. Now move up one directory level to the "root level of your release build directory" like this.

->root-level-of-your-release-build

->->services-folder-underneath-root-level-of-your-release-build

go to the top level which is: ->root-level-of-your-release-build

15. you will see your swf and html files and a bunch of other nonsense, too. Find the amf_config.ini file. This file is pure evil and no one except Mihai Corlan at Adobe knows how to use it. Oh, yeah…did I mention that everyone at Zend and Adobe are morons except Mihai?  Yes, they are all idiots and will suck you into a time tunnel or black hole with all their self-aggrandizing word soup they call Support Center…don’t waste your time on those sites or your boss will fire you.

okay, back to the task at hand…

the amf_config.ini file looks like this:

[zend]
;set the absolute location path of webroot directory, example:
;Windows: C:\apache\www
;MAC/UNIX: /user/apache/www
webroot =/home/yeswedo/public_html/1

;set the absolute location path of zend installation directory, example:
;Windows: C:\apache\PHPFrameworks\ZendFramework\library
;MAC/UNIX: /user/apache/PHPFrameworks/ZendFramework/library
zend_path =/home/yeswedo/public_html/ZendFramework/library

[zendamf]
amf.production = false
amf.directories[]=webServiceTemplate/services

Now delete some of the bullshit, well, most of it is bullshit and will throw mystery errors like the Fred Merkle in the 1908 world series. Mystery errors are errors that are created by the error fairies and can never be resolved without kidnapping the CEO of Adobe and holding him ransom for 445 days (one day longer than the Iranian Hostage Crisis) and threatening to take away all his ill-gotten stock options….(don’t try this at home).

[zend]
webroot =c:\wamp\www\
;zend_path =c:\wamp\www\ZendFramework\library

[zendamf]
amf.production = false
amf.directories[]=yourLocalReleasebuildFolderName/services

YOUR NOT DONE YET! THIS IS THE IMPORTANT PART OR YOU WILL THROUGH THE DREADED CHANNEL ERRORS!
[zend]
webroot =c:\wamp\www\
;zend_path =c:\wamp\www\ZendFramework\library

[zendamf]
amf.production = false
amf.directories[]=yourLocalReleasebuildFolderName/services

Let’s go line by line:

nothing to change on the first line [zend]

[zend]

second like is so easy it is hard. webroot =

this is the web root on your webhosting site. Most of the time it is located in the top left corner of your cpanel and should look something like:

/home/yourDomainNameWithTheDotComOrSomethingClose/public_html/

so if your domain is yeswedoservers.com then this line might look something like:

/home/yeswedo/public_html

make sure you leave off the last "/" or you will throw a channel error.

if you have your stuff in a subdirectory of your webroot like this:

/home/yeswedo/public_html/myCoolFolderWhereIStoreMyFiles/myReleaseBuildFolder/

where myCoolFolderIStoreMyFiles is a subdirectory with workfiles or something…whatever…then make sure you modify this like to read:

/home/yeswedo/public_html/myCoolFolderWhereIStoreMyFiles

okay..that line is done and make sure there is no semi-colon or spew in front of it.

the next line looks something like this before modification: Notice the semi-colon-spew-that-you-will-delete, too. Delete everything back to the equal sign "=" and enter the path to the ZendFramework\library…

;zend_path =c:\wamp\www\ZendFramework\library

should look like:

zend_path =/home/yeswedo/public_html/ZendFramework/library

where yeswedo is the name of YOUR folder (not mine), again, this should be in the upper left corner of your cpanel.

If you have a different path to your ZendFramework directory then change it accordingly.

You’re almost done. The next three lines may look like this before modification…
[zendamf]
amf.production = false
amf.directories[]=webServiceTemplate/services

leave the first two as they are above, like this:
[zendamf]
amf.production = false

and change the last line to match the releaseBuildDirectory on the webhost, remember this from above?
amf.directories[]=thisIsYourReleaseBuildFolder/services

notice that this points to the php service file we edited above, too.

Save and exit.

16. Now try to run your releaseBuildfile.swf or releaseBuildFile.html. and see if you get an error. If you get a channel error or gateway.php not found error check your paths.

17. if you keep getting channel errors you may have a syntax error in your php class file (this is the one in your services folder). If you used the editor from your webhost to edit these files you shouldn’t have a problem. Some people say the files need to be saved in utf-8 or ansi, but they should be fine if edited using your webhost editor, otherwise use a namebrand html editor like dreamweaver…just open and re-save.

Most of the time, channel errors are caused by a bad path in the amf_config.ini file. Don’t mess with the gateway.php file because it only exists to read the amf_config.ini file.

Flex generates the class php file in the services directory and if it works locally then it will work on the webhost as long as you change the connection stuff I outlined above.

Let me know if you have any questions.

Paul Chavaux

 

26 comments to UPDATE! Flex 4.5 and PHP – configure ZendFramework the easy way (yeh…right!)

  • Kenn Lau

    Thank you for this wonderful article. I have a deeper understanding on amf_config.ini. And yes, Mihai is DA MAN in adobe! By any chance, do you know if there are any good reads on the specification of amf_config.ini? Again, thank you for sharing your expertise with the community.

  • Filip Dewaele

    hi

    thank you for this nice article.
    i changed everything like you explained and i stil get this error.
    can you please help me?

    “Channel disconnected
    Channel disconnected before an acknowledgement was received”

  • Filip Dewaele

    this is my amf_config.ine

    and the test location is
    http://www.amba-amba.be/KD

    [zend]
    ;set the absolute location path of webroot directory, example:

    webroot =/home/usr1/amba-amba/public_html/KD

    ;set the absolute location path of zend installation directory, example:

    zend_path =/home/usr1/amba-amba/public_html/ZendFramework/library

    [zendamf]
    amf.production = false
    amf.directories[]=services

    • admin

      Here is a sample I copied from one of my working sites. Its possible you will need to remove the ‘/KD’ from your webroot path.
      [zend]
      webroot = /home/youraccount/public_html
      zend_path = /home/youraccount/public_html/ZendFramework/library

      [zendamf]
      amf.production = false
      amf.directories[]=services

  • Filip Dewaele

    thanks

    i tried it, and removed the /KD, and this is the error i get now:

    Class “KdplanningService” does not exist: Plugin by name ‘KdplanningService’ was not found in the registry; used paths:
    : /home/usr1/amba-amba/public_html/services/
    #0 /home/usr1/amba-amba/public_html/ZendFramework/library/Zend/Amf/Server.php(550): Zend_Amf_Server->_dispatch(‘getAllKdplannin…’, Array, ‘KdplanningServi…’)
    #1 /home/usr1/amba-amba/public_html/ZendFramework/library/Zend/Amf/Server.php(626): Zend_Amf_Server->_handle(Object(Zend_Amf_Request_Http))
    #2 /home/usr1/amba-amba/public_html/KD/gateway.php(69): Zend_Amf_Server->handle()
    #3 {main}

    • admin

      check that your services folder contains a php file called KdplanningService . Flex doesn’t post this automatically and you have to copy it from your project folder’s service to your services folder on your host where you will also need to change the login, password, database and host if it varies from your local configuration in your flex project.
      Please forgive me if you’ve already done that.
      one more thing…your services folder should exist in the root, also, you could also place the KdplanningService php file in the zend directory but i prefer it within the site or folder i am currently referring to. I’ve had this same sort of error before and i finally renamed my services file to something like 1.php and updated the new name in my flex project. Sometimes those capital letters in file names honk it up.

  • Filip Dewaele

    i think i’ve got it.
    it was a mistake in the database name.
    but i get still some errors. I’ll first try to solve that.
    i’ll let you now.
    many thanks!

  • Filip Dewaele

    fond it!
    the database name was spelled wrong.

    thank you for your support!

  • I really want to thank you man, without your help I would have been fired jjajaja. But after searching a lot in google, your answer was simply what I need. Thank you very much!

  • Bill

    I’ve stumbled across this blog after hours trying to figure out how to get the ZendFramework to work on my shared hosting provider. It was easy to set up on wamp but still having one heck of a time getting it to work on my shared provider. I followed the steps above to the T but not sure why I keeping getting errors – may be how I installed ZendFramework. I just uploaded it to a folder in my web root called ZendFramework. If I go to my gateway.php file I get the following errors: Warning: include_once(Zend/Config.php) [function.include-once]: failed to open stream: No such file or directory in /home1/configre/public_html/ZendFramework/library/Zend/Loader.php on line 146

    Warning: include_once() [function.include]: Failed opening ‘Zend/Config.php’ for inclusion (include_path=’.:/usr/lib64/php:/usr/lib/php:/home1/configre/public_html/ZendFramework/library’) in /home1/configre/public_html/ZendFramework/library/Zend/Loader.php on line 146

    Fatal error: Class ‘Zend_Config’ not found in /home1/configre/public_html/testprojectlocal/gateway.php on line 30

    Any ideas on what I’m doing wrong and do I need to make any changes to php.ini or anything? Any help would be greatly appreciated.

  • Bill

    Figured out my issue… Looks like I had a corrupt extraction of ZendFramework. I downloaded the latest released today (1.11.4) and compared it to the 1.11.3 version I had extracted previously – looks like for some reason many of the files were missing as well… after uploading the latest and then following your instructions again from above, things seem to be working now.

  • Hi guys, and thank you for that article that i followed to the letter!
    I’m kind of stuck with the “DREADER CHANNEL ERRORS!

    Let me explain the details : I have built a simple Flex application that calls a php service to connect to a sql database. In local mode, with a wamp “server”, everything works just fine, the problem begins when i try to publish my app on a remote server (provided by OVH). I followed all the steps of the article but in spite of it, i cannot manage do get it right.

    Here are my configuration files, i must be missing something…

    //amf_config.ini
    [zend]
    webroot =/var/www/flex3d.net
    ;zend_path =

    [zendamf]
    amf.production =false
    amf.directories[] =1/services

    i hate modified the php service i call with my remote server settings… the beginings of the file looks like this :

    //AuthentificationService.php

    class AuthentificationService {

    var $username = “root”;
    var $password = “mypassword”;
    var $server = “localhost”;
    var $port = “3306″;
    var $databasename = “mydatabase”;
    var $tablename = “andthenameofmytable”;
    var $connection;

    Of course i have the ZendFramework in the same folder than my flex project since i haven’t unquote the ;zend_path parameters in the amf-config.ini file.

    So, does anyone see what i am missing? Maybe

    Thank you all!

    Could the channel error message

  • Pan

    Please help me:
    I have tried lots of times, but the error is still on. The error is same as Filip Dewaele. The php file is on the right way,but it show the error (http://www.evenfood.com/mobil/mobilsoft.html):
    Class “sellservice” does not exist: Plugin by name ‘Sellservice’ was not found in the registry; used paths:
    : /home/content/67/7848667/html/mobilsoft/
    #0

    Should I config the Godaddy’s php.ini ? Or what should I do? I have been in trouble with it for about 1 month.
    Thanks.

    The configtion about my web is :
    [zend]
    webroot=/home/content/67/7848667/html
    zend_path =/home/content/67/7848667/html/ZendFramework/library
    [zendamf]
    amf.production = false
    amf.directories[]=mobilsoft

    • admin

      Hi Pan,
      First of all I love your app although it looks to be in mandarin. :-)
      I have a couple of questions about your problem and I think we can get it fixed for you.
      1. is your class “sellservice.php” or SellService.php?
      2. can you list the path to this file? Where is it located within the ZendFramework directory?
      3. Have you tried renaming sellservice to SellService…?
      Paul Chavaux

  • Pan

    PS , the follow is php info:

  • Pan

    Thanks very much. I rename the sellservice.php to Sellservice.php, it works right on the way(3. Have you tried renaming sellservice to SellService…?).
    So I think maybe zend framework is looking for a file that starts with a capital letter, even though it works fine on my machine.
    Thanks very much for you help.I am from China. Very happy to be friend with you. Thanks again.

  • Got it it was the zendframework i was using which had mistakes ….thanks anyways

  • Yes, I finally gave up using all those frameworks. They are simply a waste of time. I have never seen the advantage of them. I also suggest using simple php pages and calls to your databases with the Flex HTTPService instead of the Flex Data Management tools. You can create a php page that converts all of mysql data from the server into XML and then simply use an ArrayCollection object within Flex to pass the data to your controls. Moreover, you can post very easily, too using the HTTPService using the request option with binding. This will save you hundreds of bogus lines of code that Flex generates when you use the data management stuff. You don’t need value objects for simple calls back and forth to the server. Do it all with PHP and pull all your data into Flex using XML. Also, you can skip the resultformat method as you don’t need it. You only need three things in the HTTPService: 1:url to your php page the returns XML data, 2: an ID, 3: the result method which can simply be an inline call like result=”YourArrayCollectionObject=’your id.lastResult.records.record’ where id is the name this HTTPService and lastResult.records.record refers to the XML object’s children (records).

  • hey i have the same problem as Filip Dewaele, i get this error

    Class “servicios” does not exist: Plugin by name ‘Servicios’ was not found in the registry; used paths:
    : /home1/messoftc/public_html/oc/services/
    #0 /home1/messoftc/public_html/ZendFramework/library/Zend/Amf/Server.php(553): Zend_Amf_Server->_dispatch(‘checkLogin’, Array, ‘servicios’)
    #1 /home1/messoftc/public_html/ZendFramework/library/Zend/Amf/Server.php(629): Zend_Amf_Server->_handle(Object(Zend_Amf_Request_Http))
    #2 /home1/messoftc/public_html/oc/gateway.php(69): Zend_Amf_Server->handle()
    #3 {main}

    and this is my amf.config
    [zend]

    webroot =/home1/messoftc/public_html/oc

    zend_path =/home1/messoftc/public_html/ZendFramework/library

    [zendamf]
    amf.production = false
    amf.directories[]=services

    this is my test page
    http://www.messoft.com/oc/Orders2.html

    i have all the files like you said in “oc” folder and inside oc folder i created services folder wich contains the servicios.php

    i little help here please!!

    Thank you!

  • Fabro

    Well I found this blog in wich everyon get a solution =P
    so, I was wondering if you guys can help me to find what is wrong with my file =S (it’s driving me crazy)
    I checked many time de configurations but I get the same error:

    Class “CustomerService” does not exist: Plugin by name ‘CustomerService’ was not found in the registry; used paths:
    : /home/u918346104/public_html/services/
    #0 /home/u918346104/public_html/ZendFramework/library/Zend/Amf/Server.php(553): Zend_Amf_Server->_dispatch(‘count’, Array, ‘CustomerService’)
    #1 /home/u918346104/public_html/ZendFramework/library/Zend/Amf/Server.php(629): Zend_Amf_Server->_handle(Object(Zend_Amf_Request_Http))
    #2 /home/u918346104/public_html/pagingsample/gateway.php(69): Zend_Amf_Server->handle()
    #3 {main}

    I don’t want to sound desperate but as The Beatles said: “HELP!!!”

    Thanks!

  • David Baron

    Hi All,

    It seems like this web site might just save me…but I’m not there yet. I have the exact same problem Fabro is having.

    My Linux shared hosting site structure:
    www
    MyApp
    amf_config.ini
    gateway.php
    (all of my flex/flash files)
    library
    (all of my class definitions – Value object, i.e., DefPerson.php)
    services
    (all of my actual worker php files, i.e., ClsFindPeople.php)
    ZendFramework

    I get the same error Fabro does, which implies that ZendAMF/PHP *is* looking in the right place, i.e., the services directory, but something just ain’t working.

    My amf_config.ini (with commented-out lines removed):
    [zend]
    webroot = /user/www/

    zend_path = /user/www/ZendFramework/library

    [zendamf]
    amf.production = false
    amf.directories[]=MyAppName/services

    At the very top of this blog entry, Paul seems to suggest that the webroot value should include the ‘MyAppName’ value. True? He then continues to suggest that the amf.directories would ‘only’ need the ‘services’ value (since we are already ‘in’ the right place to start?).

    As Fabro shouted: Help!

    Oh, and I had already taken much of Paul’s advice many months ago (actually came from Wade Arnold) who basically told me to stop using the ‘cool, auto-magic Flex Data Services wizard/tool and just do it ‘manually’. My code is now very simple, very effective. And… everything was working great on my local PC development machine (win 7 with WAMP). It just won’t seem to ‘work’ once moved to a shared linux hosing environment. All individual components have been tested as working though, i.e., PHP, my classes, database connectivity, etc…

    Thanks,

    -David
    Centennial, CO

  • David Baron

    Sorry folks,

    I did not realize that my ‘indentation’ would not work (I uses simple spaces which of course get ignored). Let me try again. My web structure is:
    www
    ….MyApp
    ……..amf_config.ini
    ……..gateway.php
    ……..(all of my flex/flash files)
    ……..library
    …………(all of my class definitions – Value object, i.e., DefPerson.php)
    ……..services
    …………(all of my actual worker php files, i.e., ClsFindPeople.php)
    ….ZendFramework

    Sorry…

    -David

  • I was wondering if you ever considered changing the page layout of your website? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having 1 or 2 images. Maybe you could space it out better?

You must be logged in to post a comment.