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.

Monday, August 26, 2013

How to get your first Zend framework work on WAMP?

This is not a new thing and you can find this anywhere, I just note it down for my personal reference just in case I'm too old to remember all this.

OS: Window 7 Enterprise
WAMP version 2.4

1. Download Zend project skeleton from https://github.com/zendframework/ZendSkeletonApplication

2. Unzip the Zend framework and rename it as "ZendProject".

3. Open DOS prompt and change to the "ZendProject folder"

4. Type in the command as shown below to download Zend framework
php composer.phar self-update

5. Type in the command as shown below to install Zend framework.
php composer.phar install
During executing this command line, you might encounter the error as shown below.
You must enable the openssl extension to download files via https
To resolve this error, please enable openssl at WAMP server. Open php.ini located at [WAMP_HOME_FOLDER]\bin\php\php5.4.12 uncomment extension=php_openssl.dll

6. Once the installation has been completed, the output as described below will be displayed
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing zendframework/zendframework (2.2.3)
    Downloading: 100%

zendframework/zendframework suggests installing ext-intl (ext/intl for i18n feat
ures (included in default builds of PHP))
zendframework/zendframework suggests installing doctrine/annotations (Doctrine A
nnotations >=1.0 for annotation features)
zendframework/zendframework suggests installing ircmaxell/random-lib (Fallback r
andom byte generator for Zend\Math\Rand if OpenSSL/Mcrypt extensions are unavail
able)
zendframework/zendframework suggests installing ocramius/proxy-manager (ProxyMan
ager to handle lazy initialization of services)
zendframework/zendframework suggests installing zendframework/zendpdf (ZendPdf f
or creating PDF representations of barcodes)
zendframework/zendframework suggests installing zendframework/zendservice-recapt
cha (ZendService\ReCaptcha for rendering ReCaptchas in Zend\Captcha and/or Zend\
Form)
Writing lock file
Generating autoload files

7. In WAMP server, I enabled vhost file by uncomment "Include conf/extra/httpd-vhosts.conf" in [WAMP_HOME_FOLDER]\bin\apache\Apache2.4.4\conf folder.

8. Add the configuration as displayed below in httpd-vhosts.conf file located at [WAMP_HOME_FOLDER]\bin\apache\Apache2.4.4\conf\extra folder.
<VirtualHost *:80>
    ServerName zend2
    DocumentRoot D:/work/research/Zend/ZendProject/public
    SetEnv APPLICATION_ENV "development"
    <Directory D:/work/research/Zend/ZendProject/public>
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

9. Edit "hosts" file located at C:\Windows\System32\drivers\etc folder.
127.0.0.1       zend2 localhost

10. Open the browser, type in URL "http://zend2/", the Zend2 framework page as displayed below will be displayed

Sunday, August 11, 2013

Issue encounter and simple note on Google AppEngine exploration

Issue 1

During the deployment of the sample app "Guestbook" to AppEngine through Eclipse, error message "Unable to update app: Cannot get the System Java Compiler. Please use a JDK, not a JRE." is prompted. Please refer to the screenshot as shown below:


Steps to resolve
1. Open the eclipse.ini, normally located at "ECLIPSE home path".
2. Add configuration as shown below in the first line of eclipse.ini.
-vm
[JAVA_HOME_PATH]/bin/javaw.exe
3. Restart Eclipse and redeploy the app to AppEngine, you will be able to get this through.

Issue 2

Try to use Jersey (version 1.7) to create JAX-RS service on Google App Engine, please refer to http://tugdualgrall.blogspot.sg/2010/02/create-and-deploy-jax-rs-rest-service.html.
Encounter the error in AppEngine log as described below when use browser to call the service.

Uncaught exception from servlet
java.lang.IncompatibleClassChangeError: Implementing class
 at com.google.appengine.runtime.Request.process-638cb79974cf6c0a(Request.java)
 at java.lang.ClassLoader.defineClass1(Native Method)
 at java.lang.ClassLoader.defineClass(ClassLoader.java:794)
 at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
 at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
 at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:601)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:359)
 at com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:79)
 at com.sun.jersey.api.core.PackagesResourceConfig.init(PackagesResourceConfig.java:104)
 at com.sun.jersey.api.core.PackagesResourceConfig.(PackagesResourceConfig.java:78)
 at com.sun.jersey.api.core.PackagesResourceConfig.(PackagesResourceConfig.java:89)
 at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:696)
 at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:674)
 at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:203)
 at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:374)
 at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:557)
 at javax.servlet.GenericServlet.init(GenericServlet.java:212)
 at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:440)
 at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:263)
 at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
 at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:685)
 at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
 at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
 at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
 at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
 at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
 at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:435)
 at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:442)
 at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:186)
 at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:306)
 at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:298)
 at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:439)
 at java.lang.Thread.run(Thread.java:722)

Steps to resolve
1. Right click project in Eclipse and select "Properties".
2. Change "Datanuclues JDO/JPA version to "v1". Please refer to screenshot as described below.


3. Redeploy the app to AppEngine. You should be able to call the service.

Reason: The used of asm-4.0.jar by AppEngine crash with the Jersey 1.7.

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.

Saturday, August 3, 2013

Issue encounter and simple note on Android Studio exploration

Issue 1

Change the IDE for my current project that used to develop on "Eclipse" to "Android Studio", encounter the error and issue as described below

1. Prompted the error message "unmappable character for encoding UTF-8" when build my current project on Android Studio.

- Click on "File" -> "Setting"
- Select File Encodings in the left menu
- Change IDE Encoding from "UTF-8" to "ISO-88590-1"

Rebuild the project.