I've hit a roadblock with my phpunit functional tests. The AWS SDK requires APC, for some reason I can't get phpunit to load the extension. I'm not sure where I'm going wrong. The CLI is using the same ini file as MAMP
Gregs-MacBook-Pro:HvH-PHP greg$ php --ini
Configuration File (php.ini) Path: /Applications/MAMP/bin/php/php5.3.6/conf
Loaded Configuration File: /Applications/MAMP/bin/php/php5.3.6/conf/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
Gregs-MacBook-Pro:HvH-PHP greg$
I've also attempted to add the ini file into app/phpunit.xml.dist
<php>
<ini name="mamp" value="/Applications/MAMP/bin/php/php5.3.6/conf/php.ini"/>
<server name="KERNEL_DIR" value="app/" />
</php>
Error message in CLI
PHP Fatal error: Call to undefined function apc_fetch() in /vendor/aws-sdk-for-php/lib/cachecore/cacheapc.class.php on line 58
EDIT: Some more test as per comments
In CLI I can run a test script with apc_fetch(); and it works successfully.
Running php -m also shows APC as an installed module
Any suggestions as to what else I should try?
I could propose you 2 solutions:
Create a symlink of /Applications/MAMP/bin/php/php5.3.6/conf/php.ini to /private/etc/php.ini
Modify phpunit execution file and append -c /Applications/MAMP/bin/php/php5.3.6/conf/ to the php run command. Also - check if correct php binary is used. If it is not - change to the correct path first and check if issue has been fixed
Related
I just upgraded my PhpStorm project from PHPUnit 4.x to PHPUnit 5.x. Running my unit tests works fine.
In order to get "run with coverage" working, I had to edit my Run/Debug configuration and add --whitelist=/path/to/whitelisted/dir to Test Runner options. Now coverage is generated when I choose "Run with coverage," but I get this Xdebug warning.
Testing started at 12:06 PM ...
/usr/local/opt/php56/bin/php -dzend_extension=/usr/local/opt/php56-
xdebug/xdebug.so -dxdebug.coverage_enable=1
/Users/bwood/code/php/WpsConsole/vendor/phpunit/phpunit/phpunit --
whitelist=/Users/bwood/code/php/WpsConsole/src --coverage-clover /Users/bwood/Library/Caches/PhpStorm2017.3/coverage/WpsConsole$NEW.coverage --no-configuration /Users/bwood/code/php/WpsConsole/tests/UnitTests --teamcity
Cannot load Xdebug - extension already loaded
PHPUnit 5.7.27 by Sebastian Bergmann and contributors.
I think the issue is that php is being called with
-dzend_extension=/usr/local/opt/php56-xdebug/xdebug.so
But I can't figure out where I can remove that option. I'm testing a console application so there is no webserver configuration.
I had two different problems that led to this same situation. (Mine was saying already loaded twice).
The first was the above debugger extension field in PHPStorm. I fixed that but was still having problems.
So then I ran:
>php --ini
Cannot load Xdebug - it was already loaded
Configuration File (php.ini) Path: /usr/local/etc/php/7.2
Loaded Configuration File: /usr/local/etc/php/7.2/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.2/conf.d
Additional .ini files parsed: /usr/local/etc/php/7.2/conf.d/ext-opcache.ini
Since all of those files were in the same base directory I went to /usr/local/etc/php
$:/usr/local/etc/$ grep -r 'xdebug' .
./php/7.2/php.ini:zend_extension="xdebug.so"
./php/7.2/php.ini:zend_extension="xdebug.so"
This showed me that the problem was in my php.ini file. For some reason, I had this at the top of my php.ini file.
zend_extension="xdebug.so"
zend_extension="xdebug.so"
[PHP]
I removed one of the lines and the warning went away!
Check your PHP Interpreter in PhpStorm -- there is a separate field for xdebug extension. It allows you to not to have xdebug loaded in actual php.ini (so the ordinary script execution will be faster) and only load xdebug when needed (debug/coverage).
Based on your info so far you have it in php.ini and there. Proposed solution is to remove it from that field.
P.S. Obviously, it works for CLI stuff only and dopes not affect browser based debug in any way (as it's web server that runs PHP so IDE cannot pass such parameter there).
I recently deployed a new Symfony 4 project to a prod server where I set (via ssh) both APP_ENV and APP_SECRET among others, as environment variables. Both commands printenv and set list those variables in their output so I assume everything should be fine on that part.
I get an error 500 on the site though, the log returning PHP Fatal error: Uncaught RuntimeException: APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.
What am I missing here ?
[EDIT 2020] --> use the 'symfony/dotenv'
According to the how to deploy official documentation what you can do is to move 'symfony/dotenv' in your composer file from require-dev to require so it's installed also on production environement. Then you can keep using a .env.local file.
If you don't want or can't use the 'symfony/dotenv'
For Apache and on Ubuntu first you need mod_env activated
sudo a2enmod env
sudo service apache2 restart
Then put the environement variable in the .htacess or in the vhost config file. For SF4 the .htacess is in /public and here is the syntax. I don't know if order matter, I would say no, so I added them on the top of the file.
SetEnv APP_ENV prod
SetEnv APP_SECRET fjsdkfj...
SetEnv DATABASE_URL mysql://...
Now some random useful tricks :
You don't want to commit the .htaccess file. Add it to the shared part of your deployment tool. In my case (easy-deploy-bundle)
->sharedFilesAndDirs(['public/.htaccess'])
You'll need to copy the environment variables in /etc/environment so it's available by composer ... this one is a real pain in the ass, because now you duplicated your variables. So the Symfony team said env variable are betters because safer and standard. But duplicate the information is not safer at all. Maybe I'm doing it wrong (which is completly possible). If you know how to avoid this please share.
The printenv command will show you if it's correctly configured.
If you use easy-deploy-bundle for production remove the --quiet option on composer so you have a clear error message if it fail (because it doesn't find the env variable for example). Also check that --no-dev option is here, so it won't install dotenv package.
->composerInstallFlags('--prefer-dist --no-interaction --no-dev')
System variables won’t be available to your web server. The variable should be defined in the vhost/htaccess file. I assume you are using Apache.
if you are using nginx have to defined at the end of pool configuration file.
php5
/etc/php5/fpm/pool.d/www.conf
php7
/etc/php/7.1/fpm/pool.d/www.conf
I have installed Lampp on my linux system, and I am learning symfony2, while trying to create the schema with symfony2 command
php app/console doctrine:schema:create
I am getting the following error message:-
PDOException “could not find driver”
I also uncomment this line extension=php_pdo_mysql.dll in php.ini file
I tried to look and google my issue but couldn't resolve my problem. when i run php -m command i am getting the following result:-
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626+lfs/mysql.so' - /usr/lib/php5/20090626+lfs/mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626+lfs/mysqli.so' - /usr/lib/php5/20090626+lfs/mysqli.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626+lfs/pdo_mysql.so' - /usr/lib/php5/20090626+lfs/pdo_mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
date
dba
dom
ereg
exif
fileinfo
filter
ftp
gettext
hash
iconv
json
libxml
mbstring
mhash
openssl
pcntl
pcre
PDO
----
----
Is there a way i can remove this issue ?
In Ubuntu, write in the console
sudo apt-get install php5-gd php5-mysql
and it will work
Hope you are running your project in localhost. In your project folder app/config a file named parameters.ini , Make sure that your Mysql database connection cofiguration is correct. If you are using mysql See database_driver=pdo_mysql is its driver.
Below is an example.
database_driver = pdo_mysql
database_host = localhost
database_port =
database_name = databasename
database_user = msqlusername
database_password = mysqlpassword//if not make blank
mailer_transport = smtp
mailer_host = localhost
mailer_user =
mailer_password =
locale = en
secret = ThisTokenIsNotSoSecretChangeIt
Hope it helps you.
You need to have a module called pdo_mysql.
Look for the following in phpinfo() output,
pdo_mysql => PDO Driver for MySQL, client library version => 5.1.44
to install pdo_mysql you need to do this:
pecl install pdo
pecl install pdo_mysql
and then add the following to your php.ini file:
extension=pdo.so
extension=pdo_mysql.so
brew install php70-pdo-pgsql
in case you installed php7 on mac with brew and, change php version according to what you have installed.
if you are using XAMPP then in php.ini file line no 897(depends on version),
;extension=php_pdo_pgsql.dll
uncomment it , then it appears like below
extension=php_pdo_pgsql.dll
in php.ini file line no 897, then restart XAMPP.
There are two PHP versions installed in my server PHP 5.6 and PHP 7
When I run the command php app/console doctrine:schema:update I have the error : [PDOException] could not find driver
I resolve this error by specifying the PHP version:
php5.6 app/console doctrine:schema:update
Looks like your install is missing the .so files it needs to implement the mysql connection. If you're using a package management system to install PHP then make sure you've installed all the necessary submodules (in this case I think you'll need mysql-dev, and the various PHP PDO modules), though such dependencies should have been resolved for you by the package manager.
If you didn't go through a package manager, then you'll have to compile the required .so files from source.
I had the same problem and for me, it was having multiple PHP versions.
So specifying the full address of the PHP solved the problem.
Adding to Jaspreet Chahal's answer.
When installing PDO as a shared module, the php.ini file needs to be updated so that the PDO extension will be loaded automatically when PHP runs. You will also need to enable any database specific drivers there too; make sure that they are listed after the pdo.so line, as PDO must be initialized before the database-specific extensions can be loaded. If you built PDO and the database-specific extensions statically, you can skip this step(Source).
What I mean is, it should look something like this -
extension=pdo.so should be placed before the extensions of the different database drivers.
Maybe you forget to install doctrine/dbal
composer update
composer require doctrine/dbal
if it didn't work go to your php.ini (according to current version)
and remove ";"
;extension=pdo_mysql.so
I would like to use PHPUnit to create code coverage reports. I have tried a lot of installation setups found on the web. But nothing seems to work out.
I use the latest version of Laravel 5 (>5.2) and PHPUnit v. 5.0.10. Further, I use MAMP on Mac OS X 10.9.5 running PHP 7.
When I run PHPUnit that is integrated in my Laravel distribution, I receive the following error.
$ vendor/bin/phpunit -v
PHPUnit 5.0.10 by Sebastian Bergmann and contributors.
Runtime: PHP 7.0.0
Configuration: /Applications/MAMP/htdocs/myProject/phpunit.xml
Error: No code coverage driver is available`
My composer file looks like:
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "5.0.*",
"phpunit/php-code-coverage": "^3",
"symfony/css-selector": "2.8.*|3.0.*",
"symfony/dom-crawler": "2.8.*|3.0.*"
},
I have also tried the following command:
/Applications/MAMP/bin/php/php7.0.0/bin/phpdbg -qrr ../../../htdocs/myProject/vendor/bin/phpunit -v
This seems to set up the code coverage driver well, but it ends up in an exception:
$ /Applications/MAMP/bin/php/php7.0.0/bin/phpdbg -qrr ../../../htdocs/myProject/vendor/bin/phpunit -v
PHPUnit 5.0.10 by Sebastian Bergmann and contributors.
Runtime: PHPDBG 7.0.0
Configuration: /Applications/MAMP/htdocs/myProject/phpunit.xml
[PHP Fatal error: Uncaught ErrorException: include(/Applications/MAMP/htdocs/myProject/app/Exceptions/Handler.php): failed to open stream: Too many open files in /Applications/MAMP/htdocs/myProject/vendor/composer/ClassLoader.php:412
Stack trace:
...
The phpunit.xml looks as follows:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="bootstrap/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<logging>
<log type="coverage-html" target="./tests/codeCoverage" charset="UTF-8"/>
</logging>
<filter>
<whitelist>
<directory suffix=".php">app/</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
</php>
</phpunit>
Is it possible to use PHPUnit that comes with the Laravel framework together with code coverage? How should I set it up and use it?
Thanks a lot for your help.
It seems like you are missing the Xdebug extension. If you're using homebrew you can install it like:
brew install php70-xdebug
After that, don't forget to edit your php.ini file to enable the extension.
php -i | grep xdebug
After checking that xdebug is enabled you should be able to do code coverage
Update for anyone else stuck;
pecl install xdebug
For windows users:
1) Download xdebug
2) Rename the file to _php_xdebug.dll_ and copy the file to the ext folder in your php installation e.g C:\Program Files (x86)\php\ext
3) Open your php.ini file. For me it’s available at C:\Program Files (x86)\php\php.ini.
4) Paste the below code at the bottom of the file.
zend_extension = php_xdebug.dll
xdebug.remote_enable = 1
xdebug.remote_handler = dbgp
xdebug.remote_host = localhost
xdebug.remote_autostart = 1
xdebug.remote_port = 9000
xdebug.show_local_vars = 1
Update for PHP 7.1
xdebug is essential for code lookup and coverage , so xdebug is must to be installed or enabled in test environment. xdebug in production environment is not suggestible, it will affect performance if you turned on
brew install php71-xdebug
As other developers answered, you need to install PHP Xdebug but I want to add new recommend for the developers who are using homestead by default have Xdebug (but it is off) and you can make it ON or OFF
If you want to make it on use below command in homestead
#for on :
xon
#for off:
xoff
Then check php -v and you will see Xdebug in the detail box
it's worked for me. follow this step :
1.) install php7.x-dev, (x) is PHP version on your Linux server
sudo apt-get install php7.x-dev
2.) install Xdebug through PECL on Linux
sudo pecl install xdebug
3.) add the following php.ini file. (you can insert it on last line)
zend_extension="/wherever/you/put/it/xdebug.so"
If you run phpunit inside a vagrant box then you don't need to install xdebug in local and homestead comes with xdebug install automatically. only needs to link homestead xdebug.ini file
Here is the step that worked for me:
cd ~/homestead/REPLACE THIS WITH YOUR HOMESTEAD FOLDER IN LOCAL //
vagrant ssh
sudo ln -s /etc/php/7.2/fpm/conf.d/20-xdebug.ini /etc/php/7.2/cli/conf.d/
In the above command if your running 7.3 or 7.1 then replace it based on your php version
To Reproduce, kindly follow the solution(s) below;
Steps to reproduce the behavior if you don't have Xdebug activated already:
Inside your project root directory open your CMD terminal and type php -i
A list of important information concerning your php will be listed in the CMD terminal
Copy and paste the output here https://xdebug.org/wizard
After you paste the output, click on the button Analyse my phpinfo() output to proceed
Follow the instructions to the latter after your redirect to the Summary page
After you are done with the installation, type php -v to confirm that Xdebug is activated successfully.
If you already have Xdebug activated, follow these steps get test coverage running;
Type ./vendor/bin/phpunit --coverage-html tests/coverage into the CMD terminal to generate the test coverage
After it is done with running the tests successfully, the coverage report of the tests will be in the project_dir/tests/coverage directory
Inside the project_dir/tests/coverage directory, click on the index.html file to open and view the general report of the project's phpunit test coverage
NB:
I worked in Laravel ^6.0
Tested in Windows 10 environment but can be replicated in other environments
I am having
PHP 7.1.33, Centos 7, PHPUnit 5.7.27
and this works for me
$ yum install gcc
$ pecl install xdebug-2.9.0
Build process completed successfully
Installing '/usr/lib64/php/modules/xdebug.so'
install ok: channel://pecl.php.net/xdebug-2.9.0
configuration option "php_ini" is not set to php.ini location
You should add "zend_extension=/usr/lib64/php/modules/xdebug.so" to php.ini
Proceeding after that
Find position of php.ini file
$ php -i | grep 'Configuration File'
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini
Add Xdebug config
$ vi /etc/php.ini
Add this at the end
zend_extension=/usr/lib64/php/modules/xdebug.so
Check if Xdebug is installed
$ php -ini|grep 'xdebug support'
xdebug support => enabled
I am trying to install Symfony 2.1.3 (latest). I am running composer and installs everything okay. The only error that I get is:
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
handling the post-install-cmd event terminated with an exception
[RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command.
It's being installed under www folder. I am running nginx and followed the composer approach. I read on internet that apache should be run manually not as a service, however I am using nginx instead. Does apache still have any bearing on it? I'm using debian squeeze.
Edit: As per AdrienBrault's suggestion the error was because the timezone was not set in the php.ini. Only with --verbose I could see the warning. Thanks guys.
Apache is not related - PHP is called via command line.
Most likely is the permission in the cache folder: did you check if the user that runs the composer update can actually write the cache folder?
Try to manually run rm -Rf app/cache/dev (for production environment replace dev with prod) and see if you get any permission error.
Also you will get this error if the default.timezone setting is not configured in php when running in CLI. To verify just run
php --info | grep timezone
and check that the setting date.timezone is correctly configured.
On the security side, setting 777 to the folder is not the optimal solution - if you have ACL enabled you could use that to correctly set up the permission for the cache and logs folder. Read more at the Symfony2 official installation page
I had this same issue for a while and after hours of face to brick wall pounding I realized... I have a .gitmodule in my project, and on initial checkout these submodules are NOT initialized and as such are not there for your composer to update, which results in the above error.
Make sure you run the following
git submodule update --init src/Acme/Sadness/Bundle
of course replace src/Acme/Sadness/Bundle with YOUR project namespace.
Hope this helps someone not go through the same pain I just did.
If you have vendor folder already I would remove it and install symfony 2.1.3 again via "composer.phar install". Problem might be coming from outdated version of composer
I had the same problem and I resolve in this way.
execute this on the console
and you should see something like this
$ locate php.ini
/etc/php5/apache2/php.ini
/etc/php5/cli/php.ini
/etc/php5/fpm/php.ini
the first line is probably your php.ini that appear when you do a phpinfo();
the problem is that when you execute composer update this no check the same php.ini
in my case the second line
all my sites work fine but always I had problems not now
after edit the second file and put the same time zone that you set in the first one
run
$ sudo service apache2 reload
and now
$ composer update
I hope that this work for you like work for me
regards
Emiliano