Monday, April 11, 2011

Installing Zend Framework on XAMPP Server for Windows and Linux



Zend is easy to get up and running on XAMPP.  For Windows systems, just install
XAMPP per their instructions, then download and uncompress the latest ZF library 
source into \xampp\htdocs which is the server path for all hypertext documents.

Then make sure to change the include path in \xampp\php\php.ini -- if you add
the Zend Library update -- and it should be first because there is another
version of Zend in the PEAR folder.  It should look something like this:
include_path = ".;C:\xampp\htdocs\Zend\library;C:\xampp\php\PEAR"
(footnote: and/or run pear upgrade from the XAMPP shell as XAMPP suggests)

If using PHP cURL, be sure to enable the cURL library by uncommenting this line:
;extension=php_curl.dll which is found in \XAMPP\php, then restart.

If trying the QuickStart, add something like this to the httpd-vhosts.conf file
in \xampp\apache\conf\extra.  Of course make name changes for your path:

# for all XAMPP requests that do not match a ServerName 
# or ServerAlias in any <VirtualHost> block
<VirtualHost *:80>
    DocumentRoot /xampp/htdocs
</VirtualHost>
    
<VirtualHost *:80>
    ServerName quickstart.local
    DocumentRoot /xampp/htdocs/ZendQuickstart/public
    SetEnv APPLICATION_ENV "development"     
# (if needed:)      
#    <Directory /xampp/htdocs/ZendQuickstart/public>
#        DirectoryIndex index.php
#        AllowOverride All
#        Order allow,deny
#        Allow from all
#    </Directory>
</VirtualHost>

After re-starting the server, run the QuickStart index.php in your browser. 
If you get any Zend level errors, try adding this fix I found as user comments
on the Zend site comment page (if no Quickstart errors, they fixed this/it's gone).

In the ../application/bootstrap.php file, add the 'user code...' segment:

    protected function _initDoctype()
    {
        $this->bootstrap('view');
        $view = $this->getResource('view');
        $view->doctype('XHTML1_STRICT');


// user code comment to fix error:
$loader = new Zend_Loader_Autoloader_Resource (array (
'basePath' => APPLICATION_PATH,
'namespace' => 'Application',
));

$loader -> addResourceType ( 'model', 'models', 'Model');
$loader -> addResourceType ( 'form', 'forms', 'Form');

    }
...
(Note I added the last line after a form error similar to the model error
the other user found a fix for -- thank you.)

For Linux/LAMPP and Zend, the easy way (at least on the popular Ubuntu --
so probably for all the Debian-based distributions out there...)
is to run sudo apt-get install zend-framework-bin in a terminal window
then add the Zend path to set_include_path of your startup index.php file.
(this installs the Zend files in /usr/share/php/libzend-framework-php/).

Or when test installing manually, I put the latest Zend into this shared directory:
/usr/share/php/Zend/.  The same is added to the php set_include_path.

That looks something like this in my test/example apps index.php file:
set_include_path('library'. PATH_SEPARATOR. get_include_path().
  PATH_SEPARATOR. '/usr/share/php/Zend/library/');
 
(FYI when I installed the Zend files manually, I first used the terminal command 
 mkdir to create the /php folder in /usr/share/ directory (/usr/share/php/).  

 After that I ran a tar extract similar to suggested way to install XAMPP on Linux: 
 tar xvfz ZendFramework-current_version_numberxxx.tar.gz -C /usr/share/php/
 changing to a superuser via sudo su first.  Then I renamed the long Zend
 folder using the mv terminal command.)  

Also some miscellaneous XAMPP on linux tips:

To run XAMPP from a visual desktop menu, add this file to your system:
sudo gedit /usr/share/applications/xampp-control-panel.desktop

Save this content, then restart:

[Desktop Entry]
Comment=Start/Stop XAMPP
Name=XAMPP Control Panel
Exec=gksudo "python /opt/lampp/share/xampp-control-panel/xampp-control-panel.py"
Icon[en_CA]=/usr/share/icons/Tango/scalable/devices/network-wired.svg
Encoding=UTF-8
Terminal=false
Name[en_CA]=XAMPP Control Panel
Comment[en_CA]=Start/Stop XAMPP
Type=Application
Icon=/usr/share/icons/Tango/scalable/devices/network-wired.svg
Categories=Application;Network;Development

(my ideas for categories: Network = Internet menu, Development = Programming menu)

If getting an XAMPP error msg 'Another web server daemon is already running'
and you don't want to remove any other packages, try changing port 80 to 85
in file sudo gedit /etc/apache2/ports.conf then restart.  Just remember
that XAMPP might then work but something else might need to be reconfigured
or at least run something like this: http://localhost:85/...

(follow-up: a simple change allows multiple virtual hosts for the above.
  just run sudo gedit sites-available/default and change *:80 to *:*)

And if you are having any problems with XAMPP, PostgreSQL and your PHP apps, 
try a connection string like this:

$connect = pg_Connect("host=localhost port=5432 
                       dbname=yourtestdb 
                       user=yourtestuser password=youruserpassword");

Also be sure to install the php lib with apt-get install php5-pgsql
for PostgreSQL/Apache use outside of XAMPP...

And if can't run localhost on the Google Chrome browser, here is the step by step
way I fixed it in Ubuntu Linux:

1) put an icon on the panel or desktop -- if not there already, by right-clicking
   the menu option and selecting 'Add this launcher to panel' or desktop...
2) Right-click the Google Chrome launch icon, then select Properties.
3) Append this text on the end of the launch Command line --enable -ipv6

Maybe this will clear up what you might have found on the support pages. :)

All of this tested only on Linux Ubuntu 9.10, 10.04 LTS, and 10.10 by the way.

Hope this helps.  Best of luck.

No comments:

Post a Comment