Thursday, November 18, 2010

Solution: You don't have permission to access / on this server

Encounter this problem after you set up virtual host in web server?
It is because the folder permission is not set probably.

Here is an example:


<Virtualhost *:80="">
ServerName testhost.com
DocumentRoot "/home/testhost/www"
DirectoryIndex index.php
<Directory "/home/testhost/www">
AllowOverride All
Allow from All
</Directory>


ErrorLog "logs/testhost-error.log"
CustomLog "logs/testhost-access.log" common
</Virtualhost>

Make sure to set permission 755 for each folder in the document root path
/home <- 755
/home/testhost <-- 755
/home/testhost/www <-- 755

Thursday, November 11, 2010

Custom error500 / 400 page in symfony 1.4

Custom 400 page:

In config/settings.yml,
all:
  .actions:
    error_404_module:       error
    error_404_action:       404

Then when a page is not found, it will forward to "<your_domain>/error/404".

Custom 500 page:

1. Create "error" folder under "config"
2. create "error.html.php" under "config/error"

Monday, November 1, 2010

Solution: route has some missing mandatory parameters

This time I encountered an error in symfony, I set a new route and got this error.
The route is like this:

new_page:
  url: /new/page/:id
  param: {module: page, action: new}
  requirements:
    id: \d+

How to fix?
1. Add a default value.


new_page:
  url: /new/page/:id
  param: {module: page, action: new, id: 0}
  requirements:
    id: \d+


2. Check if you used any routing functions like url_for2() that missing the input parameter.

Sunday, October 24, 2010

Solution - "Fatal error: Maximum execution time of 30 seconds exceeded"

There are two methods to solve this problem (Fatal error: Maximum execution time of 30 seconds exceeded).

Method 1:
Step 1 : Open php.ini
Step 2 : Modify the value of "max_execution_time" to a greater value say 600
Step 3: Restart Server
Done.

Method 2 (Recommended):
Add "set_limit_time(600)" in your code, where the input parameter is the max execution time, and 0 means unlimited.

Explanation:
You should be aware of this error message, because it should not take more than 30s to complete a script normally. Sometime, it may because of coding mistakes like (infinity loop in your code).

However, you may really need to execute heavy code in many cases, then I would recommend you to use the method 2 to solve this problem.

Sunday, October 10, 2010

PHP Filter - email validation

For PHP5, you can validate email format as below:

$email = 'testemail@xxx.com';  
  
if( filter_var($email, FILTER_VALIDATE_EMAIL) )  
 echo 'Valid email format!';  
else  
 echo 'Invalid email format!'; 

For PHP version less than 5.0, you have to use regular expression to validate email format.

$email = 'testemail@xxx.com';  
  
if( eregi('^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$', $email) ) 
 echo 'Valid email format!';  
else  
 echo 'Invalid email format!'; 


For reference:

You can found out more build-in validates at php.net each as URL, IP validation which are very useful.
http://php.net/manual/en/filter.filters.validate.php

Friday, October 8, 2010

An IDE to recommend - NetBeans

A workman must first sharpen his tools if he is to do his work well. --- A famous word from China.



A good IDE can really boost up your speed on developing.
I tried notepad++ and eclipse before, finally I think NetBeans is the best.

For the php version,
it supports some frameworks like Zend Framework, symfony, smarty.
Let's download and try it!

NetBeans website

Thursday, October 7, 2010