PHP Startup: Unable to load dynamic library ‘/usr/lib64/php/modules/module.so’

For some reason (I think just on Red Hat/CentOS) you may end up with a bad reference in mcrypt.ini so “module.so” as opposed to “mcrypt.so”

To update this simply edit mcrypt.ini so that it points to the right extension (instead of what I’m assuming is placeholder text)

vim /etc/php.d/mcrypt.ini

You should see the following…

; Enable mcrypt extension module
extension=module.so

Change this to…

; Enable mcrypt extension module
extension=module.so

This might be the way the extension comes down from RPMForge I’m not sure

Concrete5 “Fatal error: Class ‘View’ not found”

Concrete5 may present you with the confusing error ”Fatal error: Class ‘View’ not found”, which looks like a Loader issue but often it is not. When moving between different servers, the database permissions may not be quite right, which will cause this to happen.

If you check that the user that Concrete5 is using has access to the database and the correct credentials, then often this will solve the issue.

There are various reasons why Loader issues occur, but this is a quite common issue (and the error message isn’t very helpful!)

“Could not open configuration file /usr/local/zend/etc/sites.d/zend-default-vhost-80.conf”

If you’ve upgraded from an older version of Zend Server than 5.6 up to 6.0 you may have ended up with a patched httpd.conf that references a vhost configuration file that has not been created. If you try to start Apache you may see this message:

$ sudo apachectl start
httpd: Syntax error on line 428 of \
/usr/local/zend/apache2/conf/httpd.conf: \
Could not open configuration file \
/usr/local/zend/etc/sites.d/zend-default-vhost-80.conf: \
No such file or directory
-e /usr/sbin/apachectl start [FAILED]

This means your Apache configuration has been patched to references the virtual host files, without actually creating them. If you take a look in /usr/local/zend/apache2/conf/httpd.conf it may look like this:

#ZEND-{D530A88D964D3928787617703831DDA9}
NameVirtualHost *:80
<VirtualHost *:80>
#ZEND-{A5F00F7D0B1F44B6CEDF7CA64E576EC6}
Include "/usr/local/zend/etc/sites.d/zend-default-vhost-80.conf"
#ZEND-{A5F00F7D0B1F44B6CEDF7CA64E576EC6}
</VirtualHost>
#ZEND-{D530A88D964D3928787617703831DDA9}
#ZEND-{ADBE6F7D623A36E39CB1FBD16A356D09}
Include "/usr/local/zend/etc/sites.d/globals-*.conf"
Include "/usr/local/zend/etc/sites.d/vhost_*.conf"
#ZEND-{ADBE6F7D623A36E39CB1FBD16A356D09}

One way to fix this is to simply copy them down from these Gists:

How to safely handle PHP “__toString() must not throw an exception”

Because there is no safe way to handle an exception thrown during __toString the easiest workaround for this is to catch all exceptions thrown and return either an empty string or null.

Since any invocation of __toString will expect a string back, it is a graceful way to handle any under-the-hood errors if you’re using __toString as a shortcut to echo out objects.

What does vagrant up do, where does the box get downloaded to?

Vagrant is a pretty nifty tool that simplifies developing on a Virtual Machine. However it is sometimes not obvious what happens in the background! An example of this is where your VM’s actually get downloaded to, and how they are managed.

Since Vagrant acts as a wrapper for VirtualBox (or VMWare Fusion more recently) when you “add” a box, it essentially downloads a pre-built Virtual Machine Disk (VMDK) from the internet/network and stores it somewhere. It then uses this as a base before applying your project-specific configuration, such as Shared Folders, networking and so on.

The VMDK’s get downloaded to a hidden sub-directory in your home directory.

cd ~/.vagrant.d/boxes/

Therefore if you run a command in your project (as per the tutorial) such as

vagrant box add precise32 \

http://files.vagrantup.com/precise32.box

Then assuming you are using VirtualBox (as boxes will be stored differently depending on which virtualization provider you are using) the box will be downloaded to the following location

cd ~/.vagrant.d/boxes/precise32/virtualbox

If you look what is in there, you will see a VMDK, Vagrantfile describing the box, Open Virtualization Format (OVF) file for VirtualBox (so VirtualBox can import it, I assume you’ll get a VMX for VMWare Fusion) and a metadata JSON file telling Vagrant the provider (in this case VirtualBox)

ls
Vagrantfile  box-disk1.vmdk  box.ovf  metadata.json

 

Convert non-Java Eclipse ADT project to Android project

If you’ve imported a project into Eclipse, say from Git for example, then it might not be set as an Android project. There doesn’t seem to be an easy way to convert the project to an Android project through Eclipse itself, but you can change the nature of the project by editing the project XML file.

  1. Close the project in Eclipse
  2. Open .project in a text editor
  3. Assuming <natures></natures> is empty, add the following natures
    • <nature>org.eclipse.jdt.core.javanature</nature>
    • <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
  4. Re-open the project

The first nature lets it know it’s a Java project, the second nature let’s it know it’s an Android project, which of course needs to be a Java project.

You should now have all the Android and Java project options available to you.

“Your proxy directory must be writable”

When you first start off with Doctrine 2, you’ll eventually start creating complex objects with child objects as properties, which of course you will use Doctrine to load. Unlike how you’d do it traditionally though, Doctrine uses proxy pattern objects to lazy-load these child objects until they are accessed; these objects are cached, and thus the proxy directory just like the cache directory must be writable.

I found on Stack Overflow where the default proxy directory is so you need to create the directories and make the proxy directory writable

mkdir data/DoctrineORMModule
mkdir data/DoctrineORMModule/Proxy
chmod 755 data/DoctrineORMModule/Proxy

Replace 755 with whatever mode you need, i.e. 777 if you’re being dangerous/lazy

“The class ‘x’ was not found in the chain configured namespaces”

If you are getting a namespace chain error when trying to load entities with Doctrine 2 in Zend Framework 2, it is likely because as far as Doctrine is concerned the namespace your entity is in is missing.

If you’ve copied Jason Grime’s Doctrine 2 and Zend Framework 2 tutorial then you’ll notice the configuration he places in module.config.php

array(
  'doctrine' => array(
    'driver' => array(
      __NAMESPACE__ . '_driver' => array(
        'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
        'cache' => 'array',
        'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity')
      ),
      'orm_default' => array(
        'drivers' => array(
        __NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
      )
    )
  )
)

The key thing to note here is that it will load any entities in the Entity sub-directory of whatever namespace you are currently in. That is why he adds the namespace declaration at the top (that isn’t normally required)

namespace Snowcone;

In theory you could probably hardcode the driver configuration to whichever namespace you’d like; this is just generic so you can copy-and-paste it anywhere.

Therefore if your code doesn’t work, check that

  1. You have a ‘doctrine’ configuration section in module.config.php for whichever module you’re trying to load entities for
  2. You set the namespace of module.config.php to whichever namespace that module is, so module/Snowcone/config/module.config.php will be namespace Snowcone

AES encryption with PHP, 256-bit using IV

I had a bit of trouble finding a how-to of how to encrypt and decrypt using AES, so I put together a quick example of how to using a non-blank IV.

However I did find a useful code snippet from Chilkat Software that helped me a lot of the way.

The only gotcha I found is that if you generate an AES 256 CBC key and IV using OpenSSL it will generate a 64-bit key and 32-bit IV, even though using PHP mcrypt it expects them both to be 32-bit. If you generate an AES 128 CBC key and IV though they’re the right length; I’m assuming the encryption is still 256 however.

openssl enc -aes-128-cbc -k [insert-passphrase-here] -P -md sha1

Which should generate something that looks like this:

salt=DD740CB2ABBE8C3A 
key=23FA93B1A2E5CE60E7F456F9EFC9FE75 
iv =B33D526335805E2CB332CAEF643E0C07

Here is a sample PHP script to demonstate the encryption and decryption:

<?php

$text = 'Testing encryption';

$cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_256, '', MCRYPT_MODE_CBC, '');
$iv_size = mcrypt_enc_get_iv_size($cipher);

$key = '12345678901234561234567890123456';
$iv =  '9532654BD781547023AB4FA7723F2FCD';

echo "<strong>IV:</strong> " . bin2hex($iv) . '<br />';
echo "<strong>Key:</strong> " . bin2hex($key) . '<br />';
echo '<strong>Before encryption:</strong> ' . $text . '<br />';

// Encrypt
if (mcrypt_generic_init($cipher, $key, $iv) != -1)
{
	$encrypted = mcrypt_generic($cipher, $text);
	mcrypt_generic_deinit($cipher);

	echo '<strong>After encryption:</strong> ' . bin2hex($encrypted) . '<br />';
}

// Decrypt
if (mcrypt_generic_init($cipher, $key, $iv) != -1)
{
	$decrypted = mdecrypt_generic($cipher, $encrypted);
	mcrypt_generic_deinit($cipher);

	echo '<strong>After decryption:</strong> ' . $decrypted . '<br />';
}

How to install CentOS 6.3 on Microsoft Hyper-V virtualization

Many developers rely on Linux, but often work in a Windows infrastructure environment. Often it’s not feasible to install a flow-blown VSphere or XenServer setup when everything else runs on Windows Server and there’s limited hardware, but virtualization has many advantages. Enter Hyper-V, which can be looked after by Windows system administrators, but let you use Linux in virtual machines as you would in any other virtualized environment.

With a few caveats mind you…

Install CentOS

Use any of the ISO’s that you can download from a CentOS mirror, although I found using the net install the easiest as it verifies that your networking is up and running before you install (it can be a pain to sort out post-install if eth0 isn’t detected)

Setup bootable IDE hard drive

The VM will need a bootable hard drive to install CentOS on. Due to Hyper-V restrictions this must be an IDE hard drive and cannot be larger than 128GB. This is due to the IDE-emulation that Hyper-V uses, which hopefully will be fixed in a future release.

If you need additional storage (as if often required) you can add a second IDE or SCSI hard drive, which is explained later.

Install Linux IC

Get the latest Linux Integrated Components from Microsoft(currently 3.4) Mount the Linux Integrated Components ISO and copy the files to the virtual machine somewhere, then run the installer

mkdir /opt/linuxic
mkdir /mnt/cdrom
mount /dev/cdrom /mnt/cdrom
cd /mnt/cdrom
cp * -R /opt/linuxic/
cd /opt/linuxic
cd RHEL63
./install.sh

Once this has completed you should be able to access the synthetic networking and storage that come with Hyper-V. Reboot the virtual machine you should have access to the network adapter (instead of the legacy network adapter) and SCSI virtual disks.

Configure synthetic network adaptor

To configure the synthetic network adapter instead of the legacy adapter, once Linux IC are installed you can turn off the VM and switch them over. If CentOS installed successfully with the legacy network adaptor, it should be configured as eth0.

With the VM turned off, go into the settings and copy the dynamic MAC address of the legacy network adaptor into the synthetic network adaptor (labelled just network adapter) and set the MAC address to be static.

Once you boot the VM, CentOS should switch to using the new network adaptor in place of the old legacy network adaptor.

Setup additional hard drive

On the assumption that you will use the 2nd IDE channel for mounting CD/DVD images (such as the Linux IC .iso) you can add additional hard drives via SCSI. In theory once Linux IC are installed the SCSI emulation should be faster than the IDE emulation…

If you need help partitioning, formattting and mounting the new disk there is a guide for adding a new disk drive to a CentOS system on Techotopia.

fdisk /dev/sdb

Create a new primary partition on the drive using all available space, then write the changes to the device. As a shortcut just type n, p, 1, (empty), (empty), w

/sbin/mkfs.ext4 -L /var /dev/sdb1
mv /var /var_old
mount /dev/sdb1 /var
Pages:1234567...15»

Twitter