0

i was previously building my website on windows with xampp etc... however due to some software issues i had to change to linux and am now running ubuntu 13.10.

I reinstalled xampp onto ubuntu and transfered and setup my website on it for me to carry on work, everything seems to work fine apart from one section of the website which is this line of code.

$iv = mcrypt_create_iv(128, MCRYPT_DEV_URANDOM);

This code worked fine on windows and created the random string for me to create the cookie, however on the new ubuntu setup it is failing to work and just exits to the current page im on with no error messages.

I changed it to a random string like below

$iv = "aahd98a8du98sd9a8ud9ajsd89";

And the code ran fine, so it must be the mcrypt failing to run. Any ideas on why this may be happening?

Thanks

Zword
  • 5,933
  • 2
  • 22
  • 51
Al Hennessey
  • 2,175
  • 5
  • 34
  • 57
  • Display error messages so you know where to begin. http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display – John McMahon Jan 31 '14 at 02:30
  • I checked the php.ini and the display_errors = on, so it should be reporting errors, but i get nothing – Al Hennessey Jan 31 '14 at 23:26
  • if you can't get the error during php execution, you could get the errors from error_log file, its usually in /var/log/apache2/ but in your installation it may be under /opt/lampp/logs. if you provide the error, you can find an answer alot quicker and more precise. – Volkan Ulukut Feb 08 '14 at 16:40

2 Answers2

1

Can you try this and post the results?

mv -i /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/
sudo php5enmod mcrypt
sudo service apache2 restart
Filipe YaBa Polido
  • 1,580
  • 1
  • 14
  • 35
  • Hi, i navigated to the /opt/lampp folder in console and ran your 3 lines there so hopefully that is correct, your first line said could not find the mcrypt.ini file. The second line said unrecognised command `php5enmod`. The third said apache2 was an unrecognised service – Al Hennessey Feb 04 '14 at 00:40
  • Hi, so you're not using apache2? Paths may vary on different distributions. Can you tell what versions do you have installed ? – Filipe YaBa Polido Feb 04 '14 at 00:58
  • The /opt/lampp folder sounds like the non-built in version of Apache + PHP, did you install XAMPP or similar? – Tom Feb 10 '14 at 22:54
1

Taken from the documentation on mcrypt_create_iv, regarding MCRYPT_DEV_URANDOM:

The source of the IV. The source can be MCRYPT_RAND (system random number generator), MCRYPT_DEV_RANDOM (read data from /dev/random) and MCRYPT_DEV_URANDOM (read data from /dev/urandom). Prior to 5.3.0, MCRYPT_RAND was the only one supported on Windows.

It's possible that your original use of MCRYPT_DEV_URANDOM on your windows machine was simply ignored as unsupported (I can't know for sure without knowing what version of PHP you were running on your windows machine). If so, then it would have defaulted to MCRYPT_RAND and worked fine before.

But now that you are on Ubuntu, MCRYPT_DEV_URANDOM is actually being taken into account, which means that PHP is looking to read data from /dev/urandom. It's possible that your system does not have /dev/urandom.

Here are steps that I would take. You will need to have sudo or root access to your Ubuntu machine.

Check to see if your system has /dev/urandom available.

ls -a /dev/urandom

If not, then create it.

These steps taken from Ubuntu Manpages:

mknod -m 644 /dev/random c 1 8
mknod -m 644 /dev/urandom c 1 9
chown root:root /dev/random /dev/urandom

Just in case, you do have mcrypt installed, yes?

My Ubuntu setup, after installing PHP5, did not have mcrypt support right out of the box. To install it:

sudo apt-get install php5-mcrypt
sudo service apache2 restart
Alvin S. Lee
  • 3,900
  • 26
  • 33