does uncommenting works to install PHP extension - php

this is not a bug in my program but a general doubt. I've heard and read that in Windows people uncomment extension names in PHP.ini to enable them. Does this works in Ubuntu too?
Actually I've tried it in my Ubuntu and it didn't work, just want to be sure it doesn't works like this in Ubuntu or it was my fault somewhere (which doesn't matters now ).
In my case I didn't even touched the ini file but just recompiled the php from source with passing extension arguments. Why didn't I have to enable them?
Tried searching SO but didn't find any questions related to this.

With Windows, pretty much all the extensions are already compiled as DLLs. So when you uncomment the line in the ini file and restart the service, it simply loads the file.
When you compile from source in Linux, you aren't building all the extensions by default. You usually have to explicitly specify which extensions you want to enable and they are compiled along with PHP. So the extension has to be compiled successfully and be accessible to be used. The ini file is simply the instruction of whether or not to TRY loading that extension when PHP starts.
Also, there are some basic extensions that are part of the typical PHP build / configure / make process. You can consult the docs to figure out which ones are default but a good practice is to explicitly enable those that you want.
Don't build EVERY extension if you don't need them though. The more extensions that get loaded, the more memory that PHP needs/uses when starting up.

the simple answer is yes it works but if only the extension is in your ubuntu.

Related

What library do I need for 'pg_connect()'?

I'm trying to connect to another database within a wordpress plugin. Inside the main php file, I tried to call 'pg_connect($con_string);' but I now realize that this function is undefined. Is there a library that I need to include somewhere in the directory? Thanks.
This function is in the php-pgsql package or module. Not sure what OS you are on, but on some Linux distributions the package has version-specific naming like php5-pgsql or php7-pgsql so you might need to install the version specific to whatever PHP version you're using. You can use phpinfo() to output information that will help you troubleshooot what is going on, including versions and what packages are enabled.
The package may need to be installed, or it may be installed but disabled. It is enabled by default in PHP >= 5.3.x. If you're finding it is not included by default, you likely either have a very old version of PHP, or one that is custom-configured not to have this package enabled.
If the issue is enabling it, look in the configuration files. On some systems there is a file installed in /etc/php.d/ like 20-pgsql.ini with a line that will enable the extension. In other systems it is in php.ini which is usually somewhere in the /etc directory. Search these files for a line containing the text pgsql and make sure it is enabled. Then restart the web server (or PHP-FPM if you are using that.)
Hopefully this will address the issue.
If you need further help, the official PostgreSQL documentation is a good resource:
https://www.tutorialspoint.com/postgresql/postgresql_php.htm
And beyond that I would recommend a web search including your specific distribution and possibly PHP version, as this will return information with the correct configuration file locations and options.

When installing just PHP on Windows, all php extensions are commented out by default?

I'm trying to get Laravel installed and when running composer I get lots of errors along the lines of the requested PHP extension mbstring is missing from your system except there are dozens. It's really tiring going one by one and uncommenting these. What am I doing wrong? Do I need to just install apache(edit: I meant XAMPP) and its default php.ini will have better default options?
Is there a way to get a .ini file that has the most common stuff available? Can I just uncomment all extensions or is there a reason that's a bad idea?
Can I just uncomment all extensions or is there a reason that's a bad idea?
Yes, you can uncomment all extensions, but that won't improve your user experience :)
In general: enable only PHP extensions, you really need
The more dynamic extensions PHP needs to load, the more stuff it has to load and process during startup and the more time it takes. So, the startup will be slower.
For instance, enabling the default extension php_pdo_firebird.dll doesn't gain you anything, except, when you really want to access the Firebird database from PHP via PDO.
Is there a way to get a .ini file that has the most common stuff available?
The PHP extensions shipped by PHP itself are all listed in php.ini.
There is also php.ini-development with some dev configurations.
If everything is off by default, then i suggest to enable curl + openssl, mysql, sqlite, mbstring for a start, because:
Curl and Openssl are needed to get Composer running,
Mysql and Sqlite to support these often used databases,
mbstring for UTF8 stuff
and whenever some library meows enable some more ,)

PHP 5.3 - getting it to run on Apache server?

I've set up my own Apache server; with MySQL, PHP and PHPMyadmin.
It used to work previously when I did it before on various computers; but that was the older versions I dealt with, not the latest. However, it's been a while since I've updated my PHP version, so that's why I'm asking this.
What configuration changes do I need to make to get 5.36 to work properly with Apache?
Currently any .htm files can display properly in http://localhost, but no .php ones.
All I see is a text file, so what's gone wrong with this?
The server is not public - in fact, it's on a Windows Vista Home Edition install, and it's a development one. I don't need to worry about anything else just yet, as this is a totally new install.
What config changes do I need to make?
I tried:
# mod_php5
Include conf/extra/suite-php5.conf
but that didn't work, so what's the solution with PHP 5.36?
Should I re-enable the above line (it's currently commented out with the # symbol).
So far the server works; but it's not serving up PHP pages, which is strange.
Anyone got any ideas why? I would gladly appreciate your help!
Won't post the httpd.conf since it's being developed right now though.
No more VC6 versions of PHP 5.3.x?
From the release announcement:
Windows users: please mind that we do no longer provide builds
created with Visual Studio C++ 6. It
is impossible to maintain a high
quality and safe build of PHP for
Windows using this unmaintained
compiler.
For Apache SAPIs (php5_apache2_2.dll), be sure that you
use a Visual Studio C++ 9 version of
Apache. We recommend the PHP builds as
provided by ApacheLounge. For any
other SAPI (CLI, FastCGI via mod_fcgi,
FastCGI with IIS or other FastCGI
capable server), everything works as
before. Third party extension
providers must rebuild their
extensions to make them compatible and
loadable with the Visual Studio C++9
builds that we no longer provide.
Check your config files for http and php. I haven't done this in a while, but you need to add the file type .php to list of files types that you want Apache to serve. READ the config file carefully.
Also, inside your http config file there should be some additional lines that tell Apache where to find php, vis-a-vis the php.ini file. You need to set up your path information inside the config file and in the environment/system variables section of your Microsoft OS.

Understanding extensions in php.ini

I'm having trouble understanding these ;extension=xxx.dll files in php.ini
Is there any document I can refer to which explains these extensions in detail?
The .dll files are for PHP extensions. You can read about all of them here: http://php.net/manual/en/install.windows.extensions.php
PHP extensions give you extra PHP functionality. They are basically function libraries that add features like MySQL functions, LDAP functions, and even Java functions.
To activate the extensions provided by the default PHP install, simply uncomment the ;extension=xxx.dll line (remove the semicolon) so that it just looks like extension=xxx.dll.
However, not all extensions are bundled with PHP. For example, the PECL extensions, including APC, have to be installed externally. Instructions for installing PECL can be found here: http://www.php.net/manual/en/install.pecl.php
"Extension Writing Part I: Introduction to PHP and Zend"
You only need to worry about those if you're running on a Windows server - since they appear to be commented out (; at the start of the line) I would assume you're on a Linux server?
In any case, you should be able to look up each extension individually on Google.

Installing PHP extensions on shared hosting

I need to enable the mcrypt functions on my website, except I'm on a shared host (running linux) and obviously don't have access to the php.ini file. There does seem to be options for installing PEAR modules but a search told me mcrypt wasn't available. Is there any way I can do this, short of begging technical support to help me?
Update: Looking around a bit more, it looks like I might be able to use the dl() function to dynamically load a library at run time. Since I'm only using the mcrypt functions in one spot, I could probably get away with doing this since the performance hit (I assume there is a hit) should be minimal. The only problem now is how to get the libmcrypt.so file?
Another update: I've downloaded the libmcrypt.tar.bz2 file from Sourceforge and run ./configure, make, and then copied the libmcrypt.so.4.4.8 file into my home directory (as libmcrypt.so), but now I can't find where to put it so that the dl() function will find it.
The MCrypt Sourceforge page should have it
http://mcrypt.sourceforge.net/
To compile it just:
wget http://superb-east.dl.sourceforge.net/sourceforge/mcrypt/libmcrypt-2.5.8.tar.gz
tar -xzvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
sudo make install
EDIT:
Can you reference it with a direct path?
What have you tried?
Edit2: It seems that you can only load moduals from the extensions directory set in the php.ini and you cannot override extensions_dir with ini_set so you will either have to convince your host to install it or if they allow you to have your own php.ini (many do usually in [username]/php.ini) then you could set the extensions_dir in there and load the modual with that.
Really the best way is to tell your ISP to include mcrypt support. Even if you bundle your own PHP extension and load it with dl(), there is no guarantee it is going to work after a PHP upgrade, as PHP is sometimes very version-number picky.
dl() will not help you either, since it only loads libraries from certain paths, and those paths are usually only writable by the system administrators for security reasons.
I very much doubt that there is a way to use binary libraries without the consent of the hoster.
PHP in versions before 5.2.5 allowed you to use a path in the dl() function so that you could easily load libraries in a shared environment.
This changed for 'security' reasons with 5.2.5 and as far as I am aware your only option is to get your system administrator to add the module to the extensions_dir.
This issue is described at bugs.PHP.net

Categories