ElkArte Community

Project Support => General ElkArte discussions => Topic started by: badmonkey on January 27, 2017, 11:10:44 pm

Title: Server migration with exception
Post by: badmonkey on January 27, 2017, 11:10:44 pm
Hi guys.  Me again.   :D

Working on an unmanaged server migration.  The learning curve is strong.  There is likely stupidity mixed with the monkey business.  Anyway, the site (mostly) loads and is (mostly?) operational.  The things that don't work:  can't upload attachments, can't post, can't see formerly attached images, can't access attachment settings in ACP.  That's what I've noticed so far.  There is an exception that pops up in each case:

Code: [Select]
Exception: safe_unserialize: unknown/malformed type: s

This is most likely a configuration error as this was a perfectly operational forum on the old server.  Anyone have ideas?  Thanks!!
Title: Re: Server migration with exception
Post by: ahrasis on January 28, 2017, 03:23:26 am
Server build? Php version?
Title: Re: Server migration with exception
Post by: emanuele on January 28, 2017, 07:49:05 am
hmm...
Interesting one.

The safe_unserialize is a "custom" (actually one coming from the internet) version of the php equivalent unserialize, whose only difference is not wake up serialized classes (avoiding possible attacks).

Try one thing, open /sources/ext/serialize.php, search for:
Code: [Select]
			throw new \Exception('safe_unserialize: unknown/malformed type: '.$type);

and replace it with:
Code: [Select]
			throw new \Exception('safe_unserialize: unknown/malformed type: '.$type . '<br>String: <pre>' . Util::htmlspecialchars($str) . '</pre>');
then, if the error doesn't contain anything sensible, feel free to post it here, otherwise send me a PM. ;)
Title: Re: Server migration with exception
Post by: badmonkey on January 28, 2017, 09:57:31 am
The edit produces 500 errors when trying to access attachment settings.  Still no attachments visible on the forum.  Absolutely nothing in the error log.
Title: Re: Server migration with exception
Post by: badmonkey on January 28, 2017, 10:10:04 am
Oh, if I manually change the currentAttachmentUploadDir in the database, I can access the attachment settings in ACP. 

Obviously this causes a problem when trying to rename the attachment directory to the proper path. 

Code: [Select]
Warning: rename(a:1:{i:1;s:36:"/var/www/clients/client0/web1/web/attachments";},/var/www/clients/client0/web1/web/attachments): No such file or directory
Title: Re: Server migration with exception
Post by: ahrasis on January 28, 2017, 11:19:42 am
Ok. My guess - your server is nginx + debian/ubuntu build (may be + ISPConfig too) as var/www/clients/client0/web1/web format is similar.

I think the cause could be the file and/or the directory ownership. Check that, and if my guess is correct may be do the chown web1:client0 -R (recursively) on that /var/www/clients/client0/web1/web folder.

Extra note, as a practice suggestion, do not use client0 to build a website as it is the admin. Create a reseller and then client(s) under him. Later use any client under the reseller to create a website, instead of the admin or the reseller.

Sorry if this post is or sounds nonsense.
Title: Re: Server migration with exception
Post by: emanuele on January 28, 2017, 12:42:53 pm
Quote from: badmonkey – Oh, if I manually change the currentAttachmentUploadDir in the database, I can access the attachment settings in ACP. 
Yes, my guess was the attachments dir serialized string, but I wanted to see what was the string causing the issue. :)

Quote from: badmonkey – Obviously this causes a problem when trying to rename the attachment directory to the proper path. 

Code: [Select]
Warning: rename(a:1:{i:1;s:36:"/var/www/clients/client0/web1/web/attachments";},/var/www/clients/client0/web1/web/attachments): No such file or directory
Did you by chance run a query to update all the paths at once?
Something like:
Code: [Select]
update elkarte_settings set value = replace(value, '/your/old/path/', '/your/new/path');
Title: Re: Server migration with exception
Post by: badmonkey on January 28, 2017, 01:22:54 pm
Quote from: ahrasis – Ok. My guess - your server is nginx + debian/ubuntu build (may be + ISPConfig too) as var/www/clients/client0/web1/web format is similar.

I think the cause could be the file and/or the directory ownership. Check that, and if my guess is correct may be do the chown web1:client0 -R (recursively) on that /var/www/clients/client0/web1/web folder.

Extra note, as a practice suggestion, do not use client0 to build a website as it is the admin. Create a reseller and then client(s) under him. Later use any client under the reseller to create a website, instead of the admin or the reseller.

Sorry if this post is or sounds nonsense.

I went the ispconfig route on your suggestion.  ;)  It's part of the learning curve too.  haha.  Good suggestion on chown/chmod.  That did occur to me but unfortunately that's not the fix.  Definitely worth checking.  :) 

It's Centos 6.8, nginx, php 5.6 fpm, mariadb. 

Your suggestions make sense.  It will take time for me to wrap my head around what I need to do.  May have to pick your brain from time to time.  ;D  Thanks!!



Quote from: emanuele –
Quote from: badmonkey – Oh, if I manually change the currentAttachmentUploadDir in the database, I can access the attachment settings in ACP. 
Yes, my guess was the attachments dir serialized string, but I wanted to see what was the string causing the issue. :)

Quote from: badmonkey – Obviously this causes a problem when trying to rename the attachment directory to the proper path. 

Code: [Select]
Warning: rename(a:1:{i:1;s:36:"/var/www/clients/client0/web1/web/attachments";},/var/www/clients/client0/web1/web/attachments): No such file or directory
Did you by chance run a query to update all the paths at once?
Something like:
Code: [Select]
update elkarte_settings set value = replace(value, '/your/old/path/', '/your/new/path');

No.  I updated the paths in Settings.php, then went in through phpmyadmin and set everything manually in the settings table, one by one.  Is that a bad method?  It's definitely something wrong with the attachments settings. 

The original files and database still exist on the old server.  I replaced all the files a second time in case there was a corrupt transfer, as well as double checked the attachment directory setting in the database.  It's very strange the manual update will not cause the software to "see" the new directory path. 
Title: Re: Server migration with exception
Post by: vbgamer45 on January 28, 2017, 01:29:32 pm
I think won't work since it looks like it stored in a serialized array
Code: [Select]
a:1:{i:1;s:36:"/var/www/clients/client0/web1/web/attachments";},
Should be
Code: [Select]
a:1:{i:1;s:45:"/var/www/clients/client0/web1/web/attachments";},
36 is the length of the string correct size should be 45
Title: Re: Server migration with exception
Post by: emanuele on January 28, 2017, 03:01:24 pm
Quote from: badmonkey – No.  I updated the paths in Settings.php, then went in through phpmyadmin and set everything manually in the settings table, one by one.  Is that a bad method?
Yep, bad method...
As vbgamer explained the serialized strings break that way.
The "correct" way was to open up the admin panel and fix the paths there. The ACP was not accessible because of the error in the serialized string, but if the string was "fine" (in terms of serialization) and the paths were wrong, you would have been able to access it and fix one by one from there. :)
Title: Re: Server migration with exception
Post by: ahrasis on January 29, 2017, 12:21:44 am
Quote from: badmonkey – I went the ispconfig route on your suggestion.  ;)  It's part of the learning curve too.  haha.  Good suggestion on chown/chmod.  That did occur to me but unfortunately that's not the fix.  Definitely worth checking.  :) 

It's Centos 6.8, nginx, php 5.6 fpm, mariadb. 

Your suggestions make sense.  It will take time for me to wrap my head around what I need to do.  May have to pick your brain from time to time.  ;D  Thanks!!

Good to hear that. Centos is indeed a good choice.

I am personally running 16.04 ubuntu server now with nginx + php 7.0 + ispc 3.1.2 to keep closer to ispc developer settings i.e. based on original debian.

I am currently stuck in restoring 1.1 b 3 site and I think my nginx and optional php5.6.30 config may be the cause for being not properly configured. At first, I feel I want to just rebuild them but other sites are working just fine. So, I choose to rebuild elkarte 1.1 instead.

By the way, how do you edit all the files? Do you have your own ftp like net2ftp installed or you are using other client?

Sorry, if this post is a little bit out of topic. I hope you fix your serialize problem though it shouldn't have occurred since it was running fine in your previous server.
Title: Re: Server migration with exception
Post by: badmonkey on January 29, 2017, 12:22:53 am
Told you guys I knew enough to be dangerous or cause trouble.  ;D 

OK, the database edit fixed the ability view attachments and their ACP settings.  Yay!!  Thanks guys!


Now, there is still an issue with the Attachment Image Resize mod.  Posting is still impossible unless the mod is uninstalled or attachment upload is disabled.  Here's the error from the site error log:

Code: [Select]

FastCGI sent in stderr: "PHP message: PHP Fatal error:  Class 'Attachment_Error_Context' not found in /var/www/clients/client0/web1/web/sources/subs/Air_Resize.subs.php on line 126" while reading response header from upstream,

Title: Re: Server migration with exception
Post by: badmonkey on January 29, 2017, 12:30:50 am
Quote from: ahrasis –
Quote from: badmonkey – I went the ispconfig route on your suggestion.  ;)  It's part of the learning curve too.  haha.  Good suggestion on chown/chmod.  That did occur to me but unfortunately that's not the fix.  Definitely worth checking.  :) 

It's Centos 6.8, nginx, php 5.6 fpm, mariadb. 

Your suggestions make sense.  It will take time for me to wrap my head around what I need to do.  May have to pick your brain from time to time.  ;D  Thanks!!

Good to hear that. Centos is indeed a good choice.

I am personally running 16.04 ubuntu server now with nginx + php 7.0 + ispc 3.1.2 to keep closer to ispc developer settings i.e. based on original debian.

I am currently stuck in restoring 1.1 b 3 site and I think my nginx and optional php5.6.30 config may be the cause for being not properly configured. At first, I feel I want to just rebuild them but other sites are working just fine. So, I choose to rebuild elkarte 1.1 instead.

By the way, how do you edit all the files? Do you have your own ftp like net2ftp installed or you are using other client?

Sorry, if this post is a little bit out of topic. I hope you fix your serialize problem though it shouldn't have occurred since it was running fine in your previous server.

Good luck with restoration.  Basically sums up migration too lol!

For file editing I use WinSCP as the client with Notepad++ chained in as the actual editor.  There are some quirks but it works nicely overall.  WinSCP works well enough for single file transfers.  Or for maybe a handful.  For large batch transfers, it's back to Filezilla since it can perform 10 simultaneous file transfers.  Suggestions are welcome!!  ;)
Title: Re: Server migration with exception
Post by: badmonkey on February 03, 2017, 10:03:28 am
Hey guys!  I moved another site to the new server.  Still have the two larger sites to move as well.  Also still trying to learn how to make it a smooth transition. 

On eman's suggestion, the first move was to try to correct the attachment settings in the ACP.  The problem is when the folder structure is completely different, an error is encountered and that part of the ACP is unreachable.  So ACP correction is impossible unless I did it wrong again.  Either way, this makes migration at best difficult.  It may be something you guys want to address?  The workaround is to set the attachment directory in the settings table to:

Code: [Select]
a:1:{i:1;s:0:"";}

Then you can set the correct path in the ACP.

Another noted behavior is the inability to post from the full Reply page if the attachment settings are incorrect.  It produces an error message stating attachments cannot be uploaded even if there are none to be uploaded.  Not sure that's a good behavior as something as simple as incorrect folder permissions or a typo can make the forum useless as well as impossible to correct within the site itself.  The workaround is to manually disable attachments in the settings table. 
Title: Re: Server migration with exception
Post by: emanuele on February 03, 2017, 04:55:46 pm
Yep, I guess there is something to take care of.
In theory, to make the transition smooth, there is repair settings, but TBH, I don't remember if I pushed the fix for the multiple attachments directories... :-[
Title: Re: Server migration with exception
Post by: badmonkey on February 03, 2017, 07:39:34 pm
It's all part of the learning curve for us all.  Many, many thanks to this community.  People here are willing to help as well as listen.

Speaking of thanks, I must give credit to @vbgamer45  for the info he posted.  It provided just what I needed to understand what was happening with that setting so it could be applied to multiple attachment directories. 

One other item worth mentioning: on the small forums, this method corrected the paths just fine.  On the mid size forum, 500 errors kept popping up.  Huh?  Ah yeah, php memory limit.  Increasing it to 128M didn't work.  I went for broke, set it for 1G, and got the job done.  Apparently it takes a lot of memory to rename the attachment filenames in the database.  That forum has around 25,000 attachments.  Tonight we will find out how that works on the Big Girl with over 90,000 attachments. 

 :D
Title: Re: Server migration with exception
Post by: ahrasis on February 03, 2017, 09:41:56 pm
Now I remember that repair_settings will indeed detect that attachments path an offer a proper correction.

By the way, for me, after running an nginx server as well, I think I am more comfortable with the previous apache2 setup as it almost didn't shows all that errors (500, 404, 403 etc) at all. But reverting back to it may be a hassle (small though) and nginx seems faster and very good in handling concurrent session.

Meditate on this, I will. :P
Title: Re: Server migration with exception
Post by: badmonkey on February 03, 2017, 11:16:28 pm
Nginx can be finicky.  On the plus side, it works oh so well.  It's fast.  It's also easy/intuitive to configure.  Much simpler than Apache, at least for me.  Resource consumption is nearly nothing too.  It does have it's downsides as you point out.  Go with what you feel best!


One of the hurdles here is I'm moving large forums while simultaneously configuring and learning ispconfig.  It hasn't been easy!  lol  Hopefully some of it being in print here will help someone in the future.  :)

Thanks for your help everyone!  Hope you have a great weekend.   8)
Title: Re: Server migration with exception
Post by: ahrasis on February 04, 2017, 02:29:29 am
I agree that nginx is kind of simpler if compared to apache. Anyway, I haven't decided on reverting back to apache but just a thought that crossed my mind.

I track my problem with nginx to the issue of cache / caching as well as vhost settings. Now testing with higher amount of memory limit for xcache and modifying some of my vhost.

I also manage to work with email system for all domain and now configuring a fax via hylafax.

Will see about it in a week or two more.
Title: Re: Server migration with exception
Post by: emanuele on February 04, 2017, 03:57:34 pm
Quote from: badmonkey – One other item worth mentioning: on the small forums, this method corrected the paths just fine.  On the mid size forum, 500 errors kept popping up.  Huh?  Ah yeah, php memory limit.  Increasing it to 128M didn't work.  I went for broke, set it for 1G, and got the job done.  Apparently it takes a lot of memory to rename the attachment filenames in the database.  That forum has around 25,000 attachments.  Tonight we will find out how that works on the Big Girl with over 90,000 attachments. 
Why do you need to rename the attachments as part of the migration? I may have missed a bit here.
Title: Re: Server migration with exception
Post by: badmonkey on February 04, 2017, 05:35:07 pm
Sorry, that should have been directories.  The process handling the move ran php OOM.