Attempted to call function "ldap_connect" from namespace "App\Bundle\Controller". - php

I can't use the ldap_connect function but I checked in php.ini and it's in.
I didn't find this error on Internet. Everyone is having "Call to undefined function" but I got "Attempted" and can't figure why.
I checked with function_exists('ldap_connect') and it was false.
I use Symfony2, apache and PHP 5.5.9.
I call the function from my controller and I get the parameters from parameters.yml :
$ldap_user = $this->container->getParameter('ldap_user');
$ldap_pass= $this->container->getParameter('ldap_pass');
$ldap_co = ldap_connect($this->container->getParameter('ldap_address'));
If someone could help me that would be awesome.
Thanks in advance.

I think I find the answer. It was an apache2 issue.
I went in /etc/apache2/mods-available to check if ldap.conf and ldap.load were in, and they were. Then I checked in /etc/apache2/mods-enabled in which they were not. And that's the problem.
So I ran the following command : sudo a2enmod ldap in order to activate the ldap module for apache2. Then sudo service apache2 reload and in the instant I saw it enabled in phpinfo().
Maybe that's not the correct way to do it, if anyone have a better answer I'll take it.

You need to enable ldap extension to php. To do that (paths are from Ubuntu) add symbolic link /etc/php5/apache2/conf.d
lrwxrwxrwx 1 root root 31 Sep 23 2014 20-ldap.ini -> ../../mods-available/ldap.ini
(similar to /etc/php5/cli/conf.d if you want to have this available in cli)
Check doc for more info

Related

Running Rscript from within PHP: cannot load shared libraries

I am trying to run R code from within PHP. I am using RHEL 7.4.
However, because Apache runs as a different user than installed the R packages, it cannot load packages:
My PHP code has this line:
echo shell_exec("(Rscript -e 'library(lme4, lib.loc = \"/var/www/R/lib\")')2>&1");
which produces this error in the browser:
Error: package or namespace load failed for 'lme4' in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/var/www/R/lib/Rcpp/libs/Rcpp.so':
/var/www/R/lib/Rcpp/libs/Rcpp.so: failed to map segment from shared object: Permission denied
Execution halted
The file /var/www/R/lib/Rcpp/libs/Rcpp.so has permissions 775, so I don't think the permissions are actually the problem.
How can I tell Apache / PHP where to look for the shared libraries?
The server is not public-facing, so I would take any solution from properly accessing the shared library, to giving user apache sudo access with NOPASSWD to run as my user (or something similarly reckless, since that didn't actually work...).
Thank you!
This appears due in part to an SELinux setting in Red Hat. I'm not entirely sure whether this is Red Hat-centric, or specific to the configuration at my university (who installed Red Hat in the first place).
Originally:
$ getenforce
Enforcing
Fix:
$ sudo setenforce 0
$ getenforce
Permissive
Persistent fix: modify /etc/selinux/config to have the line
SELINUX=Permissive
Credit to this StackOverflow thread.

OCIEnvNlsCreate() failed - please check that ORACLE_HOME and > LD_LIBRARY_PATH

ubuntu 16.10 / nginx / php7.0 / oracle 11 xe
I'm trying to connect to the Oracle databas via PHP. And I get the following errors.
$conn = oci_connect('login', 'pass', 'localhost/xe');
Warning: oci_connect(): OCIEnvNlsCreate() failed. There is something
wrong with your system - please check that ORACLE_HOME and
LD_LIBRARY_PATH are set and point to the right directories in
/var/www/blah.php on line 26
Warning: oci_connect(): Error while trying to retrieve text for error
ORA-01804 in /var/www/blah.php on line 26
Really request variables, they will be empty. This code return empty string.
$test = getenv('LD_LIBRARY_PATH')." ".getenv('ORACLE_HOME');
print ("$test");
But in phpinfo() they are displayed.
I can write environment variables to each file, but this is not an option.
putenv("ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe");
putenv("LD_LIBRARY_PATH=-Wl,-rpath,/u01/app/oracle/product/11.2.0/xe/lib -L/u01/app/oracle/product/11.2.0/xe/lib -lclntsh");
What can I do?
I solved it by removing semicolon from the line ;clean_env=no in the file /etc/php-fpm.d/www.conf in case of php-fpm 5.6 in CentOS 6. Hope it will help in newer PHP versions. Remember to restart php-fpm service after making changes to this file.
We dont have the same infrastructure but I just solved this same issue in :
Apache
CentOS7
PHP 5
Oracle 12cR1
The message says :
please check that ORACLE_HOME and LD_LIBRARY_PATH are set and point to the right directories
In apache, there is a file where you can set the environment variable :
/etc/sysconfig/httpd. There has to be a config file for nginx.
I added the required environment variables.
Assuming that
ORACLE_HOME is /oracle/product/12.1.0/dbhome_1
Oracle client was installed under /oracle/product/12.1.0/client
Add :
ORACLE_HOME=/oracle/product/12.1.0/dbhome_1
LD_LIBRARY_PATH=/oracle/product/12.1.0/dbhome_1/lib:/oracle/product/12.1.0/dbhome_1/network/lib:/oracle/product/12.1.0/client/lib
I also added :
TNS_ADMIN=/oracle/product/12.1.0/dbhome_1/network/admin
ORACLE_SID=<your sid>
After updating /etc/sysconfig/httpd I just restarted Apache's service httpd and that was it:
$ sudo systemctl restart httpd
I hope it helps !
This is related to the incorrect NLS_LANG parameter. It was set to 'NA' in my case. The fix is:
Windows - The NLS_LANG must be unset in the Windows registry (re-named is best). Look for the NLS_LANG subkey in the registry at \HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE, and rename it.
Linux/UNIX - Here you simply issue the Linux command "unset NLS_LANG"

Apache and Symfony date.timezone error

I am trying to install Symfony with my Apache (Ubuntu) but I get this error:
Set the "date.timezone" setting in php.ini* (like Europe/Paris)
Using phpinfo() in my browser it says that the configuration file is in /etc/php5/apache2/php.ini So I modified it wtih
date.timezone = "Europe/Paris"
I also modified the file /etc/php5/cli/php.ini
I also run php app/console cache:clear as it was suggested in this question Fixing requirements in Symfony2 but with no results. I restarted the server every time.
What else can I try?
Thanks!
Try removing double quotes
date.timezone = Europe/Paris
Please see David Jacquel correct solution below !
I leave this answer for historical purposes...
In sf1, I ran through this and got it fixed with a
date_default_timezone_set('Europe/Madrid');
in the bootstrap (that was ProjectConfiguration.class.php).
In sf2 you may modify the web/app.php file to insert the same piece of code. It is a bit hackyish, but will get you up and running.

PHP LDAP Admin - Undefined variable: _SESSION

I'm trying to install PHP LDAP Admin, http://phpldapadmin.sourceforge.net , on a RHEL 6 server. I have the files in place and Apache virtual host directive configured to htdocs.
The error I'm getting is:
Notice: Undefined variable: _SESSION in /path/to/pla/lib/page.php on line 381 Fatal error:
Call to a member function getValue() on a non-object in /path/to/pla/lib/page.php on line 381
PHP (5.4.13) is running on the server, and sessions are not a problem elsewhere. I cloned my git repository to an OSX development box and it works there. I double checked and session_start() is called.
If httpd is running under apache group:
chgrp apache /etc/phpldapadmin/config.php
I had the same problem and finally i solved it just placing config.php
in the correct folder (phpldapadmin/config)...really silly mistake
I had the same problem (ubuntu 14.04).
I changed the permissions on usr/share/phpldapadmin/config.php and that solved the problem.
This has already been answered by harveyzh but this answer is for linux-noobs like me :)
Happens in most cases after update
and apache (or php5-fpm!) didn't run with default users.
Just add the user wich is running Apache2 (or php5-fpm!) to the system group "www-data" (debian) and restart services apache AND if used php5-fpm both.
Get the User apache is running as:
~# sed -rn 's/^User (.+)/\1/p' /etc/apache2/apache2.conf
Remember:
Changing permissions to repo maintained files is a bad idea.
This takes effect only until the next update fixes them back to default...
I had also same problem where we have just changed the group name for phpldapadmin config.php file. It worked for me.
chgrp apache /etc/phpldapadmin/config.php
Use chgrp GNU command with the group name of apache2
In my case was: www-data
So you need to do like that:
chgrp www-data /etc/phpldapadmin/config.php
to find group name of config.php you should use ls -l command line and take the fourth column

oci_connect() works only from command line

OK, so I have this terrible problem with oci, apache, php and suse. First off, versions:
PHP 5.3.15 (cli)
Apache/2.2.22 (Linux/SUSE)
OCI8 1.4.9
SUSE 12.2 32 bit
Oracle client 10.2.0.4
Problem
I have really simple php file:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
oci_connect('user', 'passwd', 'host/sid');
?>
When I run it from command line it executes fine:
machine:~ # php oci.php
machine:~ #
But when i run it in browser, it gives me:
Warning: oci_connect() [function.oci-connect]: OCIEnvNlsCreate() failed. There is something wrong with your system - please check that ORACLE_HOME and LD_LIBRARY_PATH are set and point to the right directories
Apache configuration
I've been struggling with this issue for some time now and I'm pretty sure my apache configuration is correct.
I export all required variables before any apache process is started - I added
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/oracle/home/lib; export LD_LIBRARY_PATH
ORACLE_HOME=/path/to/oracle/home; export ORACLE_HOME
TNS_ADMIN=/path/to/oracle/home/network/admin; export TNS_ADMIN
NLS_LANG=POLISH_POLAND.EE8MSWIN1250; export NLS_LANG
at the beginning of /etc/init.d/apache2 script (I start apache by /etc/init.d/apache2 start).
Apache runs from wwwrun user, who is in oinstall and dba groups:
machine:~ # cat /etc/apache2/uid.conf
User wwwrun
Group www
machine:~ # id wwwrun
uid=30(wwwrun) gid=8(www) groups=8(www),113(oinstall),114(dba)
machine:~ # l $ORACLE_HOME
total 216
drwxr-xr-x 48 oracle oinstall 4096 Jan 25 17:07 ./
drwxrwxr-x 3 oracle oinstall 4096 Jan 25 17:01 ../
...
machine:~ #
Possible problem
I don't have any environmental variables in Environment section in phpinfo(); output - could this be the problem? If yes, how can I fix this? Is it some kind of security issue? I've read about problems like that with SELinux enabled, but I don't have it, my firewall is off.
Solution?
Any help would be greatly appreciated!
Problem solved! Thanks to these (Setting the Oracle Environment section) instructions and ken_yap's answer to this thread.
To put variables in Apache's Environment section you just have to add them in /etc/sysconfig/apache2 file: LD_LIBRARY_PATH=/path/to/oracle/lib.
Another solution ( that do not need root access ) is to add this lines in the php page:
putenv("ORACLE_HOME=/opt/app/oracle/product/11.2.0/db_1");
putenv("LD_LIBRARY_PATH=/opt/app/oracle/product/11.2.0/db_1/lib:/lib:/usr/lib");
Regards
For Debian users - edit file
/etc/apache2/envvars
on the end of file add link to your OCI library - eg.
export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2
Another approach for Centos 7 with nginx
$ sudo vim /etc/ld.so.conf.d/oracle-instantclient.conf
// Add path to oracle client lib, the XX is the version, ex: /usr/lib/oracle/XX/client64/lib
$ sudo ldconfig
$ sudo service php-fpm restart
Done!

Categories