Showing posts with label CakePHP. Show all posts
Showing posts with label CakePHP. Show all posts

Thursday, August 29, 2013

Issue encounter and simple note on CakePHP 2.3.9 & WAMP 2.4 exploration

How to disable debug mode on cakephp? (Please refer to the selected red rectangle)



Steps to resolve
1. Open core.php located at "[WAMP_INSTALL_PATH]\app\config".
2. Edit debug value to "0" and deploy to the server
<?php
    Configure::write('debug', 0);
?>
3. Deploy to the server, the debug mode will be disabled.

How to resolve "Forbidden You don't have permission to access / on this server." error message when access the new installed WAMP server version 2.4?

Description
Install a new WAMP server and when access the web server using the assigned IP address through browser, "Forbidden You don't have permission to access / on this server." error message is displayed.

When using localhost/127.0.0.1 in the local machine to access the WAMP server, the default WAMP page is displayed.

Steps to resolve
1. Edit https.conf which located at "[WAMP_INSTALL_PATH]\bin\apache\Apache2.4.4\conf", edit the configuration as shown below
<Directory "[WAMP_INSTALL_PATH]/www">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order Deny,Allow
    Allow from all
</Directory>

2. Make sure port 80 in Window 2008 firewall  is opened.
- Launch "Windows Firewall with Advanced Security" screen
- Right click "Inbound Rules" and select "New Rule..." menu
- Select "Port - Rule that controls connections for a TCP or UDP port", click "Next" button
- Select "TCP" type and enter "80" for "Specific local ports", click "Next" button
- Select "Allow the connection" and click"Next" button
- Check "Domain", "Private" and "Public" checkbox and click on "Next" button
- Enter "Name" and "Description" value and click on "Finish" button.

3. Restart WAMP server, WAMP index page will be displayed.

How to redirect all the visitor's request to a particular subdirectory?

Description
When came to a requirement to redirect all visitor request to a particular subdirectory, for example /myapp/ in your PHP web application, normally I will use Apache rewrite feature to redirect all the request.

Steps to resolve
1. Edit httpd.conf and uncomment "LoadModule rewrite_module modules/mod_rewrite.so"
2. I have enable the virtual host configuration, add in the rewrite engine as described below

<VirtualHost *:80>
 ServerName [SERVER_NAME]
 DocumentRoot "C:/wamp/www"
        ErrorLog "c:/wamp/logs/apache_error.log"
        CustomLog "c:/wamp/logs/access.log" common
 RewriteEngine on
 RewriteRule ^/$ /[MY_APP_DEFAULT_FOLDER]/ [R]
</VirtualHost>
3. Rewrite your Apache web server.

Friday, August 9, 2013

How to get your first CakePHP tutorial work on WAMP?

In getting first CakePHP example works on WAMP, steps below illustrated how I get through.

1. Download CakePHP framework from GitHub: https://github.com/cakephp/cakephp/tags
2. Unzip CakePHP source code and place it in
"[WAMP_INSTALL_PATH]\wamp\www\cakephp" directory.
3. Create Post.php in "/app/Model" directory.
<?php
    class Post extends AppModel {
  
    }
?>
4. Create PostsController.php in "/app/Controller" directory.
<?php
class PostsController extends AppController {
    public $helpers = array('Html', 'Form');
 
  public function index() {
        $this->set('posts', $this->Post->find('all'));
    }
}
?>
5. Create index.ctp in "/app/View" directory.
<h1>Blog posts</h1>
<table>
    <tr>
        <th>Id</th>
        <th>Title</th>
        <th>Created</th>
    </tr>

    <!-- Here is where we loop through our $posts array, printing out post info -->

    <?php foreach ($posts as $post): ?>
    <tr>
        <td><?php echo $post['Post']['id']; ?></td>
        <td>
            <?php echo $this->Html->link($post['Post']['title'],
array('controller' => 'posts', 'action' => 'view', $post['Post']['id'])); ?>
        </td>
        <td><?php echo $post['Post']['created']; ?></td>
    </tr>
    <?php endforeach; ?>
    <?php unset($post); ?>
</table>

Note: To get this example to work on WAMP, uncomment "LoadModule rewrite_module modules/mod_rewrite.so" in httpd.conf file. Restart Apache Web Server.

6. Type in "http://localhost/cakephp/posts/index" in your browser to access this example.

Once able to get the first example to work, please follow with the example provided in CakePHP website to continue with the further exploration.