Skip to content

How to change the time zone within a php script

06-Nov-09

How to change the time zone within a php script

You can change the time zone within a php script. Here is a sample code:

putenv("TZ=Europe/Amsterdam");
?>

You can set the timezone in .htaccess as well. Add the line:

SetEnv TZ America/Indianapolis

List of timezones is here: http://us.php.net/manual/en/timezones.php

Rsync your old files to your new server

05-Nov-09

Rsync your old files to your new server.

From your new server run the following commands:

rsync -vrplogDtH --progress -e ssh root@192.168.0.1:/home/ss/public_html/ /home/ss/public_html/

Adding opera repository to Ubuntu

03-Nov-09

Adding opera repository to Ubuntu

Installing Opera.

echo "deb http://archive.canonical.com/ jaunty partner" >> /etc/apt/sources.list
wget -O - http://deb.opera.com/archive.key | sudo apt-key add -
sudo apt-get install debian-archive-keyring
sudo apt-get update
sudo apt-get install opera

Ubuntu /etc/network/interfaces DHCP setup

02-Nov-09

Ubuntu /etc/network/interfaces DHCP setup

To setup eth0 to dhcp in /etc/network/interfaces

auto eth0
iface eth0 inet dhcp

/etc/network/interfaces Ubuntu Static Network setup

02-Nov-09

/etc/network/interfaces Ubuntu Static Network setup

Following example setup eth0 with 192.168.1.1 IP address and gateway (router) to 192.168.1.2

iface eth0 inet static
address 192.168.1.1
netmask 255.255.255.0
gateway 192.168.1.2

With IPtables

auto eth0
iface eth0 inet dhcp
pre-up iptables-restore < /etc/iptables.rules
post-down iptables-restore < /etc/iptables.downrules

Another Example -

auto lo
iface lo inet loopback
auto eth1
iface eth1 inet static
address 192.168.1.1
netmask 255.255.255.0
broadcast 192.168.1.255
network 192.168.1.0

alfresco-community open source enterprise content management solution

02-Nov-09

alfresco-community open source enterprise content management solution

$ sudo apt-cache search alfresco
alfresco-pdf2swf – a PDF to SWF converter
alfresco-community – open source enterprise content management solution

How to install

$ sudo apt-get install alfresco-community
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
alfresco-pdf2swf dbconfig-common gcj-4.3-base imagemagick imagemagick-doc
java-common jsvc libcommons-collections-java libcommons-daemon-java
libcommons-dbcp-java libcommons-pool-java libecj-java libecj-java-gcj
libgcj-bc libgcj-common libgcj9-0 libgcj9-jar libjaxp1.3-java
libjaxp1.3-java-gcj libnss-mdns libservlet2.5-java libtomcat6-java
libxalan2-java libxalan2-java-gcj libxerces2-java libxerces2-java-gcj
odbcinst1debian1 openoffice.org-base-core openoffice.org-calc
openoffice.org-common openoffice.org-core openoffice.org-draw
openoffice.org-emailmerge openoffice.org-impress openoffice.org-math
openoffice.org-style-human openoffice.org-writer python-uno sun-java6-bin
sun-java6-jre tomcat6 tomcat6-common unixodbc uno-libs3 ure
Suggested packages:
transfig equivs java-virtual-machine classpath-doc ecj ant libgcj9-dbg
libgcj9-0-awt libbsf-java libxalan2-java-doc libxsltc-java
libxerces2-java-doc openoffice.org-base openoffice.org-style-industrial
openoffice.org-style-hicontrast openoffice.org-gcj
openoffice.org-filter-binfilter openoffice.org-java-common
openoffice.org-writer2latex sun-java6-plugin ia32-sun-java6-plugin
sun-java6-fonts ttf-baekmuk ttf-unfonts ttf-unfonts-core ttf-kochi-gothic
ttf-sazanami-gothic ttf-kochi-mincho ttf-sazanami-mincho tomcat6-docs
tomcat6-admin tomcat6-examples libmyodbc odbc-postgresql libct1
java2-runtime cli-uno-bridge
Recommended packages:
default-jre-headless java2-runtime-headless java5-runtime-headless
The following NEW packages will be installed:
alfresco-community alfresco-pdf2swf dbconfig-common gcj-4.3-base imagemagick
imagemagick-doc java-common jsvc libcommons-collections-java
libcommons-daemon-java libcommons-dbcp-java libcommons-pool-java libecj-java
libecj-java-gcj libgcj-bc libgcj-common libgcj9-0 libgcj9-jar
libjaxp1.3-java libjaxp1.3-java-gcj libnss-mdns libservlet2.5-java
libtomcat6-java libxalan2-java libxalan2-java-gcj libxerces2-java
libxerces2-java-gcj odbcinst1debian1 openoffice.org-base-core
openoffice.org-calc openoffice.org-common openoffice.org-core
openoffice.org-draw openoffice.org-emailmerge openoffice.org-impress
openoffice.org-math openoffice.org-style-human openoffice.org-writer
python-uno sun-java6-bin sun-java6-jre tomcat6 tomcat6-common unixodbc
uno-libs3 ure
0 upgraded, 46 newly installed, 0 to remove and 160 not upgraded.
Need to get 233MB of archives.
After this operation, 527MB of additional disk space will be used.
Do you want to continue [Y/n]?

ubuntu network setup and configuration

01-Nov-09

To configure your Ethernet device with a static IP address and custom configuration, some more information will be required.

Suppose you want to assign the IP address 192.168.0.2 to the device eth1, with the typical netmask of 255.255.255.0.

Your default gateway’s IP address is 192.168.0.1. You would enter something like this into /etc/network/interfaces:

iface eth1 inet static
address 192.168.0.2
netmask 255.255.255.0
gateway 192.168.0.1

If you have only one Ethernet device, eth0, and it gets its configuration from a DHCP server, and it should come up automatically at boot, only two additional lines are required:

auto eth0
iface eth0 inet dhcp

The first line specifies that the eth0 device should come up automatically when you boot. The second line means that interface (“iface”) eth0 should have an IPv4 address space (replace “inet” with “inet6” for an IPv6 device) and that it should get its configuration automatically from DHCP

Find php.ini path

01-Nov-09

root@laptop:~# php -i|grep php.ini

Configuration File (php.ini) Path => /etc/php5/cli
Loaded Configuration File => /etc/php5/cli/php.ini

root@laptop:~#

PHP Security

01-Nov-09

PHP Security

PHP as a module or as a CGI

Using PHP as a mod-ule is suitable for systems that are dedicated to a single purpose or for sites run by trusted groups of administrators and developers. Using PHP as a CGI (possibly with an execution wrapper) is a better option when users cannot be fully trusted.

When PHP is installed as a module, it becomes a part of Apache and performs all operations as the Apache user (usually httpd).

Using PHP as a CGI

Compiling PHP as a CGI is similar to compiling it for the situation where you are going to use it as a module. This mode of operation is the default for PHP, so there is no need to specify an option on the configure line.

Migrating from a module to CGI operation, therefore, requires modifying every script.

register_globals and allow_url_fopen

register_globals. This option is off by default as of PHP 4.2.0

allow_url_fopen, allows programmers to treat URLs as files.

Because of security reasons, we turn off these options in the php.ini file:

allow_url_fopen = Off
register_globals = Off

PHP uses modules to extend its functionality dynamically. Unlike Apache, PHP can load modules programmatically using the dl( ) function from a script. When a dynamic module is loaded, it integrates into PHP and runs with its full permissions.

enable_dl = Off

Use the expose_php configuration directive to tell PHP to keep quiet.

Setting this directive to Off will prevent the version number from reaching the Server response header and special URLs from being processed:

expose_php = Off

The PHP configuration directives disable_functions and disable_classes allow arbitrary functions and classes to be disabled.

The most useful security-related PHP directive is open_basedir. It tells PHP which files it can access.

Given that web server root, here is how open_basedir should be set:

open_basedir = /var/www/

When PHP is compiled with a –enable-memory-limit, it becomes possible to put a limit on the amount of memory a script consumes. Consider using this option to prevent badly written scripts from using too much memory. The limit is set via the memory_limit option in the configuration file:

memory_limit = 8M

You can limit the size of each POST request. Other request methods can have a body, and this option applies to all of them. You will need to increase this value from the default value specified below if you plan to allow large file uploads:

post_max_size = 8M

The max_input_time option limits the time a PHP script can spend processing input.

max_input_time = 60

The max_execution_time option limits the time a PHP script spends running.

max_execution_time = 30

File uploads can be turned on and off using the file_uploads directive.

file_uploads = Off

Safe mode (http://www.php.net/manual/en/features.safe-mode.php) is an attempt of\PHP developers to enhance security of PHP deployments. Once this mode is enabled, the PHP engine imposes a series of restrictions, making script execution more secure.

PHP safe mode is a useful tool. We start by turning on the safe mode:

safe_mode = On

Safe mode puts restrictions on external process execution. Only binaries in the safe directory can be executed from PHP scripts:

The following functions are affected:

• exec( )
• system( )
• passthru( )
• popen( )

Some methods of program execution do not work in safe mode:

shell_exec( ) Disabled in safe mode.
backtick operator Disabled in safe mode.
dl( ) Disabled in safe mode.

Hardened-PHP (http://www.hardened-php.net) is a project that has a goal of remedying some of the shortcomings present in the mainstream PHP distribution.

Reference – http://www.php.net

php security resources

01-Nov-09

Security section of the PHP manual (http://www.php.net/manual/en/security.php)
PHP Security Consortium (http://www.phpsec.org)