PHP Libsodium Installing Latest Library Failing, Linux Newb - php

I installed PHP extension libsodium via PECL on Linux, and everything seemed fine as I started to test the functions, but I've noticed that some functions are working and others are not.
For example, when I call sodium_crypto_generichash and sodium_crypto_secretbox i get no errors, but when i call sodium_crypto_pwhash I get an error in PHP saying sodium_crypto_pwhash is not a function.
I'm new to PHP and Linux but I'm thinking this means my PHP library is out of date. When I call
var_dump([
SODIUM_LIBRARY_MAJOR_VERSION,
SODIUM_LIBRARY_MINOR_VERSION,
SODIUM_LIBRARY_VERSION
]);
I get
array(3){[0]=>int(9)[1]=>int(1)[2]=>string(5)"1.0.8"}
And I see at https://github.com/jedisct1/libsodium/releases the latest release is 1.0.16
So I would like to install the latest library. As I'm new to Linux I'm trying to do this in the terminal and I don't know what to do. these are the steps I followed to this point, starting from my home directory
wget https://github.com/jedisct1/libsodium/releases/download/1.0.16/libsodium-1.0.16.tar.gz (downloads the file ok)
tar -xvzf libsodium-1.0.16.tar.gz (unzips the file ok, creates libsodium-1.0.16 directory)
cd libsodium-1.0.16 directory
Now what?
Any help would be appreciated.

Related

ssh2 ssh2_connect() function not found

So I have a class that I build that uses the ssh2 package in php. I have successfully set this up and used and tested this class on apache2 server. The server at work where this is going to be running is an instance of litespeed. I have scoured the web for a way to get ssh2 working with this litespeed server however I cannot for the life of me figure it out. I get ssh2_connect() function not found. If I go go /etc/php/... I can see that the ssh2.ini file exists. However I believe the active php instance is located /usr/local/lsws/lsphp74/7.4/etc/php/ where I do not see the ss2.ini located. Is there a way to get ssh2 installed in the directory that is being used by the server? If I run ssh2_connect at the command prompt, it works just fine as it is most likely using the /etc/php instance of php.
You're correct, ssh2_connect() is provided by a pecl extension. These are optional binary add-ons for php. I'd make a quick phpinfo(); page and add it to the litespeed server so you can see what modules are active and where the config files php is using are actually located on disk.
The install guide can walk you through installing this pecl extension.
https://www.php.net/manual/en/ssh2.requirements.php
Another way to accomplish this is with a pure-php library that doesn't depend on special plug-ins. phpseclib fully implements the ssh protocol in pure php, taking advantage of libraries if they are present but it's able to function without them.
since you didn't mention what exactly is your server env
I would assume it's either OpenLiteSpeed image , or CyberPanel image
first of all , compile libssh2
wget https://libssh2.org/download/libssh2-1.10.0.tar.gz
tar vxzf libssh2-1.10.0.tar.gz
cd libssh2-1.10.0
./configure
make
make install
then compile the PHP extension
mkdir /usr/local/lsws/lsphp74/tmp
pecl channel-update pecl.php.net
/usr/local/lsws/lsphp74/bin/pear config-set temp_dir "/usr/local/lsws/lsphp74/tmp"
/usr/local/lsws/lsphp74/bin/pecl install https://pecl.php.net/get/ssh2-1.3.1.tgz
echo "extension=ssh2.so" > /usr/local/lsws/lsphp74/etc/php/7.4/mods-available/50-ssh2.ini
and finally , restart lsphp process to load new module
touch /usr/local/lsws/admin/tmp/.lsphp_restart.txt
or
killall lsphp
then verify by phpinfo(); to make sure you see ssh2 loaded

Using Libsodium with PHP on WAMP

I'm having really hard trouble installing libsodium on my local server (WAMP64).
I used this guide and many others, but still no luck.
I successfully installed PEAR but I can't use it to install the PHP wrapper of libsodium. Can someone post a little guide step by step to help me?
I would appreciate help installing Halite, wich needs libsodium, because maybe it will be my next step.
Thank you everyone.
On Windows, download the appropriate zip file for your version of PHP and then follow these three steps. (I used 1.0.6 for PHP 7.0 in my testing).
Copy libsodium.dll to the System32 Folder or the same directory as php.exe. Also copy it to the apache/bin/ folder (for me that was C:\xampp\apache\bin).
Copy php_libsodium.dll to the PHP extension directory (C:\xampp\php\ext\ for me)
Add extension=php_libsodium.dll to your php.ini file.
The bolded part in step 1 is what I was missing. As soon as I placed the dll in that folder and restarted Apache, everything started working.
You can create a new php file with this code to verify it is working properly:
<?php
var_dump([
\Sodium\library_version_major(),
\Sodium\library_version_minor(),
\Sodium\version_string()
]);
Do Not Try To Install Pecl Extensions On Windows With Pear/Pecl. It Will Not Work.
Rather use pre-compiled .dll file.
The guide page even says so:
Installing Libsodium and the PHP Extension on Windows
On Windows, download the appropriate zip file for your version of PHP and then follow these three steps.
goto WAMPSERVER and install listed PHP
Enable sodium and check in 'Show PHP loaded Extensions' it will get loaded
check-in PHP module if sodium is available or not with the following command
cmd> php -m
cmd> php --ri sodium
if sodium is not listed then go to your /php/php.ini and search for ';extension=sodium' and remove ';' you will be good to go

Compiling php extensions for MAMP

I need to install a couple of PHP extensions, like memcache and geoip, on MAMP 3.5, for PHP 5.6.10.
What I'm doing is to run phpize:
/Applications/MAMP/bin/php/php5.6.10/bin/phpize
Which outputs:
Configuring for:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
Then configure:
/configure --with-php-config=/Applications/MAMP/bin/php/php5.6.10/bin/php-config
And, afterwards, try to build with make. This is where I get this error:
/Applications/MAMP/bin/php/php5.6.10/include/php/Zend/zend.h:51:11: fatal error: 'zend_config.h' file not found
I downloaded the content of the include/php folder from php.net, version 5.6.10 (found here).
I feel I'm closer now to solving this problem, but I'm at loss with this error. What am I doing wrong, so that apparently the freshly downloaded php from php.net is missing files?
Thank you.
I ended up using pecl instead of manually compiling the extensions.
The headers missing on the make step were I didn't run ./configure on the php folder - I came across this step by chance, really.
Afterwards, all I had to do was run:
sudo /Applications/MAMP/bin/php/php5.6.10/bin/pecl install memcache
And everything was running on wheels.
Before trying pecl, I tried to run make as I was doing on my post, and the extension compiled successfully, but I had versions mismatch between the php and the extension. I had previously tried pecl without success, but I don't really know what changed in my configuration since I last tried.
Anyway, I wrote a gist with all my steps to get this working, in case anyone has the same problem and is a complete beginner on this subject like I am.

How do I solve this PHP-PEAR error / install PEAR on Fedora?

I'm trying to save an old, failing web-server setup consisting of Fedora, PHP, PEAR, and Oracle.
With some difficulty (I'm very new to all four), I've been able to set up something similar on a newer system. I used Fedora 19, PHP 5.5.4 (with Apache 2.4.6), and Oracle 11g.
That just leaves PEAR.
Now, from what I understand, PEAR is some PHP code, like a library, which PHP Web Applications can use to save time from having to code them again - database connection, for example.
But I don't know what to do with it, or even how to get it. Copy paste from my old system? Download using the CLI using yum? Are there packages I need to be aware of, or is it just a one download-one install thing?
For instance, a basic PHP webpage with the following code:
<?php
phpinfo();
?>
works fine on the new server setup, so I'm assured that everything else is working. But when I try to load the PHP files from the other server, it returns an Internal Server Error. I checked the error_log files under /etc/httpd/logs, and most of the errors appear as below:
PHP Fatal error: require_once(): Failed opening required 'MDB2.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/hrweb/includes/functions.php on line 4
EDIT:
According to the PEAR Website, PEAR is included upon the installation of PHP, though not all modules / packages are there. Typing in the command pear in the CLI does confirm it is installed, though it does not help the issue.
I got the MDB2 package via pear install MDB2, though apparently, MDB2_Driver_oci8 is required. Whenever I try to download that, I get the following:
"MDB2_Driver_oci8" version "1.4.1" does not have REST XML available
In addition to this, I also tried to download OLE, which gets me the following:
No releases available for package "pear.php.net/OLE"
This was also previously the error of trying to download MDB2_Driver_oci8.
Thanks.
You have to install the (surprise!) MDB2 package to get MDB2.php:
$ pear install mdb2
and the adapter of your choice:
$ pear install mdb2_driver_mysql-beta
Then make sure the PEAR php directory is in your include path - see the PEAR manual.
"MDB2_Driver_oci8" version "1.4.1" does not have REST XML available
try to install the beta version:
$ pear install mdb2_driver_oci8-beta
No releases available for package "pear.php.net/OLE"
You're trying to install the stable version, but OLE does not have any stable version (yet): http://pear.php.net/package/OLE/download
Append either -alpha or -beta after OLE:
$ pear install OLE-beta

How to install mcrypt on OS X's natively installed PHP?

I am trying to install the mcrypt PHP extension on my OS X Mountain Lion 10.8 operating system. This OS comes shipped with Apache and PHP already installed. The mcrypt extension however does not come shipped with PHP. I want to install mcrypt into the version of PHP that came shipped with my machine.
I do not want to use Homebrew, Macports, or any similar package manager, and I do not want to install another version of PHP in addition to the one I already have. I just want to plug mcrypt into the PHP that came bunded with my OS. I feel like this makes sense, instead of having multiple versions of the same program installed, yet every tutorial I come across seems to all immediately say to use Homebrew/Macports, and the few that don't teach you how to install a new PHP instead of using the one I already have.
I started following the directions laid out on this page: http://www.coolestguyplanettech.com/how-to-install-mcrypt-for-php-on-mac-osx-lion-10-7-development-server/.
I downloaded libmcrypt-2.5.8.tar.gz from Sourceforge.
I extracted the contents with the following command: tar -zxvf libmcrypt-2.5.8.tar.gz.
I entered the libmcrypt-2.5.8 directory that was created and issued the following commands: ./configure, make, and sudo make install.
Now that tutorial says to go into a directory that was created by a new, non-native version of PHP that the tutorial tells you to install, not the native version that came shipped with OS X. The tutorial says to go into the following directory: cd ../php-5.3.13/ext/mcrypt/ (which is a directory I don't have), and run the phpize command. I can't go into that directory because I'm using the native PHP that came with OS X, so instead I go into the libmcrypt-2.5.8 directory, but when I try to run the phpize command I get an error that says: Cannot find config.m4. Make sure that you run '/usr/bin/phpize' in the top level source directory of the module. I do however have the files acinclude.m4 and aclocal.m4 in this directory. I am not sure if they are related to the config.m4 that phpize is looking for.
I am not sure how to proceed. Maybe I should just cut my losses and install another PHP using Macports or Homebrew, but I'd really prefer to use the native PHP that came bundled with OS X. Can you help me figure out how to do this? It would really help me a lot, and help me understand better how PHP and extensions work. Thank you!
"I'd really prefer to use the native PHP that came bundled with OS X.
Can you help me figure out how to do this? It would really help me a
lot, and help me understand better how PHP and extensions work."
The PHP that came bundled with OSX isn't any more "Native" than any other version that you would install.
You don't have that directory because, IIRC, OSX doesn't ship with PHP source, just a compiled binary and apache module.
You can only run phpize on a php extension, which you can get in the PHP source download (including the mcrypt extension). What you downloaded is the C library (which you may also need to install) that the PHP extension will reference (you don't need to worry about how this happens).
If you want to just install that extension:
Download it
Extract and cd into
sudo phpize
sudo ./configure && sudo make && sudo make install
Add extension=mcrypt.so (or whatever is generated) to your php config / php.ini and restart apache
This sounds to me like a good opportunity to learn more about how your computer works. This is some documentation I wrote for myself a few years ago on how to do this:
http://www.calvinfroedge.com/common-php-compile-configuration-options/ (note that the formatting in the blog might not work if you paste it into terminal, for example –with-mysql should be --with-mysql)
Besides, you don't need to get rid of your PHP installation that came with OSX. You can download the PHP source to a brand new directory, compile it, backup the old binary, and either symlink the result of 'which php' to your new installation or add the binaries that get generated after you compile to your source.

Categories