Drupal 6 – “The Requested Page Can Not Be Found”

This started popping up on a website I manage today.  There were no new modules, views, etc installed.  A user was just doing thier daily activities of adding new content.

To fix I uploaded a file remove-cache.php to the server and went to it from a browser.

This fixed the issue.

Why Even Non Developers Should Learn to Use Tools Like FireBug

Have you ever gone to a website and then a stupid popup shows up that you can not get rid of? E.g. they don’t give you a close option

firebug_1Annoying, I know.  Well with a tool like FireBug, you can actually remove that popup’s code and it will magically go away!

What  you need to do is

1) Open up FireBug (or whatever) and find the “inspection” tool

Once you click this, you can then hover your mouse over the web site to highlight certain elements.  Do this until you find the annoying box:

When you’ve got this highlighted, look back at the FireBug window and you’ll see a piece of code highlighted.  This code is what actually makes the box (sort of).   It’s actually eaiser if you select the code from FireBug and have it auto highlight the web page:


Then just right click the code and “Delete Element”.  Now the box is gone!


Now lets remove the opaque background blocking your clicks.  This is pretty simple because if you go back to FireBug, click on its inspection tool and then click anywhere on the webpage, you will be clicking on the overlay.

Just right click delete element again.  And now you can view the page and click on the links!!


Have fun with FireBug.  If you ever screw the page up, just refresh 🙂

Restricting Access to All Pages Using Zend 2 and ZfcUser

A new application that I’m working on needs to block all access to every page, except the login page, for unauthenticated users. After setting up Zend 2 with the ZfcUser module, this is a piece of cake. Just update your module/Application/Module.php file with the following code:

$moduleRouteListener = new ModuleRouteListener();

$e->getApplication()->getEventManager()->getSharedManager()->attach('ZendMvcControllerAbstractActionController', 'dispatch', function($e) {

$controller = $e->getTarget();
$sm = $e->getApplication()->getServiceManager();
$auth = $sm->get('zfcuser_auth_service');

if (!$auth->hasIdentity()) {

// If on login / registration page, let them pass
!($e->getRouteMatch()->getParam('controller', 'index') == 'zfcuser' && $e->getRouteMatch()->getParam('action', 'index') == 'login')
&& !($e->getRouteMatch()->getParam('controller', 'index') == 'zfcuser' && $e->getRouteMatch()->getParam('action', 'index') == 'register'))
}, 100);


Wala. All requests, that are not to the login or register pages, are now forwarded to http://yoursite/user/login if a user is not authenticated.

Creating Entities from Existing Database with Doctrine 2 and Zend 2

So I’m upgrading an existing system to use Doctrine, Zend 2 and Dojo and the first step was to setup Doctrine with the existing database. I really didn’t want to have to manually code up all of the Entities so I was looking to see how I could use Doctrines tools to automate this. Here’s how:

(note, I’m using Windows)
1) Create a “tmp” directory in the root of your site

2) From the root of your Zend 2 site, run

php vendordoctrinedoctrine-modulebindoctrine-module orm:convert-mapping —–from-database xml .tmp

3) Once the .dcm.xml files have been generated, you need to tell Doctrine to use the XML driver by updating the vendordoctrinedoctrine-modulebindoctrine-module.php file:

// Add the following three statements above the last two lines
$driverImpl = new DoctrineORMMappingDriverXmlDriver(
/* @var $em DoctrineORMEntityManager */
$em = $application->getServiceManager()->get('doctrine.entitymanager.orm_default');
// end of new code

/* @var $cli SymfonyComponentConsoleApplication */
$cli = $application->getServiceManager()->get('doctrine.cli');

4) Create the php entity files:

php vendordoctrinedoctrine-modulebindoctrine-modules orm:generate-entities ----generate-annotations="true"

Running Windows PowerShell as Any User

So I have a need to login to other PCs through Windows PowerShell from time to time. Just like I need to SSH to other Linux machines. Well that’s fine, I just open up PS and run

Enter-PSSession computer-name

The problem is that I’m usually logged into my PC with an account that does not have permissions to the other PC. If I run PS as a privileged user though, this isn’t a problem. (Yes, I’m sure there’s a way to pass credentials through the Enter-PSSession cmdlet, but that’s not how I solved this.)

One option was to use runas and start PS from the command line

C:WindowsSystem32runas.exe /user:domainusername C:WindowsSystem32WindowsPowerShellv1.0powershell.exe

but then you don’t get the pretty blue PS window and you’re stuck in the command line.

What I ended up having to do was write a PS script to start a PS session under a certain user:

Start-Process powershell.exe -Credential "" -WorkingDirectory "C:"

I called this ps_admin.ps1 and stuck it on my desktop. So now whenever I want to run a PS session as any user, I just click it and get the following popup

From there, I login with any user I want and get the pretty blue PS screen 🙂


A Quest of Becoming a Windows and Linux Server Administrator Guru

So I’ve decided to take it upon myself to get deep down in the dirt and grime of all this server management jazz. At my job, everything has pretty much been streamlined and it’s just basic management which I have staff to handle. Though, I’m always wanting to know how exactly things work when it comes to software, the network, etc; so I’ve decided to setup a home network of the following:

– Linux Database Server
– Linux Web Server
– Linux SMTP Server
– Windows Active Directory (AD) (all Linux / Windows systems will authenticate against)
– Distributed File Share (DFS) with Windows Server 2008 (Possibly 2012 R2 if I can get my hands on it, the college expired my free software subscription)
– Hyper-V fail over cluster (need to purchase another computer or just use my crappy labtop)
– Redundant backup system (not sure on the software I’ll use)
– Security
– Maybe throw in an MS SQL Server database server

By the end of this, I’m probably going to get the system admin certs for Linux and MS. But the main goal is just to gain the knowledge. Anyhow, day one has consisted of:

Setup to CentOS 6.4 VMs one using an external network adapter (live to the world) and the other an internal network adapter (only accessible by the Virtual Machines (VMs) on my computer. The Linux Web Server will use the external network since it needs to be accessible to the world while the Database server will use the internal network. (Better security)

So that’s it for tonight, not really much, but a start. Next steps will be:

1) Upgrade MySQL and setup the my.cnf file to use all 2 GB of RAM on the database server.
2) Upgrade Apache 2 and setup httpd.conf to allow maximum connections and use 2 GB of RAM.
3) Setup a dummy website and have it connect locally to the MySQL database on the other server.

Searching All Tables in a SQL Server Database for a value.

One of my IT guys was trying to write a SQL query to search for a keyword in every table and column of a particular database. There are tons of solutions out there on how to do this and from looking at what he had done so far, I decided to see how quickly I could figure out one. Ended up being about 15 minutes.

CAUTION: Probably not the fastest or most optimized solution, but fairly simple:

USE My_Database;

-- Store results in a local temp table so that. I'm using a
-- local temp table so that I can access it in SP_EXECUTESQL.
tbl nvarchar(max),
col nvarchar(max),
val nvarchar(max)

DECLARE @tbl nvarchar(max);
DECLARE @col nvarchar(max);
DECLARE @q nvarchar(max);
DECLARE @search nvarchar(max) = 'my search key';

-- Create a cursor on all columns in the database
declare c cursor for

-- For each table and column pair, see if the search value exists.
-- Look for the search key in current table column and if found add it to the results.
SET @q = 'INSERT INTO #tmp SELECT ''' + @tbl + ''', ''' + @col + ''', ' + @col + ' FROM ' + @tbl + ' WHERE ' + @col + ' LIKE ''%' + @search + '%'''

-- Get results
SELECT tbl, col, val FROM #tmp

-- Remove local temp table.

Attaching Taxonomy Terms to Existing Drupal Nodes with SQL

A website I work with has a whole bunch of Taxonomy “keywords” that needed to be assigned to existing content. There’s no way I could use third party modules to assign these terms to the existing content because I’m using large data sets (~500,000). Plus, why have the overhead when I just use SQL to directly access manipulate the data.

Below is a SQL statement that will add a taxonomy association to any content that contains the taxonomy keyword:

INSERT INTO term_node
(nid, vid, tid)
SELECT q.nid, q.nid, t.tid
FROM content_type_yourtype q
JOIN term_data t
-- Make sure you only find full words, not partial matches
ON q.field_type_value LIKE CONCAT('% ', t.name, ' %')
-- Don't try to add existing entries
WHERE NOT EXISTS (SELECT n.nid FROM term_node n WHERE n.nid = q.nid AND n.vid = q.nid AND n.tid = t.tid)
-- Clear out blanks
AND t.name != ''
-- This is optional, I need it because my hosting provider times out on 3+ min queries...
AND q.nid >= 200000 AND q.nid < 300000 )

SCRATCH THIS. You need to setup a job to run this, it's too much work on the database:

PHP Script to use:

= $min AND q.nid < $max ");

Bash Script to automate:

for i in {1..150};
do echo "Running Job $i with $j";
php -e tax_update.php $min `expr $min + $limit`;
min=`expr $min + $limit`;

Manually Fixing / Adding Permissions to node_access Table (Drupal 6)

For some reason one of the Drupal sites that I work on for one of my clients wasn’t adding new information to the node_access table for new content being created. We noticed this because some of the results weren’t showing up in searches. (They won’t if the node doesn’t have grant_view checked.) Anyhow, I created the following query to fix this:

* This statement is just used to check how many need to be
* sync'd and can be ignored. It does let you know how many
* nodes your missing though 😉
SELECT count(*) FROM mydatabase.node n where n.nid not in (
select a.nid from mydatabase.node_access a)
and (n.type = 'content_type_a' or n.type = 'content_type_b');

* Create a temp table to insert all missing permissions.
* Note, this isn't required if you only have one access type,
* but since I three, it is necessary. This tables structure
* is just a replica of node_access table.
create temporary table s (
nid int not null,
gid int,
realm varchar(255),
grant_view tinyint(3),
grant_update tinyint(3),
grant_delete tinyint(3)

* I have three node permission groups that I have to change,
* so I will run three insert statements to populate my temp
* table. There is probably a way to combine this into one
* SQL query, but that's another days lesson.
insert into s
/* This group gets view access */
select n.nid, GID_VAL, 'term_access', 1, 0, 0
from mydatabase.node n
where n.nid not in (
select a.nid from mydatabase.node_access a
and (n.type = 'content_type_a' or n.type = 'content_type_b');

insert into s
/* This group gets view access */
select n.nid, GID_VAL, 'term_access', 1, 0, 0

insert into s
/* This group gets view, update and delete access */
select n.nid, GID_VAL, 'term_access', 1, 1, 1

* Finally add all of the missing node permissions into
* the real node_access table!
insert into mydatabase.node_access
(nid, gid, realm, grant_view, grant_update, grant_delete)
select s.nid, s.gid, s.realm, s.grant_view, s.grant_update, s.grant_delete
from s;

* You might wonder why you need the temp table, it's cause the
* where clause would return no rows after that first INSERT.
* If you only have one GID to worry about, you can forget
* the temp table step.

* Confirm you get 0 results. (No missing nodes)
SELECT count(*) FROM mydatabase.node n where n.nid not in (
select a.nid from mydatabase.node_access a)
and (n.type = 'content_type_a' or n.type = 'content_type_b');

* Remove temp.
drop table s;

Yes, you could use just rebuild all of the permissions through Drupal, but when the site has an extremely large node population, this takes hours.