Showing posts with label Php. Show all posts
Showing posts with label Php. Show all posts

How to change date and time zone in php

0 comments
If your php script is not showing correct date and time then it means your script is using date and time zone configured on your server.

If you want to set your own date and time zone for your domain then it can be done in a very simple manner.

You will need to create php.ini in document root of your domain.
nano php.ini

and enter following line.

date.timezone =Asia/Jakarta

save and exit from file.

Now create phpininfo page and open it in browser and you will see that date and time zone hve been enabled.

How to install memcache on linux server?

4 comments
Or you can use following steps to install PECL memcache manually.memcached is a high-performance memory object caching system intended to speed up dynamic web applications by alleviating database load.

memcached is meant to work in concert with something like the MySQL query cache, not replace it. The two implementations excel at vastly different things: memcached is an object cache, while MySQL provides a query cache.

memcached is extremely fast. It uses libevent, which provides a mechanism to execute a callback function when a specific event occurs on a file descriptor, to scale to any number of open connections. On a modern Linux system memcached utilizes epoll, is completely non-blocking for network I/O, ensures memory never gets fragmented, and uses its own slab allocator and hash table to achieve 0(1) virtual memory allocation.

How it install it on Linux server ?
#curl -O http://monkey.org/~provos/libevent-1.4.9-stable.tar.gz
#tar -xzvf libevent-1.4.9-stable.tar.gz
#cd libevent*
#./configure
#make
#make install

Now let’s download the newest Memcached source
#curl -O http://www.danga.com/memcached/dist/memcached-1.3.0.tar.gz
#tar zxf memcached-1.3.0.tar.gz
#cd memcached-1.3.0
#./configure
#make
#make install

Then add /usr/local/lib to LD_LIBRARY_PATH in your .bash_profile
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH

How it Works

First, you start up the memcached daemon on as many spare machines as you have. The daemon has no configuration file, just a few command line options, only 3 or 4 of which you’ll likely use:

Run Memcached as a daemon (d = daemon, m = memory, u = user, l = IP to listen to, p = port)
#memcached -d -m 1024 -u root -l 127.0.0.1 -p 11211 –u nobody

This starts memcached as a daemon (-d) on the IP address and port specified with -l and -p, respectively, running as the user nobody (-u), allocating 1024  for object storage (-m). You should adjust the amount of storage to suit your needs; many memcached installs run with 4 GB. Once you are comfortable with your startup options, add the appropriate command to your startup scripts.

Create a /etc/init.d/memcached file and add above line to start memcached when the server boots With memcached installed and running, it’s time to get PHP talking to the object cache. While multiple PHP API exists, the one in the PECL repository is recommended. If you are running a newer version of PHP, installation is as simple as:
# pecl install memcache

Or you can use following steps to install PECL memcache manually.
#cd /usr/local/src
#curl -O http://pecl.php.net/get/memcache
#tar zxvf memcache*
#cd memcache-*
#phpize
#./configure
#make && make install

Now we have to make sure PHP loads the newly built memcache.so library by adding the following line to php.ini:

extension=memcache.so

Now restart Apache:
Service httpd restart

Once it sucussfully install you can create phpinfo() on your webserver should now confirm that memcache is installed.

Error : Upgrading to 2.8.5 Wordpress

0 comments
I was getting a error while upgrating wordpress to 2.8.5- Downloading update from http://wordpress.org/wordpress-2.8.5.zip.
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 2354937 bytes) in /home1/ottousco/satmareanul.com/wp-includes/http.php on line 1324

Might need to increase the amount of memory a PHP script may consume

1. If you have access to your PHP.ini file, change the line in PHP.ini
If your line shows 32M try 64M:
memory_limit = 64M ; Maximum amount of memory a script may consume (64MB)

2. If you don't have access to PHP.ini try adding this to an .htaccess file:
php_value memory_limit 64M

3. Try adding this line to your wp-config.php file:
define('WP_MEMORY_LIMIT', '64M');

4. Talk to your host.

How to install or upgrade to PHP 5.2.x

0 comments

To upgrade to PHP 5.2.x on CentOS/RHEL/Fedora:


Step 1) Set up the atomic channel:



wget -q -O - http://www.atomicorp.com/installers/atomic.sh | sh

Step 2) Upgrade to PHP 5.2.x:



yum upgrade

Step 3) Replace the PHP 4 php.ini with PHP 5.2.x's (if applicable):



mv /etc/php.ini.rpmnew /etc/php.ini

Step 4) Replace the php.conf with the PHP 5.2.x php.conf (if applicable):



mv /etc/httpd/conf.d/php.conf.rpmnew /etc/httpd/conf.d/php.conf

Step 5) Restart the webserver



service httpd restart
(or)
/etc/init.d/httpd restart

Checklist


1) Source code installations of extensions, like Ioncube loader, or other extensions that have to be updated. Ive created php-ioncube-loader, php-zend-optimizer, and php-eaccelerator packages to fix this for you automatically.


2) php.ini settings, like memory_limit


3) execstack -c on any extensions that claim to need an executible stack (ASL users only).


Known Issues


1) VPS and RHEL users, If you dont use the atomic installer, you're going to miss some dependencies, like sqlite3. Have fun with that!


2) RHEL4 users (and possibly others) can resolve the sqlite3 dependencies by grabbing rpms from the CentOS repositories. The atomic installer fixes this for you automatically. If you dont use it... have fun with that!



rpm -Uvh http://isoredirect.centos.org/centos/4/os/i386/CentOS/RPMS/sqlite-3.3.6-2.i386.rpm http://isoredirect.centos.org/centos/4/os/i386/CentOS/RPMS/sqlite-devel-3.3.6-2.i386.rpm

up2date php

OR



yum update php

Works like a charm


3) PHP 5.2.5 causes problems with Horde and Apache configuration files on PSA 8.2.1 and lower. PSA 8.3.0 has fixed this problem, so the easiest way to fix these issues is to upgrade to PSA 8.3.0 or higher. Otherwise, you'll need to perform the following extra steps:


3a) Modify /etc/httpd/conf.d/zz010_psa_httpd.conf


Change this:



php_admin_value include_path "/usr/share/psa-horde:/usr/share/psa-horde/pear:."

to



php_admin_value include_path "/usr/share/psa-horde/lib:/usr/share/psa-horde:/usr/share/psa-horde/pear:."

Note this file is changed every time plesk is updated, so you'll need to go back and fix this when it does.


This also fixes the PHP Fatal error: Can't load Horde/SessionObjects.php, open_basedir restriction problem.


3b) General issues with php_admin_value:


The fix for now is to replace the use of php_admin_value with php_value. I have only tested this as far as the domains on this server. You will find this used all over the place in zz010_psa_httpd.conf, domain level httpd.includes, and most likely in your own customizations. The biggest problems Ive had are with register_globals and include_path, I have not run into any issues with PSA httpd.include files and open_basedir.




4) Plesk Sitebuilder is not compatible with 5.2.x on systems that did not come with it natively. Either remove it, with yum remove sb-publish, or you *might* be able to get it to work by using the php-sqlite2 from the Fedora 8 plesk repo. php-sqlite2 was added to the atomic repo to handle sitebuilder integration.



Problems with MySQL databases and PLESK 9 after upgrade.


If you get the following error after upgrading when you try to log into PLESK then you need to upgrade your database tables:



ERROR: PleskFatalException
bad column in table: `backup_time` time NOT NULL default '00:00:00',
[...]


Issue the following command from the shell:



mysqlcheck --check-upgrade --all-databases --auto-repair -uadmin -pyouradminpassword

followed by:


cat /usr/share/mysql/mysql_fix_privilege_tables.sql | /usr/bin/mysql --no-defaults --force --user=admin --password=youradminpassword ----host=localhost --database=mysql --host=localhost --database=mysql

Hardening of PHP

0 comments

Hardening PHP
Run As The User Instead of “nobody” . You can run PHP as the user (like CGI scripts do with Apache’s suexec)

Enable suPHP


PHP scripts are executed by the user who owns the VirtualHost serving the request.

Use Hardening Tools Like phpsuhosin

Remove Insecure Scripts


Apache directives like php_value are not valid for mod_suphp. It is possible to place a php.ini file in the directory containing the PHP script and specify these types of values in it.


For PHP scripts to execute, permissions of 0400 are sufficient. Scripts are run as the user who owns the VirtualHost, and as long as this user has permissions sufficient to write to a file/directory, PHP scripts will also have the ability to do so. Mod_SuPHP performs various security checks before executing PHP scripts. Most can be disabled in Mod_SuPHP configuration file located at /opt/suphp/etc/suphp.conf

URL file-access is disabled in the server configuration

0 comments
* Warning: include() [function.include]: URL file-access is disabled in the server configuration in /home/xxxxxx/public_html/index.php on line 104

I've recently upgraded Apache and PHP on my VPS, and one of the unpleasant surprises was that some scripts which tried including pages from remote sites (I know, not the most secure approach, but there were reasons for that) got broken.



allow_url_fopen


Traditionally, all the websites Google finds suggest that you double-check that your php.ini config has the allow_url_fopen enabled:




allow_url_fopen = On



Well, in my case it was enabled, but scripts were still broken. The really weird thing was that the upgrade procedure didn't include changing the php.ini in any way, so it was fully working before and I kind of expected it to continue working.



allow_url_include


After some quick research, I've found out that PHP 5.1 introduced a new security option to accompany the allow_url_fope, and this was exactly the option which broke my scripts:




allow_url_include = On



There you have it, hope it helps you next time you come across this problem!

Hardening PHP

0 comments
PHP scripts are executed by the user who owns the VirtualHost serving the request.

Use Hardening Tools Like phpsuhosin

Remove Insecure Scripts

Apache directives like php_value are not valid for mod_suphp. It is possible to place a php.ini file in the

directory containing the PHP script and specify these types of values in it.

For PHP scripts to execute, permissions of 0400 are sufficient. Scripts are run as the user who owns the

VirtualHost, and as long as this user has permissions sufficient to write to a file/directory, PHP scripts will

also have the ability to do so. Mod_SuPHP performs various security checks before executing PHP scripts. Most can

be disabled in Mod_SuPHP configuration file located at /opt/suphp/etc/suphp.confPHP scripts are executed by the user who owns the VirtualHost serving the request.

Use Hardening Tools Like phpsuhosin

Remove Insecure Scripts

Apache directives like php_value are not valid for mod_suphp. It is possible to place a php.ini file in the

directory containing the PHP script and specify these types of values in it.

For PHP scripts to execute, permissions of 0400 are sufficient. Scripts are run as the user who owns the

VirtualHost, and as long as this user has permissions sufficient to write to a file/directory, PHP scripts will

also have the ability to do so. Mod_SuPHP performs various security checks before executing PHP scripts. Most can

be disabled in Mod_SuPHP configuration file located at /opt/suphp/etc/suphp.confPHP scripts are executed by the user who owns the VirtualHost serving the request.

Use Hardening Tools Like phpsuhosin

Remove Insecure Scripts

Apache directives like php_value are not valid for mod_suphp. It is possible to place a php.ini file in the

directory containing the PHP script and specify these types of values in it.

For PHP scripts to execute, permissions of 0400 are sufficient. Scripts are run as the user who owns the

VirtualHost, and as long as this user has permissions sufficient to write to a file/directory, PHP scripts will

also have the ability to do so. Mod_SuPHP performs various security checks before executing PHP scripts. Most can

be disabled in Mod_SuPHP configuration file located at /opt/suphp/etc/suphp.co

PHP scripts are executed by the user who owns the VirtualHost serving the request.

Use Hardening Tools Like phpsuhosin

Remove Insecure Scripts

Apache directives like php_value are not valid for mod_suphp. It is possible to place a php.ini file in the directory containing the PHP script and specify these types of values in it.

For PHP scripts to execute, permissions of 0400 are sufficient. Scripts are run as the user who owns the VirtualHost, and as long as this user has permissions sufficient to write to a file/directory, PHP scripts will also have the ability to do so.

Mod_SuPHP performs various security checks before executing PHP scripts. Most can be disabled in Mod_SuPHP configuration file located at /opt/suphp/etc/suphp.conf

How to Enable PHP function for a one account ?

0 comments
IF you disable PHP function in php.ini file and if you want to enable any particular function only one account .Then You can however use suhosin to enable a function for one domain only.

How can you do that ?

After installing suhosin, remove all functions from disable_functions in php.ini and add inphp.ini suhosin.executor.func.blacklist = “exec,passthru,shell_exec” and all the functions that you want to disable globally.

After that for each domain in the virtual host section you can addsuhosin.executor.func.blacklist again but without the function that you need to enable. And so you will enable that function only for one domain.

Example:
<VirtualHost 127.0.0.1>
………..
………..
<IfModule mod_php4.c>
php_admin_value open_basedir “/usr/lib/php”
</IfModule>
<IfModule mod_php5.c>
php_admin_value open_basedir “/usr/lib/php”
php_admin_value suhosin.executor.func.blacklist = “passthru,shell_exec”
</IfModule>
…….
……
</VirtualHost>

In this example exec has been enabled for the VirtualHost. This way it will be better as you do not neet to modify all the virtual hosts only the ones that you need to enable one or more functions.

How to install memcache on linux server?

6 comments
memcached is a high-performance memory object caching system intended to speed up dynamic web applications by alleviating database load.

memcached is meant to work in concert with something like the MySQL query cache, not replace it. The two implementations excel at vastly different things: memcached is an object cache, while MySQL provides a query cache.

memcached is extremely fast. It uses libevent, which provides a mechanism to execute a callback function when a specific event occurs on a file descriptor, to scale to any number of open connections. On a modern Linux system memcached utilizes epoll, is completely non-blocking for network I/O, ensures memory never gets fragmented, and uses its own slab allocator and hash table to achieve 0(1) virtual memory allocation.

How it install it on Linux server ?

Install dependency software (Libevent)
#curl -O http://monkey.org/~provos/libevent-1.4.9-stable.tar.gz
#tar -xzvf libevent-1.4.9-stable.tar.gz
#cd libevent*
#./configure
#make
#make install 


  • Now let’s download the newest Memcached source


#curl -O http://www.danga.com/memcached/dist/memcached-1.3.0.tar.gz
#tar zxf memcached-1.3.0.tar.gz
#cd memcached-1.3.0
#./configure
#make
#make install


  • Then add /usr/local/lib to LD_LIBRARY_PATH in your .bash_profile


LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH

How it Works

First, you start up the memcached daemon on as many spare machines as you have. The daemon has no configuration file, just a few command line options, only 3 or 4 of which you’ll likely use:

Run Memcached as a daemon (d = daemon, m = memory, u = user, l = IP to listen to, p = port)
#memcached -d -m 1024 -u root -l 127.0.0.1 -p 11211 –u nobody

This starts memcached as a daemon (-d) on the IP address and port specified with -l and -p, respectively, running as the user nobody (-u), allocating 1024  for object storage (-m). You should adjust the amount of storage to suit your needs; many memcached installs run with 4 GB. Once you are comfortable with your startup options, add the appropriate command to your startup scripts.

Create a /etc/init.d/memcached file and add above line to start memcached when the server boots

With memcached installed and running, it’s time to get PHP talking to the object cache. While multiple PHP API exists, the one in the PECL repository is recommended. If you are running a newer version of PHP, installation is as simple as:
# pecl install memcache

Or you can use following steps to install PECL memcache manually.
#cd /usr/local/src
#curl -O http://pecl.php.net/get/memcache
#tar zxvf memcache*
#cd memcache-*
#phpize
#./configure
#make && make install



Now we have to make sure PHP loads the newly built memcache.so library by adding the following line to php.ini:

extension=memcache.so

Now restart Apache:
Service httpd restart

Once it sucussfully install you can create phpinfo() on your webserver should now confirm that memcache is installed.



How to Complile PHP with imap on directadmin server

13 comments
Trying to add --with-imap to your configure.php5 ?
and getting this error?

configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing

Solution (worked for me, this was a dovecot machine):

# yum install libc-client
# yum install libc-client-devel

Then add following lines in:-

nano /usr/local/directadmin/custombuild/configure/ap2/configure.php5



--with-imap=/usr/lib/dovecot/imap \
--with-imap-ssl \


to: configure.php5

# cd /usr/local/directadmin/custombuild/configure/ap2



# ./build php y


Go_GrEen^ThiNk_GReeN~LoVE_GreEn

How to Complile PHP with imap on directadmin server

15 comments
Trying to add --with-imap to your configure.php5 ?
and getting this error?

configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing

Solution (worked for me, this was a dovecot machine):

# yum install libc-client
# yum install libc-client-devel

Then add following lines in:-

nano /usr/local/directadmin/custombuild/configure/ap2/configure.php5



--with-imap=/usr/lib/dovecot/imap \
--with-imap-ssl \


to: configure.php5

# cd /usr/local/directadmin/custombuild/configure/ap2



# ./build php y


Go_GrEen^ThiNk_GReeN~LoVE_GreEn

How to Complile PHP with imap on directadmin server

14 comments
Trying to add --with-imap to your configure.php5 ?
and getting this error?

configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing

Solution (worked for me, this was a dovecot machine):

# yum install libc-client
# yum install libc-client-devel

Then add following lines in:-

nano /usr/local/directadmin/custombuild/configure/ap2/configure.php5



--with-imap=/usr/lib/dovecot/imap \
--with-imap-ssl \


to: configure.php5

# cd /usr/local/directadmin/custombuild/configure/ap2



# ./build php y


Go_GrEen^ThiNk_GReeN~LoVE_GreEn

How to install PDFLib Module on PHP5+

0 comments
PDFlib was removed awhile back for PHP5 because the newer versions have different licenses and we wanted to avoid any possible problems. The PHP4 version is still old so it's available in EasyApache, but of course I don't recommend PHP4 since it's not supported by the PHP developers anymore.

So if you want to install it, it will have to be outside of EasyApache. Here's how you could do it:

# wget http://www.pdflib.com/binaries/PDFlib/704/PDFlib-Lite-7.0.4p4.tar.gz
# tar -zxvf PDFlib-Lite-7.0.4p4.tar.gz
# cd PDFlib-Lite-7.0.4p4
# ./configure --without-java
# make && make install


Then build PHP with pdflib support.

# echo '--with-pdflib' >> '/var/cpanel/easy/apache/rawopts/all_php5'
# /scripts/easyapache --build


Finally, make sure pdflib is enabled as an extension in php.ini; add:

extension=pdf.so

to /usr/local/lib/php.ini and restart apache. Then it will show up. I have already done this for you as a courtesy.
Go_GrEen^ThiNk_GReeN~LoVE_GreEn - Pushkar

Install PEAR Module on web server

0 comments
Simply login via SSH at the root level and execute the following command:

pear -v install module_name

For example to install the mail_queue PEAR module you would execute:

pear -v install mail_queue

Memcached + PHP Memcache Extension Installation

1 comments
Reciently at work as well as in my own personal developement I have found a lot of emphasis on caching technologies. Be this for keeping heavy database queries to a minimum or because you wish to keep heavily served files out of the disk I/O. In this post (my first post!!) I will demonstrate how to install and configure memcached on a linux (CentOS to be specific) box. As well how to install the memcache extension into PHP.

Installing Memcached

Make sure before you start tying to install memcache that you have gcc (# yum install gcc) and libevent-devel (# yum install libevent-devel) installed.

[root@nitrogen ~]# wget http://www.danga.com/memcached/dist/memcached-1.2.6.tar.gz
[root@nitrogen ~]# tar -zxvf memcached-1.2.6.tar.gz
[root@nitrogen ~]# cd memcached-1.2.6
[root@nitrogen memcached-1.2.6]# ./configure
[root@nitrogen memcached-1.2.6]# make
[root@nitrogen memcached-1.2.6]# make install


Now if you are lazy like me and don’t want to have to remember what the memcached flags are every time you start it I would recommend using an init.d script. I recommend using the one located at http://www.dev411.com/wiki/Memcached_startup_files_for_Red_Hat_(RHEL). To install the init.d script on your server you need to place the start-memcached perl script in /usr/local/bin/start-memcached. Make sure you have given this file chmod 755 and is chown root:root. Then you must place the memcached-init into /etc/init.d/memcached, make sure this script has the same permissions as the previous file. Finally create the configuration file /etc/memcached.conf, you can place any options that you want ran by the memcached binary in this file. I use the following in my file.

# /etc/memcached.conf
# user to run memcached as
-u apache




# we want to run memcached as a daemon
-d


# amount of RAM we want to dedicate to memcached in MB
-m 512


# interface to listen to for memcached connections on
-l 127.0.0.1


# port to listen for memcached connections on
-p 11211
Starting Memcached



Now you should be able to start and stop memcached quickly by using the following commands.

[root@nitrogen ~]# /sbin/service memcached start
[root@nitrogen ~]# /sbin/service memcached stop


If you did not install the init.d script then you can start memcached with the following command.

[root@nitrogen ~]# memcached -d -u apache -m 512 -l 127.0.0.1 -p 11211


Installing the Memcache PHP extension

Installing the memcache php module from source is fairly strait forward, it is just like installing any other php module. Please note that you must have zlib-devel and php-devel packages installed.

[root@nitrogen ~]# wget http://pecl.php.net/get/memcache
[root@nitrogen ~]# tar -zxvf memcache-3.0.2.tgz
[root@nitrogen ~]# cd memcache-3.0.2
[root@nitrogen memcache-3.0.2]# phpize
[root@nitrogen memcache-3.0.2]# ./configure
[root@nitrogen memcache-3.0.2]# make
[root@nitrogen memcache-3.0.2]# make install


Now we need to tell php to include our memcache extension when it starts up.We do this by putting the following configuration data in /usr/local/lib/php.ini (or whatever the path is)

extension=memcache.so

You will be able to verify that the memcache php extension has been installed by typing #
php -m and looking for memcache in the php extension list.

Source link : http://www.wolflabs.org/2008/12/07/memcached-php-memcache-extension-installation/