magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

developer mode throw an exception, But production mode is good

Open yssource opened this issue 10 years ago • 20 comments

exception 'Magento\Framework\Exception\LocalizedException' with message 'Invalid Document failed to load external entity "urn:magento:framework:Data/etc/argument/types.xsd" Line: 0 Element '{http://www.w3.org/2001/XMLSchema}redefine': Failed to load the document 'urn:magento:framework:Data/etc/argument/types.xsd' for redefinition. Line: 12 ' in /home/jimmy/www/magento2/porto/lib/internal/Magento/Framework/Config/Reader/Filesystem.php:160 Stack trace: #0 /home/jimmy/www/magento2/porto/lib/internal/Magento/Framework/Config/Reader/Filesystem.php(127): Magento\Framework\Config\Reader\Filesystem->_readFiles(Object(Magento\Framework\Config\FileIterator)) #1 /home/jimmy/www/magento2/porto/lib/internal/Magento/Framework/App/ObjectManagerFactory.php(269): Magento\Framework\Config\Reader\Filesystem->read('primary') #2 /home/jimmy/www/magento2/porto/lib/internal/Magento/Framework/App/ObjectManagerFactory.php(137): Magento\Framework\App\ObjectManagerFactory->_loadPrimaryConfig(Object(Magento\Framework\App\Filesystem\DirectoryList), Object(Magento\Framework\Filesystem\DriverPool), Object(Magento\Framework\ObjectManager\Config\Mapper\Dom), 'developer') #3 /home/jimmy/www/magento2/porto/lib/internal/Magento/Framework/App/Bootstrap.php(385): Magento\Framework\App\ObjectManagerFactory->create(Array) #4 /home/jimmy/www/magento2/porto/lib/internal/Magento/Framework/App/Bootstrap.php(232): Magento\Framework\App\Bootstrap->initObjectManager() #5 /home/jimmy/www/magento2/porto/pub/index.php(36): Magento\Framework\App\Bootstrap->createApplication('Magento\\Framewo...') #6 {main} Next exception 'Magento\Framework\Exception\State\InitException' with message 'Invalid Document failed to load external entity "urn:magento:framework:Data/etc/argument/types.xsd" Line: 0 Element '{http://www.w3.org/2001/XMLSchema}redefine': Failed to load the document 'urn:magento:framework:Data/etc/argument/types.xsd' for redefinition. Line: 12 ' in /home/jimmy/www/magento2/porto/lib/internal/Magento/Framework/App/ObjectManagerFactory.php:271 Stack trace: #0 /home/jimmy/www/magento2/porto/lib/internal/Magento/Framework/App/ObjectManagerFactory.php(137): Magento\Framework\App\ObjectManagerFactory->_loadPrimaryConfig(Object(Magento\Framework\App\Filesystem\DirectoryList), Object(Magento\Framework\Filesystem\DriverPool), Object(Magento\Framework\ObjectManager\Config\Mapper\Dom), 'developer') #1 /home/jimmy/www/magento2/porto/lib/internal/Magento/Framework/App/Bootstrap.php(385): Magento\Framework\App\ObjectManagerFactory->create(Array) #2 /home/jimmy/www/magento2/porto/lib/internal/Magento/Framework/App/Bootstrap.php(232): Magento\Framework\App\Bootstrap->initObjectManager() #3 /home/jimmy/www/magento2/porto/pub/index.php(36): Magento\Framework\App\Bootstrap->createApplication('Magento\\Framewo...') #4 {main}

yssource avatar May 23 '16 15:05 yssource

I'm using the nginx.conf.example and magento v2.0.5. This only happens when setting up with "set $MAGE_MODE developer;" And then everything woks well, if change to be "set $MAGE_MODE production;"

yssource avatar May 23 '16 20:05 yssource

Hi, I have same problem with php 7.0.8 on MacOS, any fix or work arround?

ln8711 avatar Jul 15 '16 03:07 ln8711

Hi, I have the same problem with system as below: Magento: v2.1.0 with developer mode. OS: MacOS 10.11.6 Apache: 2.4.23 PHP: 7.0.9 Mysql: 5.7.14

tuancode avatar Aug 01 '16 15:08 tuancode

Same: OS: MacOSX 10.11.5 Apache: 2.4.20 PHP: 7.0.8 MySQL: 5.7.13

rickwhitehead avatar Aug 02 '16 14:08 rickwhitehead

Look like a php bug to me, can you please check to confirm:

http://stackoverflow.com/questions/38683530/libxml-set-external-entity-loader-doesnt-work-in-httpd

ln8711 avatar Aug 02 '16 17:08 ln8711

I can confirm the same test result using libxml_set_external_entity_loader - for php-7.0.6 & php-7.0.8. However; I don't see a bug listed for this on php.net ?? so... please could this be posted asap so that a bug can be confirmed and fixed if necessary?

For those that want a quick (and extremely dirty) fix, to use developer mode, this is what I've done:

Edit Dom.php /Full/path/to/document/root/vendor/magento/framework/Config/Dom.php and comment out the validation exception...

Line 317 - throw $exception; Line 317 + //throw $exception;

Edit config.xsd /Full/path/to/document/root/vendor/magento/framework/ObjectManager/etc/config.xsd and hard-code the full path to types.xsd, replacing the magento urn.

Line 11 - <xs:redefine schemaLocation="urn:magento:framework:Data/etc/argument/types.xsd"> Line 11 + <xs:redefine schemaLocation="/Full/path/to/document/root/vendor/magento/framework/Data/etc/argument/types.xsd">

I've tested swapping between developer/production modes with no errors so far.... OS: MacOSX 10.11.5 Apache: 2.4.20 PHP: 7.0.8 MySQL: 5.7.13

I had hoped that reverting to php-7.0.6 would not suffer this issue but that wasn't my experience.

rickwhitehead avatar Aug 03 '16 13:08 rickwhitehead

Yes, hacking the core is really not the option here, and the issue is not specific to Magento 2. I have submitted the bug here: https://bugs.php.net/bug.php?id=72747

Please add comment if you have one.

ln8711 avatar Aug 03 '16 16:08 ln8711

Rebuid httpd with --enable-mpms-shared=all and then add LoadModule mpm_prefork_module modules/mod_mpm_prefork.so into httpd.conf solved this.

ln8711 avatar Aug 08 '16 08:08 ln8711

hoanglan87 I can confirm the mpm workaround fixed this issue in Magento2. However; I don't understand why compiling http to use MPMs affected libxml functionality? Instead I would have expected the --with-libxml2=PATH option might have been a requirement when configuring http?

rickwhitehead avatar Aug 08 '16 12:08 rickwhitehead

Hi, I don't have enough knowledge to explain this, but mod_php needs mod_mpm_prefork to work with httpd.

You can start here for mode detail: http://php.net/manual/en/faq.installation.php#faq.installation.apache2

ln8711 avatar Aug 08 '16 14:08 ln8711

@tuanvu-se @rickwhitehead can you confirm you build httpd from source or did you use any pre-built version - if yes, please let me know what was it (stock, homebrew etc)?

piotrekkaminski avatar Aug 08 '16 15:08 piotrekkaminski

@tuanvu-se I built entire dev environment from source, e.g.

apr-1.5.1 apr-util-1.5.4 Authen-PAM-0.16 autoconf-2.69 automake-1.15 bzip2-1.0.6 cmake-3.5.2 composer curl-7.49.1 freetype-2.5.5 freetype-2.6.3 git-2.8.3 GraphicsMagick-1.3.23 httpd-2.4.20 icu4c-57_1 imap-2007f imap-2007f jpeg-9b libevent-2.0.22-stable libiconv-1.14 libiodbc-3.52.10 libmcrypt-2.5.8 libpng-1.6.16 libpng-1.6.21 libtool-2.4.6 mcrypt-2.6.8 memcached-1.4.25 mysql-5.7.13 Net-SSLeay-1.74 openssl-1.0.2h packager.tgz PAM-0.31 pcre-8.36 pcre-8.38 php-5.6.23 php-7.0.6 php-7.0.8 postgresql-9.5.3 redis-3.2.0 solr-5.1.0 t1lib-5.1.2 tiff-4.0.6 unixODBC-2.3.4 varnish-4.1.2 xdebug-2.4.0 zendopcache-7.0.4

rickwhitehead avatar Aug 08 '16 15:08 rickwhitehead

Hi @piotrekkaminski, I built httpd, php from source, install mysql from dmg file. In the previous time, I just used httpd built-in MacOS 10.11.6.

tuancode avatar Aug 08 '16 16:08 tuancode

Just out of curiosity, any specific reason to built them from source? We try to test Magento on typical configurations but it's impossible to test on every single configuration.

piotrekkaminski avatar Aug 08 '16 17:08 piotrekkaminski

It's my habit because I've worked with php for a long time. Moreover, I usually build everything from beginning to make sure I can understand obviously it. This is my configurations.

Apache 2.4.23 ./configure --enable-so

PHP 7.0.9

./configure \
  --prefix=/usr/local/php \
  --with-config-file-path=/usr/local/php/etc \
  --with-apxs2=/usr/local/apache/bin/apxs \
  --enable-mbstring \
  --enable-tokenizer \
  --enable-pcntl \
  --enable-zip \
  --enable-opcache \
  --enable-intl \
  --enable-gd-native-ttf \
  --with-mysqli \
  --with-pdo-mysql \
  --with-mcrypt \
  --with-curl \
  --with-pear \
  --with-freetype-dir=/usr/local/opt/freetype \
  --with-jpeg-dir=/usr/local/opt/jpeg \
  --with-gd \
  --with-xsl \
  --with-openssl=/usr/local/opt/openssl

tuancode avatar Aug 09 '16 00:08 tuancode

@tuanvu-se can you please confirm the fix works for you?

ln8711 avatar Aug 09 '16 01:08 ln8711

Hi @hoanglan87, I confirm that the mpm approach perfecly fixed this issue. After taking a deep look inside the problem, I think it is not really a bug. I guess the problem here is some PHP extensions, including libxml, doesn't work with threads. Thus, they break in the mpm worker mode. We can see a note in php manual as below:

Note: To build a multithreaded version of Apache, the target system must support threads. In this case, PHP should also be built with experimental Zend Thread Safety (ZTS). Under this configuration, not all extensions will be available. The recommended setup is to build Apache with the default prefork MPM-Module.

For me, my mistake is I didn't understand that. I might be used option --with-mpm=worker for compiling httpd without recognition. Everything now work perfectly. I learn more from this. Thank you very much.

tuancode avatar Aug 09 '16 17:08 tuancode

Closing this thread as resolved. Thanks everyone!

piotrekkaminski avatar Aug 09 '16 17:08 piotrekkaminski

Hi @piotrekkaminski, and everybody else, I appreciate this issue is now fixed/closed. However, for those [developers/webmasters] who potentially have a requirement to configure Apache differently - has anybody tested compiling libxml2 using the --with-threads option mentioned here: http://xmlsoft.org/threads.html and then re-tested apache either without an mpm module loaded or with --with-mpm=worker defined? This would seem a logical next step in refining Mag2 system requirements for the community?

rickwhitehead avatar Aug 10 '16 09:08 rickwhitehead

If anyone is interested. Tried using apache with compiled libxml2 --with-threads but to no avail.

This issue started when I went from macOs Apache/2.4.18 to homebrew Apache/2.4.23

PascalBrouwers avatar Oct 27 '16 11:10 PascalBrouwers