How to make drupal live side by side with WordPress

aRoot drupal and word press

It is more than fitting to start the first engineering blog with our migration of our news and blog from our custom made tools to our drupal web service **BUT*** host it using WordPress.

We will use Drupal as the main CMS and use WordPress for the blog.

Our first attempt is to reduce costs and host it using drupal blog module. We love using drupal for our main site; however, the same is not true for the web site. Our engineers had experience with both Drupal and WordPress but we decided against drupal for simplicity (and to allow any team member to write blog entries). So we moved on and tried to install WordPress as follows:

  • Drupal was already installed under: /var/www/htdocs/drupal
  • I un-tared and extracted WordPress under /var/www/htdocs/drupal/wpblog

Therefore it is under a sub-tree of drupal.

We wanted both WordPress and drupal to live side by side and to be maintained by our web master under the same source control tree. We also wanted (or hoped to share the same media and images) between the two.
The first challenge that we faced was when we browsed to  https://www.enduradata.com/  wpblog.log
After examining apache log errors, we realized that we forgot to modify /var/www/htdocs/drupal/.htaccess. Therefore, I added the following lines to .htaccess:

# WordPress
RewriteCond %{REQUEST_URI} !^wpblog
#end WordPress


This tells drupal to rewrite only urls that do not start with wpblog. Hence what we serve from
/var/www/htdocs/drupal/wpblog will be skipped since our ROOTDOC is /var/www/htdocs/drupal and therefore /var/www/htdocs/drupal/ wpblog will appear as wpblog.
After installing WordPress and an espresso, I modified .htaccess under /var/www/htdocs/drupal/wpblog as follows:


RewriteEngine On
RewriteBase /wpblog/
RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wpblog/index.php [L]

Now we I browse to https://www.enduradata.com/wpblog without any problem and I get the familiar WordPress menus without drupal attempting to boot strap and getting errors such as the following.

  • Failed opening required ‘./wp-blog-header.php’
  • PHP Fatal error: Cannot re-declare timer_start() (previously declared in …)


I then created a menu under drupal and a script to read and echo the content of /wpblog/index.php using the following code snippet:

< ? php
$server = $_SERVER[‘HTTP_HOST’];
$myurl = ‘http://’.$server.’/wpblog/index.php’;
$content=file_get_contents($myurl);
echo $content;
? >

This all worked fine on my test machine until I moved it to production and all hell broke loose because file_get_contents was not enabled on the production box. So I changed to code to the following:

< ? php
$server = $_SERVER[‘HTTP_HOST’];
$myurl = ‘http://’.$server.’/wpblog/index.php’;
$request = drupal_http_request($myurl);
$data = $request->data;
echo $data;
? >

Now I am happy but not as happy as a clam yet. The “good” couple are now united in “php” and doing what they do best: Serve content.

The next major issue is to deal with two sitemap.xml’s (one for drupal and one for wordpress).
Have to go write more code and create value 🙂

–el

 

Update: We have retired Drupal now.

 

/Features

 

How to make drupal live side by side with WordPress was last modified: April 23rd, 2018 by aRoot

Share this Post