How to fix some popular issues when migrating Magento 1.x systems between dissimilar servers

Moving Magento to a dissimilar server can be messy business!

Unable to log into admin control panel


Moving to a server (or local dev environment) that doesn't have Redis installed

Install Redis! Pretty straightforward on Linux. For a guide to installing Redis on Mac, check this resource: - Or disable Redis if you must by searching for 'redis' in the app/etc/local.xml file.

Getting the error "Function name must be a string" (etc)

If you are migrating from a site that was running PHP version 5.x, try matching that in the new environment for a quick fix. Running on PHP v7+ will bring new problems - it's best to make sure it's running first before dealing with these types of issues. For more info, see


How to stop PHP code output from caching in Drupal 8

But what if we want Drupal 8 caching to be LESS awesome?

Drupal 8 caching is awesome. I get it, and thank you to the community for that awesomeness.

For those of you wondering why your PHP code (probably entered into a block or a node using the PHP Input Filter) will not execute without clearing the cache in-between runs, this information is for you.

Early in Drupal 8 beta we were able to do things like set a block as non-cacheable. But as D8 development progressed that notion went away. Now you can make modules with awesome cache tagging and invalidation. But what you can't do is include PHP code in content using the infamous PHP filter and then have it execute on every page load. Caching won't run the code a second time the user loads your page.


How do I use PHP in Drupal 8?

Drupal Loves PHP, but it loves MVC and OOP now too!

I have to admit, I'm partially writing this post just to see in my analytics reporting how many people are searching for it. But for those that are trying to wedge PHP into Drupal8 and having trouble with it, there is something here for you.

The PHP Filter has been moved out of core and is now a contib module. It was also not working during the release-candidate phase of Drupal 8, but seems to be back on track now. Sometimes people like to do crazy things like create a Panels page at a certain URL and then enable the PHP text filter. If you're slick you might do an include() or an include_once() command and call your scripts from a directory where they can be managed in a code repository and such.

But it's a drag creating a huge Panels page, with all its features, just to call an include() command. And you have to create a Panel for each path (or route) you want to bring into existence. This is pretty heavy for just having a route to call a script.


How to programmatically create a user in Drupal 8

Make user account programmatically with PHP in Drupal 8

No more user_save() and such. What is a nerd to do?

Try the following code, and for those of you programmatically migrating users across from an old site, note that you can set the new user's ID to whatever you want! You don't have to let the system auto-assign the next-available number according to the database. And when you go back to creating users "the normal way" it will resume with the next number after the highest you've assigned. Pretty cool!


Goodbye, Drupal_Goto Command... So How do I Redirect Users?

Drupal_Goto() is dead, long live Drupal_Goto()! Trying to forward your user to a new page with PHP from within Drupal?

There's a years-long discussion on about this, and why we couldn't have our wonderful, precious, easy-like-BASIC-to-remember command to send users on their way, which culminated in statements like this one from "SiliconMind"
To quote "Silicon Mind" from

This is great yet sad example of why Perfect is the enemy of good. In D7 the only thing that was needed in order to alter a redirection, was to implement a hook. A three liner solution. In D8 two files are needed and a bunch of "use" calls that take more lines than the actual implementation itself :( Who the hell will memorize this?


Getting Drupal8 Config and Variable Info with Twig and/or PHP

Drupal8, Symphony2, Twig and PHP - so happy together?

OK, so here we are. Drupal 8 and Twig. No longer can you do things like drupal_get_title() and instead you have to pull variables through a more stringent Model-View-Controller arrangement, specifically Drupal8/Symfony2 and the Twig templating engine. And many Drupal7 commands are gone, so you have to use the object-oriented approach to get information directly in PHP. So here is a progressively-building cheat-sheet of how to pull certain configs and variables using PHP and/or Twig variables specific to Drupal 8:

Get the Drupal8 Site Name and Slogan in PHP



Subscribe to RSS - PHP