Archive for the ‘PHP’ Category

Internal Server Error

Friday, January 15th, 2010

SuPHP Permission Issue

suPHP enhances overall server security. When migrating from a server that is not running suphp to a server running these, permission and ownership issues occur . When you access your domain you usually see

s1

Tail the Apache error logs to see what the error is

# tail -f /usr/local/apache/logs/error_logs

You can see the error

[Thu Jul 12 09:00:09 2007] [error] [client XXX.XXX.X.X] SoftException in Application.cpp:601: Directory “/home/user/public_html/test.php” is writable by group .

[Thu Jul 12 09:00:11 2007] [error] [client XXX.XXX.X.X] Premature end of script headers:

The script fail if the php file or folder is writable for anyone other that the owner. Check the permission and ownership .

# cd /home/user/public_html/

# ll | grep test.php

-rwxrwxrwx 1 nobody nobody 158 2008-05-13 04:32 test.php

That shows test.php has full permission and is not owned by the user . Change the permission and ownership.

# chmod 644 test.php

# chown user.user test.php

If it is a server wide issue , then its difficult to change it for each user . Here is a script (for cpanel servers) that fixes all the files and folder permissions that occurs when server changes to suphp.

1) Save the script to a file .

# vi /root/suphpfix.sh

     #!/bin/bash
     for user in `ls /var/cpanel/users`; do
     chown ${user}:${user} /home/${user}/public_html
     chmod 755 /home/${user}/public_html
     find /home/${user}/public_html -group nobody -print0 | xargs -0 chgrp ${user}
     find /home/${user}/public_html -type f -print0 | xargs -0 chmod 644
     find /home/${user}/public_html -type d -print0 | xargs -0 chmod 755
     done

2) Make the script executable.

# chmod u+x /root/suphpfix.sh

3) Execute the script

# bash /root/suphpfix.sh

How to enable php setting for all Directories

Wednesday, December 2nd, 2009

If you want enable some php related setting by using php.ini file and it reflect to all  other directories which is under your account. Then follow the steps..

First create php.ini file under the document root of your domain and change or add the default setting which you want or which is required for your domain.

for example :

allow_url_fopen = On
allow_url_include = On

then you need to add the following code in your .htaccess file. So you dont need to copy the php.ini file in each directories for chnages to reflect.

SetEnv PHPRC “/home/username/public_html”


Note: Please replace user name is equal to original domain username.

PHP Configuration Directives

Saturday, November 21st, 2009

PHP Configuration Directives

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

output_buffering

One of the newest (and greatest) features of PHP is the ability to send header lines anywhere within a script. This directive turns on output buffering for all files. You should probably leave this set to “off” because calling one of the output buffering functions of PHP will work regardless.

Example:
Turn on output buffering.
output_buffering = On

implicit_flush

This directive is used mainly for debugging purposes because of performance. Used with output_buffering it is equivalent to calling the flush() function after every print(), echo(), and HTML block.

Example:
Turn off implicit flushing of output buffers.
implicit_flush = Off

safe_mode

When PHP is used as a CGI this will ensure that the user can only access information contained in the document root.

Example:
Turn off safe mode.
safe_mode = Off

safe_mode_allowed_env_vars

This allows you to set a prefix to any environmental variables ensuring that only variables you accept can be accessed/set. Multiple prefixes can be set as a comma-delimited list.

Example:
Only allow PHP and HTTP environmental variables.
safe_mode_allowed_env_vars = PHP_, HTTP_

safe_mode_protected_env_vars

Allows you to define, by a comma-delimited list, any environmental variables that can never be changed.

Example:
Protect all HTTP environmental variables.
safe_mode_protected_env_vars = HTTP_

disable_functions

Allows you to define a comma-delimited list of functions to be disabled within PHP.

Example:
Disable certain file-related functions.
disable_functions = fopen, fwrite, popen

max_execution_time

Maximum time a PHP script will execute before timing out. Even if this is set to “off”, the execution time can be defined on a per-script basis using the set_time_limit() function.

Example:
Set maximum execution time to 1 minute.
max_execution_time = 60

memory_limit

Maximum amount of memory a PHP script can consume.

Example:
Limit memory to approximately 8 Mbits.
memory_limit = 8388608

error_reporting

This is a bit-field or named constant directive with the following bit levels added to determine the verbosity of PHP errors.

1  -  E_ERROR    Normal errors
2  -  E_WARNING  Normal warnings
4  -  E_PARSE    Parser errors
8  -  E_NOTICE   Non-critical style-related errors

Example:
Only report the three most critical errors.
error_reporting = E_ERROR | E_WARNING | E_PARSE
Show all errors except notices (shorthand for above example)
error_reporting = E_ALL & ~E_NOTICE

display_errors

This will cause PHP to print out the errors along with the HTML. Helpful for debugging.

Example:
Display errors to the screen.
display_errors = On

log_errors

This directive causes PHP to store errors in a log file which can be defined with the error_log directive.

Example:
Log all errors to a log file.
log_errors = On

track_errors

Stores the last error/warning message in a PHP variable called $php_errormsg.

Example:
Enable the tracking of last error/warning message.
track_errors = On

error_prepend_string

String to output before an error message. This is handy if you want to make all of your errors highlighted in red, for example.

Example:
Highlight all errors in red.
error_prepend_string = "<span style='color: red;'>"

error_append_string

The opposite of error_prepend_string.

Example:
error_append_string = "</span>"

error_log

The directive defines which file you would like PHP to use to log errors. If you want errors to be logged with syslog, you can give the value “syslog” (less the quotes). If you’re using NT, this will log errors in the Event Log.

Example:
Log all errors to ‘/var/log/my_php_errors.log’
error_log = /var/log/my_php_errors.log

track_vars

This turns on $HTTP_GET_VARS, $HTTP_POST_VARS, and $HTTP_COOKIE_VARS arrays.

Example:
Enable track variables.
track_vars = On

magic_quotes_gpc

Turns on magic quotes (escapes single quotes, double quotes, null, and backslash characters) for GET, POST, and cookie data.

Example:
Enable magic quotes.
magic_quotes_gpc = On

magic_quotes_runtime

Automatically escape data generated externally.

Example:
Disable magic quotes runtime.
magic_quotes_runtime = Off

magic_quotes_sybase

In addition to escaping with the standard backslash character (\) this tells PHP to use a single quote as an escape character for Sybase-related escapes.

Example:
Disable magic quotes for Sybase.
magic_quotes_sybase = Off

auto_prepend_file

This tells PHP to automatically tack on the file defined with this directive to the beginning of any file parsed by the PHP engine. This is very useful for defining global variables and making database connections.

Example:
Automatically prepend the file pre.php.
auto_prepend_file = pre.php

auto_append_file

This tells PHP to automatically tack on the file defined with this directive to the end of any file parsed by the PHP engine.

Example:
Automatically append the file post.php.
auto_append_file = post.php

default_charset

Customize the character set of PHP parsed pages.

Example:
Set the default charicter set to Latin-1.
default_charset = "iso-8859-1"

include_path

This tells PHP where to look when the include() and require() functions are used. The format for Unix is just like that of the PATH environmental variable. This is pretty much the same on Windows except that the colon is replaced with a semicolon.

Example:
Set the include path to be the current directiory and /usr/local/lib/php.
include_path = .:/usr/local/lib/php
Windows version of the above example.
include_path = .;/usr/local/lib/php

upload_tmp_dir

This defines where PHP will store uploaded files temporarily until the user can move them to a more permanent location.

Example:
Store all uploaded files in /tmp.
upload_tmp_dir = /tmp

upload_max_filesize

The maximum file size that can be uploaded through PHP.

Example:
Set the maximum uploaded file size to be 2 Mbits.
upload_max_filesize = 2097152

extension_dir

This defines the location where loadable module extensions reside.

Example:
Set the current working directory as the extension directory.
extension_dir = ./

enable_dl

This enables/disables the ability to dynamically load a PHP module extension. This doesn’t work properly on multithreaded servers so it is disabled by default on those systems.

Example:
Enable dynamically loadable modules.
enable_dl = On

extension

This directive defines a dynamically loadable module extension that PHP should load when starting up. This directive can be used any number of times for each extension that you need to load.

Example:
Enable dynamic loading of the mSQL module.
extension = msql.so

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

How to compress CSS with gZIP

Friday, November 20th, 2009

How to compress my CSS with gZIP?

To compress your CSS files with gZIP there are two things that you should do.

First, add the following line to the .htaccess file in your public_html folder:

AddHandler application/x-httpd-php52 .css

By doing this, you allow the server to process .css files through PHP.

Next, add the following lines at the very beginning of your .css file(s):

<?php
ob_start (“ob_gzhandler”);
header(“Content-type: text/css; charset: UTF-8″);
header(“Cache-Control: must-revalidate”);
$offset = 60 * 60 ;
$ExpStr = “Expires: ” .
gmdate(“D, d M Y H:i:s”,
time() + $offset) . ” GMT”;
header($ExpStr);
?>

By doing this, you will enable the gZIP compression for your CSS file. For bigger websites there will be a significant improvement in the loading speed of your pages.

Fatal error: Call to undefined function: strripos() in

Monday, November 16th, 2009

Error : Fatal error: Call to undefined function: strripos() in

Solution : strripos() is a working on only php5 . So you need to switch you account to php5 installed server or if php4 and php5 is installed on the same server then add the folloging code in .htaccess file to switch to php5.

AddHandler application/x-httpd-php5 .php

How to install PDFlib on linux server

Thursday, November 12th, 2009

You can easily install PDFlib on linux server.

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

cd /usr/local/src/

wget  ftp://ftp.free.fr/.mirrors1/ftp.netbsd.org/packages/distfiles/PDFlib-Lite-7.0.3.tar.gz

or

check this URL  http://www.filewatcher.com/m/PDFlib-Lite-7.0.3.tar.gz.5898798.0.0.html

tar -zxf PDFlib-Lite-7.0.3.tar.gz

cd PDFlib-Lite-7.0.3

./configure

make

make install

mount -o remount rw /tmp

pecl install pdflib

mount -o remount noexec,nosuid,rw  /tmp

php -m | grep pdf

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

Done

Redirect by using php code

Wednesday, November 11th, 2009

How to redirect index.php page to another url by using php code.

If you want to redirect your index.php page to another URL or page then add the following code in your index.php page.

<?php
header( ‘Location: http://www.domain.com/new_page.html’ ) ;
?>

Note : Replace “http://www.domain.com/new_page.html” with exact URL on which you want to redirect you index page .

PHP Fatal error: Call to undefined function

Saturday, November 7th, 2009

Error : PHP Fatal error: Call to undefined function

Solution : The server shows this warning because your script is not working on php4 version so you need to switch to php5 version for the domain who is facing the problem. If on the server both php4 and php5 installed then you can switch to php5 by adding the following code in .htaccess file.

AddHandler application/x-httpd-php5 .php

PHP Parse error: syntax error, unexpected T_STRING

Friday, November 6th, 2009

PHP Parse error: syntax error, unexpected T_STRING

Please add the following line in the php_flag short_open_tag X in the .htaccess file and
short_open_tag = X in the php.ini file under the clients folder on the suexcec server and then check .

osCommerce error ‘Cannot reassign this’

Sunday, August 9th, 2009

osCommerce error ‘Cannot reassign this’

The error appears because your OS Commerce is based on PHP4 rather than PHP5. To resolve the error message, you should follow the instructions below:

1. Go to your cPanel. Refer to SiteGround cPanel access guide.

2. Click on the File Manager icon.

3. Click on the folder icon next to public_html folder name.

4. Click on the folder icon next to the folder in which your osCommerce is installed

5. Find ../catalog/admin/includes/classes/upload.php file and click on it

6. In the upper right corner you will see several management options for upload.php file. Click on Edit File

7. Open the file and find the line (about 30 lines down) that says:

// self destruct
$this = null;

And change it to:

// self destruct
// $this = null;
unset($this);