Eli

To content | To menu | To search

PHP

PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.

Monday, February 18 2013

Solve "Wrong permissions on configuration file, should not be world writable!" error on phpMyAdmin

Introduction

phpMyAdmin want config.inc.php to be not world writable, it's sound simple, but not if you run phpMyAdmin from an NTFS filesystem (in my case, linux server who mount a Windows folder) it's not that simple. There are two way to solve this problem :

Simple way, Linux Server, Linux Filesystem

Just chmod 0755 the file

chmod 0755 config.inc.php


Linux or Windows Server, NTFS Filesystem

If like me you run a Linux Virtual Machine who mount a Windows folder where phpMyAdmin sources are located, edit config.inc.php and add this line :

$cfg['CheckConfigurationPermissions'] = false;

This will tell phpMyAdmin to stop checking for fileperm because they can't be properly detected.

Hope this help




Sunday, September 11 2011

How to regularly check for a newer version in a PHP application

Introduction

I was searching a quick way to inform people that a newer version of phpMemcachedAdmin was released, without needing to visit the website everyday.
I only found scripts that make HTTP request every time, so i wrote this little function to add some internal cache to the HTTP request.

Here is the result : a small script for a PHP application to check for a newer version, using a file hosted on code.google.com (File example here)

What it does

  • It stores a local file named .version where the latest version available is stored (Plain text like "1.2.0")
  • Each time the local file is older than 15 day, it goes to code.google.com to check for the latest version (Again, the file only contains version number "1.2.0")
  • It wrote the latest version available in the local file
  • If the file is younger than 15 day, it open the local file, and compare the version number stored in it with the application current version.

So with this small technique, only one HTTP request is done every 15 day, the rest of the time it's only a local file, being the least intrusive in the user system.

PHP version check script

This script works in both Linux & Windows, use system temp path to wrote the latest version file, and also use the error suppression operator (@), to prevent warning on file_get_contents() function if the user does not have access to code.google.com.

# Actual application version
define('CURRENT_VERSION', '1.2.1');
 
/**
 * Check for the latest version, from local cache or via http
 * Return true if a newer version is available, false otherwise
 *
 * @return boolean
 */
function check()
{
    # Configuration array
    $ini = array('local_path' => sys_get_temp_dir() . DIRECTORY_SEPARATOR . '.version',
                 'distant_path' => 'http://phpmemcacheadmin.googlecode.com/files/latest',
                 'time_between_check' => 15*24*60*60);
 
    # Checking if file was modified for less than $ini['time_between_check'] ago
    if((is_array($stats = @stat($ini['local_path']))) && (isset($stats['mtime'])) 
       && ($stats['mtime'] > (time() - $ini['time_between_check'])))
    {
        # Opening file and checking for latest version
        return (version_compare(CURRENT_VERSION, file_get_contents($ini['local_path'])) == -1);
    }
    else
    {
        # Getting last version from Google Code
        if($latest = @file_get_contents($ini['distant_path']))
        {
            # Saving latest version in file
            file_put_contents($ini['local_path'], $latest);
 
            # Checking for latest version
            return (version_compare(CURRENT_VERSION, $latest) == -1);
        }
        # Can't connect to Google Code
        else
        {
            # In case user does not have access to code.google.com !!!
            # Here it's up to you, you can write nothing in the file to display an alert
            # leave it to check google every time this function is called
            # or write again the file to advance it's modification date for the next HTTP call.
        }
    }
}

Hope this little script will help you well.




Tuesday, August 23 2011

PHP 5.3.7 upgrade warning & PHP 5.3.8 security fix

Two issues that were introduced in PHP 5.3.7 two days ago are now fixed in the newest release 5.3.8.
You should not use version 5.3.7 and are encouraged to upgrade to release 5.3.8.

Release notes

Core:

  • Fixed bug #55439 (crypt() returns only the salt for MD5).

OpenSSL:

  • Reverted a change in timeout handling restoring PHP 5.3.6 behavior, as the new behavior caused mysqlnd SSL connections to hang (#55283).


For a full list of changes in PHP 5.3.8 & 5.3.7, see the ChangeLog.




Friday, May 27 2011

Install Hudson/Jenkins on CentOS

Hudson monitors executions of repeated jobs, such as building a software project or jobs run by cron, we can use it as a continuous integration server for PHP Application.

Theses quick steps can be used to install Hudson or Jenkins, simply replace all hudson occurences with jenkins.

Let's see how to install Hudson on a CentOS 5.5 server.

Installing Java, Ant and Tomcat

yum install -y java ant
yum install tomcat5 tomcat5-webapps tomcat5-admin-webapps

Then we need to add Tomcat to our server startup

chkconfig --add tomcat5

Now edit Tomcat configuration file to add Hudson home directory (We will use /data/hudson/)

vi /etc/tomcat5/tomcat5.conf

Add at the bottom of the file

# If you wish to further customize your tomcat environment,
# put your own definitions here
# (i.e. LD_LIBRARY_PATH for some jdbc drivers)
# Just do not forget to export them :)
HUDSON_HOME=/data/hudson/
CATALINA_OPTS="-DHUDSON_HOME=/data/hudson/ -Xmx512m"


Installing Hudson 2.0.0

Go to webapps directory

cd /var/lib/tomcat5/webapps/

Download lastest version of Hudson from http://hudson-ci.org/ or latest from Jenkins from http://jenkins-ci.org/

wget http://java.net/projects/hudson/downloads/download/war/hudson-2.0.0.war
mv hudson-2.0.0.war hudson.war

Now make home folder for hudson and give it Tomcat user right

mkdir /data/hudson
chown tomcat.tomcat /data/hudson/

Restart Tomcat to finalize installation

 /etc/init.d/tomcat5 restart

Now check if everything is ok by opening a web browser and access hudson with something like http://yourhost:8080/hudson/

You will see something like this :

Hudson start screen

You can now add your project, if you have a PHP Project, check http://jenkins-php.org/ for an easy template solution.




Thursday, May 5 2011

Disable layout and view renderer in Zend Framework

A quick tip when you need to disable layout and/or view rendering, simply add in your controller

public function preDispatch()
{
    $this->_helper->layout()->disableLayout();
    $this->_helper->viewRenderer->setNoRender(true);
}

Hope that can save you some time trying to find how in the documentation.




- page 1 of 3