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

 

You must be logged in to post a comment.