Configure Xdebug
The output should list Xdebug among the installed extensions:
Create a php file containing the following code:


Configure Xdebug in PhpStorm
Check Xdebug installation

- Press Control+Alt+S to open the IDE settings and then select PHP .
- Check the Xdebug installation associated with the selected PHP interpreter:
- On the PHP page, choose the relevant PHP installation from the CLI Interpreter list and click next to the field. The list shows all the PHP installations available in PhpStorm, see Configure local PHP interpreters and Configure remote PHP interpreters.
- The CLI Interpreters dialog that opens shows the following:
- The version of the selected PHP installation.
- The name and version of the debugging engine associated with the selected PHP installation (Xdebug or Zend Debugger). If no debugger is configured, PhpStorm shows the corresponding message:
Alternatively, open the Installation Wizard, paste the output of the phpinfo() , and click Analyze my phpinfo() output . Learn more about checking the Xdebug installation in Validate the configuration of a debugging engine.
Define Xdebug behaviour
- In the IDE settings ( Control+Alt+S ), select Debug under the PHP node to open the Debug page.
- In the Xdebug area, specify the following settings:
- Debug port : appoint the port through which the tool will communicate with PhpStorm. This must be the same port number as specified in the php.ini file:
xdebug.client_port=»
« xdebug.remote_port=»« - Ignore external connections through unregistered server configurations : select this checkbox to have PhpStorm ignore connections received from hosts and through ports that are not registered as deployment server configurations. When this checkbox is selected, PhpStorm does not attempt to create a deployment server configuration automatically.
- Break at first line in PHP scripts : select this checkbox to have the debugger stop as soon as connection between it and PhpStorm is established (instead of running automatically until the first breakpoint is reached). Alternatively turn on the Run | Break at first line in PHP scripts option from the main menu.
- Max. simultaneous connections : use this spin box to limit the number of external connections that can be processed simultaneously.
By default, PhpStorm only listens for incoming IPv4 connections. To enable IPv6 support, you need to make adjustments in PhpStorm JVM options:
- Select Help | Edit Custom VM Options from the main menu.
- In the .vmoptions file that opens, delete the -Djava.net.preferIPv4Stack=true line.
- Restart PhpStorm.
Configure Xdebug for using in the On-Demand mode
PhpStorm supports the On-Demand mode, where you can disable Xdebug for your global PHP installation and have it enabled automatically on demand only when you are debugging your command-line scripts or when you need code coverage reports. This lets your command line scripts (including Composer and unit tests) run much faster.
- Disable Xdebug for command-line scripts:
- In the Settings dialog ( Control+Alt+S ), go to PHP .
- From the PHP executable list, choose the relevant PHP interpreter and click next to it. In the CLI Interpreters dialog that opens, click the Open in Editor link next to the Configuration file: file. Close all the dialogs and switch to the tab where the php.ini file is opened.
- In the php.ini file, find the [xdebug] section and comment the following line in it by adding ; in preposition:
;[xdebug] ;zend_extension = «
« 
- Open the CLI Interpreters dialog and click next to the PHP executable field. PhpStorm informs you that debugger is not installed:
- To enable PhpStorm to activate Xdebug when it is necessary, specify the path to it in the Debugger extension field, in the Additional area. Type the path manually or click and select the location in the dialog that opens.
Configure Xdebug for using in the Just-In-Time mode
PhpStorm supports the use of Xdebug in the Just-In-Time (JIT) mode so it is not attached to your code all the time but connects to PhpStorm only when an error occurs or an exception is thrown. Depending on the Xdebug version used, this operation mode is toggled through the following settings:
- Xdebug 2 uses the xdebug .remote_mode setting, which has to be set to jit .
- Xdebug 3 uses the xdebug.start_upon_error setting, which has to be set to yes .
The mode is available both for debugging command-line scripts and for web server debugging.
Depending on whether you are going to debug command-line scripts or use a Web server, use one of the scenarios below.
Command-line scripts
For debugging command-line scripts, specify the custom -dxdebug.remote_mode=jit (for Xdebug 2) or -dxdebug.start_upon_error=yes (for Xdebug 3) directive as an additional configuration option :
- Press Control+Alt+S to open the IDE settings and then select PHP .
- From the PHP executable list, choose the relevant PHP interpreter and click next to it.
- In the CLI Interpreters dialog that opens, click next to the Configuration options field in the Additional area.
- In the Configuration Options dialog that opens, click to add a new entry.
Type xdebug.start_upon_error in the Configuration directive field and yes in the Value field.
Type xdebug.remote_mode in the Configuration directive field and jit in the Value field.
Web server debugging
- Make sure that the debugging engine on your local or remote web server is properly configured. For more information, refer to Validate the configuration of a debugging engine.
- Open the php.ini file which is reported as loaded and associated with Xdebug.
- In the php.ini file, find the [xdebug] section.
Change the value of the xdebug.start_upon_error from the default default to yes .
Change the value of the xdebug.remote_mode from the default req to jit .
Configure Xdebug running in a Docker container
To configure Xdebug running in a Docker container, provide the Xdebug-specific parameters in the Dockerfile , for example:
RUN pecl install xdebug \ && docker-php-ext-enable xdebug && echo «xdebug.mode=debug» >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ && echo «xdebug.client_host = host.docker.internal» >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
In this example, we’re modifying /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini providing the mode and client_host Xdebug parameters.
Note that the xdebug.client_host value should be replaced with the IP address of the machine where PhpStorm is running, which is accessible from the Docker container. If you are using Docker for Windows or Docker for Mac, you can set xdebug.client_host to host.docker.internal , which automatically resolves to the internal address of the host, letting you easily connect to it from the container.
RUN pecl install xdebug \ && docker-php-ext-enable xdebug && echo «xdebug.remote_enable=on» >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ && echo «xdebug.remote_host = host.docker.internal» >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
In this example, we’re modifying /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini providing the remote_enable and remote_host Xdebug parameters.
Note that the xdebug.remote_host value should be replaced with the IP address of the machine where PhpStorm is running, which is accessible from the Docker container. If you are using Docker for Windows or Docker for Mac, you can set xdebug.remote_host to host.docker.internal , which automatically resolves to the internal address of the host, letting you easily connect to it from the container.
Configure Xdebug running on a Vagrant instance
To configure Xdebug running on a Vagrant instance, connect to the Vagrant machine and provide the Xdebug-specific parameters in the php.ini file:
[xdebug] zend_extension=»
Note that the xdebug.client_host value is 10.0.2.2 . This is the gateway used in the default Vagrant setup, which allows connecting from the instance to host where PhpStorm is running.
[xdebug] zend_extension=»
Note that the xdebug.remote_host value is 10.0.2.2 . This is the gateway used in the default Vagrant setup, which allows connecting from the instance to host where PhpStorm is running.
ini_set
Sets the value of the given configuration option. The configuration option will keep this new value during the script’s execution, and will be restored at the script’s ending.
Parameters
Not all the available options can be changed using ini_set() . There is a list of all available options in the appendix.
The new value for the option.
Return Values
Returns the old value on success, false on failure.
Changelog
| Version | Description |
|---|---|
| 8.1.0 | value now accepts any scalar type (including null ). Previously, only string values were accepted. |
Examples
Example #1 Setting an ini option
if (! ini_get ( ‘display_errors’ )) ini_set ( ‘display_errors’ , ‘1’ );
>
echo ini_get ( ‘display_errors’ );
?>
See Also
- get_cfg_var() — Gets the value of a PHP configuration option
- ini_get() — Gets the value of a configuration option
- ini_get_all() — Gets all configuration options
- ini_restore() — Restores the value of a configuration option
- How to change configuration settings
User Contributed Notes 20 notes
9 years ago
I have experienced on some systems that ini_set() will fail and return a false, when trying to set a setting that was set inside php.ini inside a per-host setting. Beware of this.
21 years ago
[[[Editors note: Yes, this is very true. Same with
register_globals, magic_quotes_gpc and others.
]]]
Many settings, although they do get set, have no influence in your script. like upload_max_filesize will get set but uploaded files are already passed to your PHP script before the settings are changed.
Also other settings, set by ini_set(), may be to late because of this (post_max_size etc.).
beware, try settings thru php.ini or .htaccess.
6 years ago
When checking for the success of ini_set(), keep in mind that it will return the OLD value upon success — which may have been «0». Therefore you cannot just compare the return value — you have to check for «identity»:
// This will NOT determine the success of ini_set(), instead
// it only tests if the old value had been equivalent to false
if ( ! ini_set ( ‘display_errors’ , ‘1’ ) )
throw new \Exception ( ‘Unable to set display_errors.’ );
// This is the CORRECT way to determine success
if ( ini_set ( ‘display_errors’ , ‘1’ ) === false )
throw new \Exception ( ‘Unable to set display_errors.’ );
?>
This explains reported situations where ini_set() «always» seems to fail!
17 years ago
set PHP_INI_PERDIR settings in a .htaccess file with ‘php_flag’ like this:
php_flag register_globals off
php_flag magic_quotes_gpc on
17 years ago
When your ISP does not allow you to add the default include directories — it might be useful to extend the ‘include_path’ variable:
21 years ago
If it’s not your server and therefore you want to hide the data in your session variables from other users, it�s very useful to set the session.save_handler in your scripts to shared memory with:
Remember: You have to set it in every script that uses the session variables BEFORE «session_start()» or php won’t find them.
17 years ago
Be careful with setting an output_handler, as you can’t use ini_set() to change it. *sigh*
In my php.ini I have this for my web pages (and I want it):
But this causes my command line scripts to not show output until the very end.
#!/usr/bin/php -q
ini_set ( ‘output_handler’ , ‘mb_output_handler’ );
echo «\noutput_handler => » . ini_get ( ‘output_handler’ ) . «\n» ;
?>
root@# ./myscript.php
output_handler => ob_gzhandler
Apparently (acording to Richard Lynch):
> TOO LATE!
> The ob_start() has already kicked in by this point.
> ob_flush() until there are no more buffers.
9 years ago
Note that this function only works with PHP_INI_ALL options!
19 years ago
While this doesn’t belong in the manual, it should be useful for people looking on this page for zend_optimizer.* ini options, which are commonly installed:
Information on the «zend_optimizer.optimization_level» and «zend_optimizer.enable_loader» options is available at:
12 years ago
Careful — in some cases, when setting zlib.output_compression to «On» via ini_set, PHP won’t send the Content-type header and browsers will garble the output. Set it to the desired buffer size instead, which sends the correct header:
ini_set ( «zlib.output_compression» , 4096 );
?>
21 years ago
[[[Editors note: Just because you’re able to set something
doesn’t mean it will work as expected. Depends on the
setting. For example. setting register_globals at
runtime will be of little use as its job has already
been completed by the time it reaches your script.
]]]
When a setting can not be changed in a user script, the return value of ini_set is «empty», not «false» as you may expect.
If you check in your script for return value is «false» the script will continue processing, although the setting has not been set.
The boolean return value is used for settings that can be changed in a script. Otherwise the empty value is returned.
To test for both error conditions use:
if (empty( $blnResult ) or (! $blnResult )) <
echo «setting cannot be set» ;
exit;
>
?>
8 years ago
if u receive an Error with generic like :
Maximum execution time of 30 seconds exceeded
if u set ini_set(max_execution_time, 300);
your problem will be solved
pls note that the 300 , is 300 seconds , which means 5 minute you can set another value !
How do I enable php to work with postgresql?
You need to install the pgsql module for php. In debian/ubuntu is something like this:
sudo apt-get install php5-pgsql
Or if the package is installed, you need to enable de module in php.ini
extension=php_pgsql.dll (windows) extension=php_pgsql.so (linux)
answered May 17, 2012 at 17:51
Jorge Olivares Jorge Olivares
1,477 1 1 gold badge 11 11 silver badges 14 14 bronze badges
Hi do you know how I would install it in windows? Sorry I don’t have ubuntu yet..
May 17, 2012 at 17:53
Depends. You are using wamp or something like that?
May 17, 2012 at 17:59
try to enable the module first, editing php.ini and searching for php_pgsql and remove the ; in the begining of the line. Then you need to reload your service.
May 17, 2012 at 18:04
Just an update on this old thread for php7 the command is: sudo apt install php7.0-pgsql
Mar 7, 2017 at 21:09
Running php 7.0 — I had to add «extension=pgsql.so» to «php.ini» = «open database successfully» = 🙂
Mar 10, 2019 at 13:09
Uncomment the following in php.ini by removing the «;»
;extension=php_pgsql.dll
Use the following code to connect to a postgresql database server:
pg_connect("host=localhost dbname=dbname user=username password=password") or die("Can't connect to database".pg_last_error());
22.4k 2 2 gold badges 39 39 silver badges 64 64 bronze badges
answered May 17, 2012 at 18:00
Sachin Puri Sachin Puri
876 7 7 silver badges 6 6 bronze badges
I’m still seeing PHP Fatal error: Call to undefined function pg_connect() , although I know I’ve uncommented it. Ideas?
May 6, 2015 at 20:17
For debian/ubuntu install
sudo apt-get install php-pgsql
answered Dec 8, 2018 at 10:21
1,653 1 1 gold badge 17 17 silver badges 15 15 bronze badges
- SO: Windows/Linux
- HTTP Web Server: Apache
- Programming language: PHP
Enable PHP to work with PostgreSQL in Apache
In Apache I edit the following configuration file: C:\xampp\php.ini
I make sure to have the following lines uncommented:
extension=php_pgsql.dll extension=php_pdo_pgsql.dll
Finally restart Apache before attempting a new connection to the database engine.
Also, I leave my code that ensures that the connection is unique:
private static $pdo = null; public static function provideDataBaseInstance() < if (self::$pdo == null) < $dsn = "pgsql:host=" . HOST . ";port=5432;dbname=" . DATABASE . ";user=" . POSTGRESQL_USER . ";password=" . POSTGRESQL_PASSWORD; try < self::$pdo = new PDO($dsn); >catch (PDOException $exception) < $msg = $exception->getMessage(); echo $msg . ". Do not forget to enable in the web server the database manager for php and in the database instance authorize the ip of the server instance if they not in the same instance."; > > return self::$pdo; >
answered Dec 7, 2018 at 1:07
Braian Coronel Braian Coronel
22.2k 4 4 gold badges 58 58 silver badges 62 62 bronze badges
I have to add in httpd.conf this line (Windows):
LoadFile "C:/Program Files (x86)/PostgreSQL/8.3/bin/libpq.dll"
answered Sep 28, 2015 at 10:37
Wojciech Legierski Wojciech Legierski
61 1 1 silver badge 3 3 bronze badges
Where would one find httpd.conf
Mar 1, 2018 at 14:31
inside config file for your apache server. If you are using mamp, then C:\MAMP\bin\apache\conf\httpd.conf
Jun 16, 2021 at 18:35
just install the database driver:
apt-get install php5-pgsql php5-mysql php5-sqlite . and so on .
answered Aug 18, 2014 at 19:39
augustowebd augustowebd
382 2 2 silver badges 8 8 bronze badges
And reload the PHP config (reload apache/nginx etc) after install new extensions
Aug 18, 2014 at 21:33
I installed PHP on windows IIS using Windows Platform Installer (WPΙ). WPΙ creates a «PHP Manager» tool in «Internet Information Services (IIS) Manager» console. I am configuring PHP using this tool.
PDO and all the major drivers ship with PHP as shared extensions, and simply need to be activated by editing the php.ini file: extension=php_pdo.dll
so i activated the extension using PHP Manager and now PDO works fine
PHP manager simple added the following two lines in my php.ini, you can add the lines by hand. Of course you must restart the web server.
[PHP_PDO_PGSQL] extension=php_pdo_pgsql.dll
How to Install PHP Extensions from Source
Sometimes it’s hard to know which PHP extensions you’ll need before you install PHP. In cases where you need to add extensions later on, you might get lucky and the extension could be in the repository of the OS you’re using. It might just be a simple sudo apt-get install php5-intl away. In other cases, however, you might need to install it from source – Phalcon is one such case, but it makes the procedure extremely simple by introducing vendor support, shortcuts and pre-written instructions for your OS to carry out. What if there’s no such thing for other extensions, though?
In this tutorial, we’ll go through installing some custom extensions on Linux systems (and OS X – the process is nearly identical). The procedure is very similar to what we already did on Nitrous.io, but adapted for local environments – more specifically, Laravel Homestead. You can easily derive installation instructions from this tutorial and apply them to other distros.
Booting the VM
If you haven’t already, read the Homestead post linked above and get it up and running. Immediately after running a new Homestead box, you should be able to do this:

That’s perfectly fine, this happens because the folder that’s mounted by default actually doesn’t contain any files yet. Now vagrant ssh into the VM, and execute the following commands:
cd Code git clone https://github.com/Swader/publicinfo
This creates a valid PHP Info file in the path that Homestead is set to by default. Refreshing the URL will now produce a PHPInfo screen:

Prepping the Environment
To build extensions from source, we need the PHP dev tools installed on our machine, as well as a compiler that can produce the extension file. Here’s how you install these prerequisites on various operating systems:
Ubuntu
sudo apt-get install php5-dev php5-mysql gcc libpcre3-dev
Fedora
sudo yum install php-devel php-mysqlnd gcc libtool
RHEL
sudo yum install php-devel php-mysql gcc libtool
Suse
yast2 -i php5-pear php5-devel php5-mysql gcc
If you’re using the most recent Homestead, all these tools will already be installed for you. With everything prepared, let’s start installing extensions.
Installing Extensions
There are two types of extensions you can install: bundled with PHP but not installed by default, and third party extensions. Third party extensions like Phalcon usually make the installation process much easier by providing shortcuts, as they don’t have to comply to certain traditions bundled PHP extensions are bound by.
First, let’s move into the home folder on the vm: cd ~ . In there, make a downloads folder, and cd into it. When installing a bundled extension, you’ll need the source code of PHP on your machine, preferably one matching your current version. The version Homestead uses is 5.5.12, so I’ll be downloading that one:
wget http://be2.php.net/distributions/php-5.5.12.tar.bz2 tar xvjf php-5.5.12.tar.bz2 cd php-5.5.12
I’m using the Belgian mirror above, feel free to use that one or any other from the download archives.
To see the sources of all bundled extensions, go into the ext folder inside the unarchived PHP source code folder and do a list with ls .

Installing a bundled extension
First, we’ll install the PHP-intl extension if you don’t have it installed already. If you do, that’s fine – the installation procedure you’ll see below is identical for every bundled PHP extension. The intl extension is for internationalization – read more here if you’re interested.
Seeing as the intl extension needs the ICU library as a prerequisite (as stated in the requirements), let’s install that first.
sudo apt-get install icu-devtools icu-doc libicu-dev libicu52 libicu52-dbg
Under other distributions, the installation instructions may vary. It’s best if you refer to the ICU site or your individual distribution’s docs for this step.
Once ICU is installed, do the following while still in the ext folder:
cd intl phpize ./configure --enable-intl make sudo make install
Let’s explain what’s going on.
- phpize prepares the extension’s folder for compliation. It allows you to do the subsequent commands by creating a configure file, and basically making the extension’s folder “think” it’s PHP itself. The procedure after phpize is, in fact, identical to what you would do when installing PHP from source – only in this case, just a fragment of PHP is compiled and prepared for use with the already compiled and installed PHP.
- ./configure —enable-intl configures the environment for compilation. It prepares everything the compiler will need to craft the intl.so file which we’ll be using. The enable-intl flag is necessary even though we’re in the intl folder because the folder, effectively, thinks it is PHP, and we need to help it live that illusion. This command tells it: “Ok, you’re PHP’s source code. Now compile and install with the intl extension.”, when in fact, it’s the only part that can be installed from this folder.
- make will compile the sources into intl.so , placing the file into the very folder you’re currently in, under the modules subfolder.
- sudo make install will move this file into the current PHP installation’s extensions folder.
All we need to do now is enable the extension by having php.ini consume it. We’ll do that later, let’s compile a third party extension first.
Installing a third party extension
We’ll be installing Mongo as a third party extension. There are binary distributions available for Mongo which make installation simpler, but let’s do it manually for the sake of education. We’ll assume you already have the actual Mongo installed, and are thus focusing only on the PHP extension. If you don’t have Mongo installed, refer to their installation docs.
git clone https://github.com/mongodb/mongo-php-driver cd mongo-php-driver phpize ./configure make sudo make install
This has built our mongo.so file, and placed it into the extensions folder of our PHP installation. We’ll enable it in the next section.
Enabling and Testing
To see if the compiled .so files are indeed in our PHP extensions folder, list out its contents:

As you can see, there they are, highlighted in bright green.
To enable them, we need to tell php.ini about them. There are several ways to do this:
- You can put the lines extension=mongo.so and extension=intl.so directly into php.ini . This works, and is a perfectly valid approach in most cases.
- You can create a separate ini file for each of these, put them in a folder that gets auto-included after php.ini is loaded, and maintain separation and isolation of php.ini that way. This approach is healthier, though harder to accomplish.
- You can combine 2) and the default tools for enabling PHP mods. Homestead uses this approach, and so will we.
cd `/etc/php5/mods-available`
This folder is the repository of all such individual ini files. Create two new files here:
sudo touch mongo.ini echo "extension=mongo.so" | sudo tee -a mongo.ini sudo touch intl.ini echo "extension=intl.so" | sudo tee -a intl.ini
These commands created two new ini files, each for one of the extensions we’ve previously built. As they are now in the mods-available folder, we can use the already available php5enmod (short for PHP enable mod) command line tool.
sudo php5enmod mongo sudo php5enmod intl
Note: If you don’t have the php5enmod tool, symlinking the ini files into the conf.d folder of various php runtimes will do the trick:
ln -s /etc/php5/mods-available/mongo.ini /etc/php5/cli/conf.d/mongo.ini ln -s /etc/php5/mods-available/intl.ini /etc/php5/cli/conf.d/intl.ini ln -s /etc/php5/mods-available/mongo.ini /etc/php5/fpm/conf.d/mongo.ini ln -s /etc/php5/mods-available/intl.ini /etc/php5/fpm/conf.d/intl.ini
The reason why there’s four entries is that we have the command line version of PHP and the FPM version of PHP. Each uses its own php.ini file, and each loads its own conf.d folder for extensions – hence, we need to add both extensions to both PHP versions if we want the extensions available all-around. Use this approach only if you don’t have the php5enmod tool.
Finally, let’s restart nginx and php-fpm to load these changes.
sudo service nginx restart sudo service php5-fpm restart
To see if we’ve got them installed, refresh the PHPinfo screen from before and search for mongo and intl respectively.

Removing Extensions
To remove extensions, there’s no need to delete any actual files unless you’re really low on space. You can do it in three ways:
- Run php5dismod if you have the tool available. It’s the opposite of the php5enmod tool mentioned above. The .so files will stay in place, and the ini files will remain in mods-available , they just won’t load because their symlinks will be removed from the fpm and cli conf.d folders.
- Remove the symlinks manually. E.g. sudo rm /etc/php5/cli/conf.d/mongo.ini
- If you enabled the extensions by putting them directly into the php.ini files, remove those lines from the php.ini files, or better yet, comment them so that they remain accessible for further use should you ever change your mind.
Conclusion
As you can see, installing extensions from source is extremely simple, even if there are no precise instructions and even if the extension isn’t supported by an OS’s official repository. The next time you need to add an extension into your PHP installation on a *nix system (this tutorial applies to OS X as well), refer back to this post for a refresher.
Please leave your feedback below, and let me know if you’re confused by a specific extension and would like help with installing it.
Share This Article
Bruno is a blockchain developer and technical educator at the Web3 Foundation, the foundation that’s building the next generation of the free people’s internet. He runs two newsletters you should subscribe to if you’re interested in Web3.0: Dot Leap covers ecosystem and tech development of Web3, and NFT Review covers the evolution of the non-fungible token (digital collectibles) ecosystem inside this emerging new web. His current passion project is RMRK.app, the most advanced NFT system in the world, which allows NFTs to own other NFTs, NFTs to react to emotion, NFTs to be governed democratically, and NFTs to be multiple things at once.
