Home > centOS, Fedora 12, PHP, Unix/Linux, Zend > PHP – zend install, zend start

PHP – zend install, zend start

Zend framework? i will make it so  easy, that a just born baby can use it?

* Follow steps 1 ………6 sucks according to zend guide. :

* Follow steps 7 ……… rest works

1. [root@www html]# whereis php
php: /usr/bin/php /etc/php.d /etc/php.ini /usr/lib/php /usr/include/php /usr/share/man/man1/php.1.gz
[root@www html]#

2. [root@www ~]# ln -s /root/zend/bin/zf.sh /usr/local/bin/zf

3. [root@www ~]# php -i | grep include_path
include_path => .:/usr/share/pear:/usr/share/php => .:/usr/share/pear:/usr/share/php
[root@www ~]#

4. vi /etc/php.ini (change like this!)

[root@www etc]# grep include_path /etc/php.ini
; (directory must also be in include_path or full path must
;include_path = “.:/php/includes”
include_path = “.:/usr/share/pear:/usr/share/php:/root/zend/library
;include_path = “.;c:\php\includes”
[root@www etc]#

5. [root@www etc]# service httpd status
httpd (pid  4102) is running…
[root@www etc]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[root@www etc]# php -i | grep include_path
include_path => .:/usr/share/pear:/usr/share/php:/root/zend/library => .:/usr/share/pear:/usr/share/php:/root/zend/library
[root@www etc]#

6. [root@www etc]# zf –help
PHP Fatal error:  Cannot access self:: when no class scope is active in /root/zend/library/Zend/Tool/Framework/Provider/Signature.php on line 355

Fatal error: Cannot access self:: when no class scope is active in /root/zend/library/Zend/Tool/Framework/Provider/Signature.php on line 355
[root@www etc]#

Damn! incompatibility with centOS!! what i do what i do?
* why? because zend doesnt shift with latest php on it, and centOS doesnt shift also with, so using zend means get infected with mysql/php updates.


7.    [root@www etc]# wget -q -O – http://www.atomicorp.com/installers/atomic.sh | sh

Atomic Archive installer, version 1.1
Configuring the [atomic] yum archive for this system

Installing the Atomic GPG key: OK
Downloading atomic-release-1.0-11.el5.art.noarch.rpm: OK

The Atomic Rocket Turtle archive has now been installed and configured for your system
The following channels are available:
atomic          – [ACTIVATED] – contains the stable tree of ART packages
atomic-testing  – [DISABLED]  – contains the testing tree of ART packages
atomic-bleeding – [DISABLED]  – contains the development tree of ART packages

[root@www etc]# yum list php-zend-optimizer
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* addons: ftp.belnet.be
* atomic: http://www.atomicorp.com
* base: ftp.belnet.be
* contrib: ftp.belnet.be
* extras: ftp.belnet.be
* rpmforge: fr2.rpmfind.net
* updates: ftp.belnet.be
atomic                                                                                                                                       | 1.9 kB     00:00
atomic/primary_db                                                                                                                            | 345 kB     00:01
Available Packages
php-zend-optimizer.i386                                                           1:3.3.9-1.el5.art                                                           atomic

[root@www etc]# php -v
Failed loading /usr/lib/php/zend/ZendOptimizer-5.2.so:  /usr/lib/php/zend/ZendOptimizer-5.2.so: cannot restore segment prot after reloc: Permission denied
PHP 5.2.12 (cli) (built: Jan 31 2010 11:31:11)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies

8. Is it done? no, the red i need to solve, because  crash kernel SELinux, i never stop this, because  respect centOS!

Summary:

SELinux is preventing php from loading /usr/lib/php/zend/ZendOptimizer-5.2.so
which requires text relocation.

Detailed Description:

The php application attempted to load /usr/lib/php/zend/ZendOptimizer-5.2.so
which requires text relocation. This is a potential security problem. Most
libraries do not need this permission. Libraries are sometimes coded incorrectly
and request this permission. The SELinux Memory Protection Tests
(http://people.redhat.com/drepper/selinux-mem.html) web page explains how to
remove this requirement. You can configure SELinux temporarily to allow
/usr/lib/php/zend/ZendOptimizer-5.2.so to use relocation as a workaround, until
the library is fixed. Please file a bug report
(http://bugzilla.redhat.com/bugzilla/enter_bug.cgi) against this package.

Allowing Access:

If you trust /usr/lib/php/zend/ZendOptimizer-5.2.so to run correctly, you can
change the file context to textrel_shlib_t. “chcon -t textrel_shlib_t
‘/usr/lib/php/zend/ZendOptimizer-5.2.so'” You must also change the default file
context files on the system in order to preserve them even on a full relabel.
“semanage fcontext -a -t textrel_shlib_t
‘/usr/lib/php/zend/ZendOptimizer-5.2.so'”

The following command will allow this access:

chcon -t textrel_shlib_t ‘/usr/lib/php/zend/ZendOptimizer-5.2.so’

Additional Information:

Source Context                user_u:system_r:unconfined_t
Target Context                system_u:object_r:lib_t
Target Objects                /usr/lib/php/zend/ZendOptimizer-5.2.so [ file ]
Source                        php
Source Path                   /usr/bin/php
Port                          <Unknown>
Host                          http://www.shamun.be
Source RPM Packages           php-cli-5.2.12-3.el5.art
Target RPM Packages           php-zend-optimizer-3.3.9-1.el5.art
Policy RPM                    selinux-policy-2.4.6-255.el5_4.4
Selinux Enabled               True
Policy Type                   targeted
MLS Enabled                   True
Enforcing Mode                Enforcing
Plugin Name                   allow_execmod
Host Name                     http://www.shamun.be
Platform                      Linux http://www.shamun.be 2.6.18-164.11.1.el5 #1 SMP Wed
Jan 20 07:39:04 EST 2010 i686 i686
Alert Count                   1
First Seen                    Mon 22 Feb 2010 07:52:49 PM CET
Last Seen                     Mon 22 Feb 2010 07:52:49 PM CET
Local ID                      e0bc69b0-5d7c-446f-8241-129480c2cdfd
Line Numbers

Raw Audit Messages

host=www.shamun.be type=AVC msg=audit(1266864769.534:113): avc:  denied  { execmod } for  pid=6877 comm=”php” path=”/usr/lib/php/zend/ZendOptimizer-5.2.so” dev=dm-0 ino=18030888 scontext=user_u:system_r:unconfined_t:s0 tcontext=system_u:object_r:lib_t:s0 tclass=file

host=www.shamun.be type=SYSCALL msg=audit(1266864769.534:113): arch=40000003 syscall=125 success=no exit=-13 a0=d8d000 a1=14b000 a2=5 a3=bfa8b430 items=0 ppid=5899 pid=6877 auid=500 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts2 ses=2 comm=”php” exe=”/usr/bin/php” subj=user_u:system_r:unconfined_t:s0 key=(null)

9. shot for  Selinux

[root@www etc]# chcon -t textrel_shlib_t ‘/usr/lib/php/zend/ZendOptimizer-5.2.so’

[root@www html]# php -v
PHP 5.2.12 (cli) (built: Jan 31 2010 11:31:11)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies

*No red lines

[root@www html]# zf –help

* no SELinux crash, works now

10. [root@www html]# zf create project zendsucks
Creating project at /var/www/html/zendsucks
Note: This command created a web project, for more information setting up your VHOST, please see docs/README
PHP Fatal error:  Class ‘DOMDocument’ not found in /root/zend/library/Zend/Tool/Project/Profile/FileParser/Xml.php on line 82

Fatal error: Class ‘DOMDocument’ not found in /root/zend/library/Zend/Tool/Project/Profile/FileParser/Xml.php on line 82

11. [root@www Gdata]# pwd
/root/zend/demos/Zend/Gdata
[root@www Gdata]# php InstallationChecker.php
== Ran PHP Installation Checker using CLI ==
PHP Extension Errors — Tested
Error number: 0
–dom extension missing – refer to http://us.php.net/manual/en/book.dom.php
Zend Framework Installation Errors — Not tested
SSL Capabilities Errors — Not tested
YouTube API Connectivity Errors — Not tested

12. yum install php-xml

13. [root@www Gdata]# php InstallationChecker.php
== Ran PHP Installation Checker using CLI ==
PHP Extension Errors — No errors found
Zend Framework Installation Errors — No errors found
SSL Capabilities Errors — No errors found
YouTube API Connectivity Errors — No errors found

14. [root@www html]# zf create project zendsucks

[root@www zendsucks]# tree
.
|– application
|   |– Bootstrap.php
|   |– configs
|   |   `– application.ini
|   |– controllers
|   |   |– ErrorController.php
|   |   `– IndexController.php
|   |– models
|   `– views
|       |– helpers
|       `– scripts
|           |– error
|           |   `– error.phtml
|           `– index
|               `– index.phtml
|– docs
|   `– README.txt
|– library
|– public
|   `– index.php
`– tests
|– application
|   `– bootstrap.php
|– library
|   `– bootstrap.php
`– phpunit.xml

15 directories, 11 files

15. [root@www zend]# pwd
/root/zend
[root@www zend]# ls
bin  demos  externals  extras  incubator  INSTALL.txt  library  LICENSE.txt  README.txt  resources  src  tests
[root@www zend]# cp -r library /var/www/html/zendsucks/

16. vi /etc/…httpd.conf
<VirtualHost *:80>
ServerName dummy.com
DocumentRoot /var/www/html/zendsucks/public
#SetEnv APPLICATION_ENV “development”
<Directory /var/www/html/zendsucks/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>

</VirtualHost>

[root@www zendsucks]# zf show version
Zend Framework Version: 1.10.1

Done

Layout steps:

===============

1. Layout

zf enable layout


Model and Database table steps:

===============================

1. setup this> aplication/configs/application.ini

[root@www zendsucks]# zf configure db-adapter \
‘adapter=PDO_SQLITE&dbname=APPLICATION_PATH “/../data/db/guestbook.db”‘ production

[root@www zendsucks]# zf configure db-adapter \
‘adapter=PDO_SQLITE&dbname=APPLICATION_PATH “/../data/db/guestbook.db”‘ testing

[root@www zendsucks]# zf configure db-adapter \
‘adapter=PDO_SQLITE&dbname=APPLICATION_PATH “/../data/db/guestbook.db”‘ development

2. Make directory
mkdir -p data/db; chmod -R a+rwX data

3. create 3  files, load data, create Dbtable/Guestbook.php

a. schema.sqlite.sql

b. data.sqlite.sql

c. load.sqlite.php

[root@www scripts]# php load.sqlite.php –withdata
Writing Database Guestbook in (control-c to cancel):
1
Database Created
Data Loaded.

d.
[root@www zendsucks]# zf create db-table Guestbook guestbook
Creating a DbTable at /var                                       ls/DbTable/Guestbook.php
Updating project profile ‘                                       ml’

4. mapper/model/controller create

[root@www zendsucks]# zf create model GuestbookMapper
Creating a model at /var/www/html/zendsucks/application/models/GuestbookMapper.php
Updating project profile ‘/var/www/html/zendsucks/.zfproject.xml’

[root@www zendsucks]# zf create model Guestbook
Creating a model at /var/www/html/zendsucks/application/models/Guestbook.php
Updating project profile ‘/var/www/html/zendsucks/.zfproject.xml’

[root@www zendsucks]# zf create controller Guestbook
Creating a controller at /var/www/html/zendsucks/application/controllers/GuestbookController.php
Creating an index action method in controller Guestbook
Creating a view script for the index action method at /var/www/html/zendsucks/application/views/scripts/guestbook/index.phtml
Creating a controller test file at /var/www/html/zendsucks/tests/application/controllers/GuestbookControllerTest.php
Updating project profile ‘/var/www/html/zendsucks/.zfproject.xml’

5. put the codes for /var/www/html/zendsucks/application/models/

// DbTable/Guestbook.php
class Application_Model_DbTable_Guestbook extends Zend_Db_Table_Abstract
{

protected $_name = ‘guestbook’;

}

//GuestbookMapper.php

class Application_Model_GuestbookMapper

{

protected $_dbTable;

public function setDbTable($dbTable)

{

if (is_string($dbTable)) {

$dbTable = new $dbTable();

}

if (!$dbTable instanceof Zend_Db_Table_Abstract) {

throw new Exception(‘Invalid table data gateway provided’);

}

$this->_dbTable = $dbTable;

return $this;

}

public function getDbTable()

{

if (null === $this->_dbTable) {

$this->setDbTable(‘Application_Model_DbTable_Guestbook’);

}

return $this->_dbTable;

}

public function save(Application_Model_Guestbook $guestbook)

{

$data = array(

’email’   => $guestbook->getEmail(),

‘comment’ => $guestbook->getComment(),

‘created’ => date(‘Y-m-d H:i:s’),

);

if (null === ($id = $guestbook->getId())) {

unset($data[‘id’]);

$this->getDbTable()->insert($data);

} else {

$this->getDbTable()->update($data, array(‘id = ?’ => $id));

}

}

public function find($id, Application_Model_Guestbook $guestbook)

{

$result = $this->getDbTable()->find($id);

if (0 == count($result)) {

return;

}

$row = $result->current();

$guestbook->setId($row->id)

->setEmail($row->email)

->setComment($row->comment)

->setCreated($row->created);

}

public function fetchAll()

{

$resultSet = $this->getDbTable()->fetchAll();

$entries   = array();

foreach ($resultSet as $row) {

$entry = new Application_Model_Guestbook();

$entry->setId($row->id)

->setEmail($row->email)

->setComment($row->comment)

->setCreated($row->created);

$entries[] = $entry;

}

return $entries;

}

}

//Guestbook.php

class Application_Model_Guestbook
#
{
#
protected $_comment;
#
protected $_created;
#
protected $_email;
#
protected $_id;
#

#
public function __construct(array $options = null)
#
{
#
if (is_array($options)) {
#
$this->setOptions($options);
#
}
#
}
#

#
public function __set($name, $value)
#
{
#
$method = ‘set’ . $name;
#
if ((‘mapper’ == $name) || !method_exists($this, $method)) {
#
throw new Exception(‘Invalid guestbook property’);
#
}
#
$this->$method($value);
#
}
#

#
public function __get($name)
#
{
#
$method = ‘get’ . $name;
#
if ((‘mapper’ == $name) || !method_exists($this, $method)) {
#
throw new Exception(‘Invalid guestbook property’);
#
}
#
return $this->$method();
#
}
#

#
public function setOptions(array $options)
#
{
#
$methods = get_class_methods($this);
#
foreach ($options as $key => $value) {
#
$method = ‘set’ . ucfirst($key);
#
if (in_array($method, $methods)) {
#
$this->$method($value);
#
}
#
}
#
return $this;
#
}
#

#
public function setComment($text)
#
{
#
$this->_comment = (string) $text;
#
return $this;
#
}
#

#
public function getComment()
#
{
#
return $this->_comment;
#
}
#

#
public function setEmail($email)
#
{
#
$this->_email = (string) $email;
#
return $this;
#
}
#

#
public function getEmail()
#
{
#
return $this->_email;
#
}
#

#
public function setCreated($ts)
#
{
#
$this->_created = $ts;
#
return $this;
#
}
#

#
public function getCreated()
#
{
#
return $this->_created;
#
}
#

#
public function setId($id)
#
{
#
$this->_id = (int) $id;
#
return $this;
#
}
#

#
public function getId()
#
{
#
return $this->_id;
#
}
#
}

put the code  for /var/www/html/zendsucks/application/controllers/

// GuestbookController.php

class GuestbookController extends Zend_Controller_Action
#
{
// by first
public function init()
{
/* Initialize action controller here */
}

// by second
public function indexAction()
{
// action body
}

#
public function indexAction()
#
{
#
$guestbook = new Application_Model_GuestbookMapper();
#
$this->view->entries = $guestbook->fetchAll();
#
}
#
}

// application/views/scripts/guestbook/index.phtml
<p><a href=”<?php echo $this->url(

array(

‘controller’ => ‘guestbook’,

‘action’     => ‘sign’

),

‘default’,

true) ?>”>Sign Our Guestbook</a></p>

Guestbook Entries: <br />

<dl>

<?php foreach ($this->entries as $entry): ?>

<dt><?php echo $this->escape($entry->email) ?></dt>

<dd><?php echo $this->escape($entry->comment) ?></dd>

<?php endforeach ?>

</dl>

Form step:

==============

1.

[root@www zendsucks]# zf create form Guestbook
Creating a form at /var/www/html/zendsucks/application/forms/Guestbook.php
Updating project profile ‘/var/www/html/zendsucks/.zfproject.xml’
[root@www zendsucks]# zf create action sign Guestbook
Creating an action named sign inside controller at /var/www/html/zendsucks/application/controllers/GuestbookController.php
Updating project profile ‘/var/www/html/zendsucks/.zfproject.xml’
Creating a view script for the sign action method at /var/www/html/zendsucks/application/views/scripts/guestbook/sign.phtml
Updating project profile ‘/var/www/html/zendsucks/.zfproject.xml’

[root@www zendsucks]#

2.

//Guestbook.php

class Application_Form_Guestbook extends Zend_Form
#
{
#
public function init()
#
{
#
// Set the method for the display form to POST
#
$this->setMethod(‘post’);
#

#
// Add an email element
#
$this->addElement(‘text’, ’email’, array(
#
‘label’      => ‘Your email address:’,
#
‘required’   => true,
#
‘filters’    => array(‘StringTrim’),
#
‘validators’ => array(
#
‘EmailAddress’,
#
)
#
));
#

#
// Add the comment element
#
$this->addElement(‘textarea’, ‘comment’, array(
#
‘label’      => ‘Please Comment:’,
#
‘required’   => true,
#
‘validators’ => array(
#
array(‘validator’ => ‘StringLength’, ‘options’ => array(0, 20))
#
)
#
));
#

#
// Add a captcha
#
$this->addElement(‘captcha’, ‘captcha’, array(
#
‘label’      => ‘Please enter the 5 letters displayed below:’,
#
‘required’   => true,
#
‘captcha’    => array(
#
‘captcha’ => ‘Figlet’,
#
‘wordLen’ => 5,
#
‘timeout’ => 300
#
)
#
));
#

#
// Add the submit button
#
$this->addElement(‘submit’, ‘submit’, array(
#
‘ignore’   => true,
#
‘label’    => ‘Sign Guestbook’,
#
));
#

#
// And finally add some CSRF protection
#
$this->addElement(‘hash’, ‘csrf’, array(
#
‘ignore’ => true,
#
));
#
}
#
}

// GuestbookController

#
class GuestbookController extends Zend_Controller_Action
#
{
#
// snipping indexAction()…
#

#
public function signAction()
#
{
#
$request = $this->getRequest();
#
$form    = new Application_Form_Guestbook();
#

#
if ($this->getRequest()->isPost()) {
#
if ($form->isValid($request->getPost())) {
#
$comment = new Application_Model_Guestbook($form->getValues());
#
$mapper  = new Application_Model_GuestbookMapper();
#
$mapper->save($comment);
#
return $this->_helper->redirector(‘index’);
#
}
#
}
#

#
$this->view->form = $form;
#
}
#
}

// sign.pthml
Please use the form below to sign our guestbook!

<?php

$this->form->setAction($this->url());

echo $this->form;

Done, zend quickstart, it finally sucks and works.

  1. class Application_Form_Guestbook extends Zend_Form
  2. {
  3. public function init()
  4. {
  5. // Set the method for the display form to POST
  6. $this->setMethod(‘post’);
  7. // Add an email element
  8. $this->addElement(‘text’, ’email’, array(
  9. ‘label’ => ‘Your email address:’,
  10. ‘required’ => true,
  11. ‘filters’ => array(‘StringTrim’),
  12. ‘validators’ => array(
  13. ‘EmailAddress’,
  14. )
  15. ));
  16. // Add the comment element
  17. $this->addElement(‘textarea’, ‘comment’, array(
  18. ‘label’ => ‘Please Comment:’,
  19. ‘required’ => true,
  20. ‘validators’ => array(
  21. array(‘validator’ => ‘StringLength’, ‘options’ => array(0, 20))
  22. )
  23. ));
  24. // Add a captcha
  25. $this->addElement(‘captcha’, ‘captcha’, array(
  26. ‘label’ => ‘Please enter the 5 letters displayed below:’,
  27. ‘required’ => true,
  28. ‘captcha’ => array(
  29. ‘captcha’ => ‘Figlet’,
  30. ‘wordLen’ => 5,
  31. ‘timeout’ => 300
  32. )
  33. ));
  34. // Add the submit button
  35. $this->addElement(‘submit’, ‘submit’, array(
  36. ‘ignore’ => true,
  37. ‘label’ => ‘Sign Guestbook’,
  38. ));
  39. // And finally add some CSRF protection
  40. $this->addElement(‘hash’, ‘csrf’, array(
  41. ‘ignore’ => true,
  42. ));
  43. }
  44. }
Advertisements
Categories: centOS, Fedora 12, PHP, Unix/Linux, Zend Tags:
  1. May 23, 2010 at 8:04 pm

    celexa and social phobia

  2. Mike Daniels
    July 16, 2010 at 9:27 pm

    Hello,

    Great guide, but I’ve run into trouble running the InstallationChecker.php. I get the following error

    –Exception thrown trying to access Zend/Loader.php using ‘use_include_path’ = true. Make sure you include Zend Framework in your include_path which currently contains: “.:/usr/share/pear:/usr/share/php:/root/zend/library“

    I have no idea why its unable to load the file, I figured it may be a permissions issue but I went ahead and changed the permissions to 777 and I still get the same error.

    Any thoughts?

  3. August 5, 2012 at 11:55 pm

    Hi there, I enjoy reading through your post.
    I wanted to write a little comment to support you.

  4. January 2, 2014 at 4:29 pm

    Hi there all, here every person is sharing these experience, therefore it’s pleasant to
    read this webpage, and I used to pay a quick visit this
    weblog every day.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: