Apache

RSS
Posts: 2

Local Windows XP, XAMPP Apache server, NuSphere PhpED debugger, Zend Framework mod_rewrite PHP Code Setup

INTRODUCTION
How to setup a Zend Framework PHP web site on a local machine Windows XP machine using XAMPP and PhPED Debugger

GOALS

- Run the site from http://localhost or some equivalent on the local machine
- Run the site in PhpED debugger

WHY THIS ISN’T LIKE A NORMAL PHP WEB SITE

- the Zend Framework URL rewrites setup will KILL you on a local machine. As in, you will either want to commit suicide or homicide trying to set this up.

- If this example uses a slash at the end of a directory path or URI, USE THE SLASH.

- Every period, comma and slash is important!

- You might be able to make this work without the punctuation, but if your setup is broken, check the punctuation!

OPERATING SYSTEM
WINDOWS XP and appropriate 150 or so Microsoft updates.

APACHE SERVER, MYSQL DATABASE
XAMPP Package xampp-win32-1.7.1.exe
It’s not the most recent but I know it works with Joomla and it works for this project as well.
Extract to c:\ which creates c:\xampp
Using the XAMPP control panel, install MySql and Apache as Windows services.

WHENEVER YOU MAKE CHANGES TO
C:/xampp/apache files,
RESTART Apache
using Windows Services
or at CMD “c:\xampp\apache\bin\httpd.exe” -k restart

DEBUGGER IDE
NuSphere PhpED Professional 5.95 build 5970
Install using all defaults to c:\program files\nusphere

WEB SITE ZEND FRAMEWORK SETUP
Extract root of web site to c:\xampp\htdocs\myapp, where myapp is the placeholder for your web site’s root directory. A correctly architected Zend project will not require an index.php in the root directory. index.php is forwarded to public\index.php. This project (that we’re calling myapp, and that I inherited), does not use public for index.php. index.php is in the root directory. It does use .htaccess on a shared server BUT DOES NOT use .htaccess here.

ARCHITECTURE

I AM NOT RECOMMENDING THIS ARCHITECTURE.
I am only documenting how to debug it.

c:/xampp/htdocs/myapp/application

configs, models, views, Bootstrap.php

c:/xampp/htdocs/myapp/public

resources such as images and videos

c:/xampp/htdocs/myapp/public/index.php

The index.php that invokes the Bootstrap

myapp/.htaccess or myapp/public/.htaccess

THERE ARE NONE. Virtual Hosts overrides .htaccess.

c:/xampp/htdocs/myapp/php.ini:

php_flag magic_quotes_gpc off
php_flag register_globals off
php_value include_path .;c:/xampp\htdocs\myapp\application;

c:/xampp/htdocs/myapp/application/configs/application.ini*
* USE FULL PATHS rather than hybrid concatenations off APPLICATION_PATH

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
phpSettings.date.timezone = "UTC"
includePaths.library = c:\xampp\htdocs\myapp\application\library
bootstrap.path = c:\xampp\htdocs\myapp\application\Bootstrap.php
bootstrap.class = "Bootstrap"
resources.frontController.controllerDirectory = c:\xampp\htdocs\myapp\application\controllers
resources.db.adapter = PDO_MYSQL
resources.db.params.host = localhost
resources.db.params.username = root
resources.db.params.password =
resources.db.params.dbname = myapp

staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

WINDOWS ENVIRONMENT PATH
Has NuSphere items from installation but NO extra definitions.
Paths are defined in php.ini, application.ini, hosts and httpd.conf files.

APACHE CONFIGURATION
c:/xampp/apache/conf/httpd.conf

Many of these are defaulted to these values. Some are not.

Enable mod_rewrite
LoadModule rewrite_module modules/mod_rewrite.so

Include vhosts conf:
Include conf/extra/httpd-vhosts.conf

Set AllowOverride to All — this directive affects whether Apache will read .htaccess.
It is actually only necessary in vhosts (instructions below). However this setup is SO touchy that
I would go ahead and set every AllowOverride to All regardless of which element it’s in.

Entire c:/xampp/apache/conf/httpd.conf:

ThreadsPerChild 250
MaxRequestsPerChild  0
ServerRoot "C:/xampp/apache"
Listen 80
LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
LoadModule asis_module modules/mod_asis.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule authn_alias_module modules/mod_authn_alias.so
LoadModule authn_anon_module modules/mod_authn_anon.so
LoadModule authn_dbd_module modules/mod_authn_dbd.so
LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authz_dbm_module modules/mod_authz_dbm.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule cache_module modules/mod_cache.so
LoadModule mem_cache_module modules/mod_mem_cache.so
LoadModule cern_meta_module modules/mod_cern_meta.so
LoadModule charset_lite_module modules/mod_charset_lite.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule dav_module modules/mod_dav.so
LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
LoadModule expires_module modules/mod_expires.so
LoadModule ext_filter_module modules/mod_ext_filter.so
LoadModule headers_module modules/mod_headers.so
LoadModule ident_module modules/mod_ident.so
LoadModule include_module modules/mod_include.so
LoadModule info_module modules/mod_info.so
LoadModule isapi_module modules/mod_isapi.so
LoadModule ldap_module modules/mod_ldap.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule speling_module modules/mod_speling.so
LoadModule status_module modules/mod_status.so
LoadModule unique_id_module modules/mod_unique_id.so
LoadModule usertrack_module modules/mod_usertrack.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule ssl_module modules/mod_ssl.so
ServerAdmin admin@localhost
ServerName localhost:80
DocumentRoot "C:/xampp/htdocs"

    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Deny from all

Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all

DirectoryIndex index.php index.php4 index.php3 index.cgi index.pl index.html index.htm index.shtml index.phtml

Order allow,deny
Deny from all

ErrorLog logs/error.log
LogLevel warn

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio

CustomLog logs/access.log common
ScriptAlias /cgi-bin/ "C:/xampp/cgi-bin/"

AllowOverride All
Options None
Order allow,deny
Allow from all

DefaultType text/plain

TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddHandler cgi-script .cgi
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml

EnableMMAP off
EnableSendfile off
Include conf/extra/httpd-xampp.conf
Include conf/extra/httpd-multilang-errordoc.conf
Include conf/extra/httpd-autoindex.conf
Include conf/extra/httpd-languages.conf
Include conf/extra/httpd-userdir.conf
Include conf/extra/httpd-info.conf
Include conf/extra/httpd-vhosts.conf
Include conf/extra/httpd-manual.conf
Include conf/extra/httpd-dav.conf
Include conf/extra/httpd-default.conf
Include conf/extra/httpd-ssl.conf

SSLRandomSeed startup builtin
SSLRandomSeed connect builtin

VHOSTS
c:/xampp/apache/conf/extra/httpd-vhosts.conf

NameVirtualHost *:80

DocumentRoot "c:\xampp\htdocs\myapp"
ServerName myapp.local
SetEnv APPLICATION_ENV "development"

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule !\.(js|ico|gif|jpg|png|css|php)$ \index.php
RewriteBase /
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all

WINDOWS HOSTS
c:/windows/system32/drivers/etc/hosts

127.0.0.1       localhost

INDEX.PHP
c:/xampp/htdocs/myapp/index.php
(Really does start with < ?php and doesn’t end with ?>)

< ?php // Define path to application directory defined('APPLICATION_PATH')     || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application')); // Define application environment defined('APPLICATION_ENV')     || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production')); // Ensure library/ is on include_path set_include_path(implode(PATH_SEPARATOR, array(     realpath(APPLICATION_PATH . '/../library'),     get_include_path(), ))); /** Zend_Application */ require_once 'Zend/Application.php';   // Create application, bootstrap, and run $application = new Zend_Application(     APPLICATION_ENV,      APPLICATION_PATH . '/configs/application.ini' ); require_once 'Zend/Mail.php'; $application->bootstrap()
            ->run();

PHPED PROJECT PROPERTIES

PROJECT

Root Directory: c:\xampp\htdocs\myapp
Additional Directories:
Source control: none

PUBLISHING

Account:
Top publishing directory:
Don't publish directories: CVS;.svn

MAPPING

HTTP mode (3rd party WEB server)
Root URL: http://localhost
Remote root directory: c:\xampp\htdocs\myapp

FILES

Default file to run: c:\xampp\htdocs\myapp\index.php
Hide files:
Hide directories: CVS;.svn

PARSER

CHECK Use Project-specific parser properties
PARSER PROPERTIES
Target PHP Version: 5.0 through 5.2
CHECK Support for short PHP tags < ? ?>
UNCHECKED Parse PHP in CSS files
UNCHECKED Support ASP style PHP Tags < % %>
UNCHECKED Parse PHP in Javascript files

DEBUGGER

UNCHECKED Use Project-specific debugger settings

MAPPING

Remote Directory: c:\xampp\htdocs\myapp
Local directory c:\xampp\htdocs\myapp
URL: http://localhost
Publishing Directory:

INTEGRATION

phpdoc_target_dir:

INCLUDES

Use what the debugger puts there

SECRET TO GETTING IT TO WORK IN PHPED

The default PhpED file is index.php.
When you run the project in the debugger
it will create a URL such as:

http://localhost/index.php?DBGSESSID=403496131559100015@clienthost;d=1,p=0,c=1

And it will just keep recycling in the debugger,
the call stack always going back to the first
line of index.php.

GET RID OF INDEX.PHP:

Change the URL to http://localhost

Zend Server and XAMPP .htaccess mod_rewrite is on but ignored, creates 404′s

Virtual hosts require the rewrite engine be set in the conf rather than the .htaccess file. If you’re using a virtual host, put the mod rewrite commands in the virutal host settings.

Include the vhosts conf file by uncommenting c:\program files\zend\apache2\conf\httpd.conf:

Include conf/extra/httpd-vhosts.conf

Add a virtual host to conf/extra/httpd-vhosts.conf. Note that a conf RewriteCond requires a pre-pended slash where .htaccess doesn’t, so you are rewriting /index.php, not index.php.

NameVirtualHost *:80
<VirtualHost *:80>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
DocumentRoot "c:\Program Files\Zend\Apache2\htdocs\yourapp"
ServerName yourapp.local
SetEnv APPLICATION_ENV development
<Directory "c:\program files\zend\apache2\htdocs\yourapp">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>

Add virtual host server to c:/windows/system32/drivers/etc/hosts:

127.0.0.1 yourapp.local

Restart apache

2013 © Web Programming Answers