Categories
PHP

Check requirements for PHP web application

Imagine that you need to have an installation form for your web app.

Of course you will need to ask many things, but before you ask, what about been sure the client match all the software requirements?

Check the PHP version:

$phpversion = substr(PHP_VERSION, 0, 6);
if($phpversion >= 5.2) {
       echo "Right PHP version";
}
else{
	echo "No, you can't continue with the installation";
	exit;
}

In this example we require 5.2 at least to continue.

Check extension loaded in PHP:

if (!extension_loaded('curl')){
    echo 'Not found, please proceed to install';
    exit;
}
else echo 'Found';

In this example we check that CURL it’s loaded.

Checking apache module installed:

if (in_array('mod_rewrite',apache_get_modules())) echo 'Found';
else echo 'Not found';

In this example we check that mod_rewrite it’s loaded.

Checking folder permissions:

 if(is_writable('/images')) {
	echo 'OK - Writable';
}
elseif(!file_exists('/images')) {
	echo 'File Not Found';
}
else {
	echo 'Unwritable (check permissions, chmod 755 should fix this)';
	exit;
}

Checking mysql connection:

if (!mysql_connect($_POST["DB_HOST"],$_POST["DB_USER"],$_POST["DB_PASS"])){
	$msg=mysql_error();
	echo 'Mysql error:' .$msg;
	exit;
}
else echo "connected!";