Monday, March 1, 2010

Remote command line for Drupal running on Windows Server 2008

Recently I set up a remote command line for Drupal. It has been available since the release of Drush. I have to work with many Drupal sites and I am a command line addict, because I think it’s more efficient than any other technique. Drush seems to the best solution for me to manage multiple sites easily.

This specific case covers Drupal 6.x running on Windows Server 2008 and IIS 7. This is not the “regular” platform for Drupal. It is originally designed to run on Apache, *nix environment - but if you have to integrate with Windows systems, in some cases it’s better to run on Win/IIS environment. For the starting scenario we have a fully installed Windows Server 2008 with IIS 7, PHP installed and one or more Drupal 6.x systems deployed.

If you are new to Windows 2008, there could be many issues installing these prerequisites. I recommend to use the Microsoft Web Platform Installer. You can install PHP and more by a few clicks of the mouse.

Installing Drush:

  1. Download the package from here.
  2. Unpack it to the desired work folder (I used the following path: C:\utils\drush)
  3. If the installation path is not added to your path, add it: right click on My Computer and select Properties. On the window select Advanced Properties then Environment Variables. Find the PATH system variable, and add your path to the end of the string (separated with a semicolon). PHP root must be on the path also (Web Platform Installer places it to Program Files (x86)\PHP on a 64 bit system, like mine).

image

After the installation I made some adjustments.

  1. Changed drush.bat to use a customized php.ini located in c:\utils\drush.
    To do this, I added the php calling parameter –cC:\utils\drush

    @REM See http://drupal.org/node/506448 for more information. @php.exe -cC:\utils\drush\ "%~dp0drush.php" %1 %2 %3 %4 %5 %6 %7 %8 %9
  2. Copied the php.ini from the php installation path to c:\utils\drush and changed some parameters. For example:

    error_log = d:\logs\drush_php_error.log – Use different error log file
    max_execution_time = 3000 – Give it time to run…
    max_input_time = 3000 
    memory_limit = 512M – A great pool    

Let’s see if it’s working. Open command line. Change directory to a Drupal root, and issue the following command: drush status . If it works, it prints something like this:

image

Well done, drush is working fine.

Issuing commands from any folder

Drush is based on the great idea of working with the Drupal installation that is in the current directory. It would however be better for me, if I could issue commands fast from anywhere. So I figured out that I can create a little script for each site:

@echo off set ORIGINALPATH=%cd% cd /D d:\wwwroot\testsite\httpdocs call drush.bat %* cd /D "%ORIGINALPATH%"

This simple cmd script changes the current directory to the required Drupal site, executes drush.bat with all paramters and restores to the current directory to the original.

So, now if I issue testsite status anywhere, I will get the same output as is on the previous screenshot.

Making it remote

It’s great to work on the remote system with Remote Desktop utility, but sometimes it is more trouble that it’s worth. It would be better if I could issue these commands on my local workstation’s command line.

Note: The server in the example is not on our local network. It accessed via a VPN connection. To use the following method, you have to be on local network with the server or use some kind of VPN.

For the remote access we have to configure Windows Remote Management. This is Microsoft’s implementation of the WS-Management protocol. If it’s configured for the first time and you do not need customization, just issue the following command: winrm quickconfig. After it finishes, the Windows Remote Management service starts and will be configured to start as necessary from now on. It also sets the firewall exception as needed and creates the default listeners. The output will be something like this:

WinRM is not set up to allow remote access to this machine for management. The following changes must be made: Create a WinRM listener on HTTP://* to accept WS-Man requests to any IP on this machine. Enable the WinRM firewall exception. Make these changes [y/n]? y WinRM has been updated for remote management. Created a WinRM listener on HTTP://* to accept WS-Man requests to any IP on this machine. WinRM firewall exception enabled.

To test if the WinRM service running fine, I issued the following command (on the server): winrs –r:http://localhost testsite status

image

Great! We have the same output. The following step was to set up the trusted hosts on the server. The system allows to set up single hosts or networks. So, I added the VPN client’s IP range to the Trusted Hosts:

imageWe have to add our server to the trusted hosts on the client workstation as well (Windows 7):

image

After this we can issue commands from the local computer in the following form: winrs –r:servername command params. This form is not too user friendly… To make it more efficient we can create “shortcut” commands for the websites. The following is for my testsite:

@winrs -r:http://10.20.0.10 testsite %*

Finally, we have a working command line to Drupal. I can easily issue commands to my remote sites. Some examples:

Put the site to maintenance mode:

image

Download a new module:

image

And more…

There are many possibilities to expand these functions to get more and more easy to use remote management functions. Drush saves me a lot of time. Thanks for the developer Moshe Weitzman! It’s great!

References:

Drupal – Open Source CMS

Drush – Drupal Shell many thanks goes to Moshe Weitzman

Microsoft Web Platform Installer – Application to install required components, and complete website engines

Windows Remote Management

Saturday, July 25, 2009

Plesk 9.2 and files starting with dot

After the default setup of Plesk 9.2 for Unix, the default FTP config hides the files starting with dot. To resolve this problem with the latest versions of ProFTPd, you have to add the following line to the /etc/proftpd.conf:

ListOptions “-a”

More information on this directive

Thursday, July 23, 2009

Plesk 9.2 and the postmaster

My company uses Plesk to provide hosting services to our Clients. We faced with the problem of creating the default domain e-mail addresses for all domains. I mean postmaster@domain.com, root@domain.com, and abuse@domain.com.

To create these e-mail addresses the easiest way is to create a script which copies the .qmail-postmaster file into each domain’s mailnames (/var/qmlail/mailnames) folder. So I wrote the following little script to do this updated, and I called it from crontab periodically.

#!/bin/bash for domain in `ls /var/qmail/mailnames/ | xargs`; do if [ ! -f "/var/qmail/mailnames/$domain/.qmail-postmaster" ] then echo "Updating postmaster account for $domain domain" cp /var/qmail/alias/.qmail-postmaster /var/qmail/mailnames/$domain/.qmail-root cp /var/qmail/alias/.qmail-postmaster /var/qmail/mailnames/$domain/.qmail-abuse cp /var/qmail/alias/.qmail-postmaster /var/qmail/mailnames/$domain/.qmail-postmaster fi done

But it not works with the Domain Aliases (as Plesk calls them). These are the virtual domains in the Qmail’s language. So I will try to dig how it works fine with these virtual ones.

After a couple of days…

I found the answer for my question. I wrote a script which queries the Plesk’s database for domains with aliases and creates a symbolic link to the domain’s folder in the mailnames QMail folder.

Friday, May 1, 2009

How to delete Team Project on TFS 2008

I have experienced some issue while deleting Team Projects.

Because we had too many obsolete projects on our Team Foundation Server, we decided to delete them. First I backed up the whole database. For the detailed instruction, read Microsoft’s paper: How to: Back Up a Team Foundation Server

To delete a Team Project, you have to use the TFSDeleteProject command from the Visual Studio 2008 Command Prompt. This operation cannot be done from the Team Explorer.

Preparation

Before doing this operation we have to clarify what will be the state of the branched code. I have found the answer on the following Microsoft site: Using TFSDeleteProject to Delete Projects on Team Foundation Server. The FAQ section’s first question clarifies this issue: only those source control items will be deleted whose in the deleted Team Project. The deletion not will operate outside of the given Team Project. I tried it, and it really works in this way. Note if you delete the parent of branch it will be orphaned. The work items (bugs, and more) will be deleted too.

The TFSDeleteProject command cannot be executed without all required security permission.

You have to be in the Team Project’s Administrators. To set it go to Team Explorer in Visual Studio. Right click on the team project, and select Team Project Settings > Group Membership…

image

Select the Project Administrators group, and press Properties button.

image

Add your user to the list.

You must be the SharePoint site’s Administrator.

Go to the SharePoint Central Administration Site.

image

Select the Application tab and then the Site collections administrators.

image

Select the Site Collection associated with the given Team Project and set the Primary site collection administrator to your user.

The execution

After the preparation you can issue the following command:

> TFDeleteProject /server:YOURSERVER TEMPPROJECT

The command asks for your confirmation:

Warning: Deleting a team project is an irrecoverable operation. All version control, work item tracking and Team Foundation build data will be destroyed from the system. The only way to recover this data is by restoring a stored backup of the databases. Are you sure you want to delete the team project and all of its data (Y/N)?y

If everything went good you will see the following:

Deleting from Build ...
Done
Deleting from Work Item Tracking ...
Done
Deleting from Version Control ...
Done
Deleting Report Server files ...
Done
Deleting SharePoint site ...
Done
Deleting from Team Foundation Core ...
Done

After the deletion the Team Project disappears immediately, but the Version Control items will be only flagged as they can be deleted. The Team Foundation Server will delete these items at next midnight. You can hurry this by executing the job manually. You can read here how to do this: http://msdn.microsoft.com/en-us/library/dd206696.aspx#jobhistory

Thursday, February 5, 2009

VS.Php 2.6 available!

After a long development period the new version of VS.Php (2.6) officially released by Jcx.Software! This is my favorite tool for PHP editing. I think it's a great combination of two technologies which are so far away from each other. (Visual Studio 2008 and PHP)

So I downloaded the new version today. I own the 2.x for Visual Studio 2008 licence. After the installation, the system asked me to enter the serial number. It doesn't accept the old serial number. Pardon. To be exact: it accepts the old serial, but asks to go to the website and request a new one. Prepare yourself: you have to find the order number...

The new serial is came instantly after submitted my request. Fine. I will try the new version in the next weeks. I'll share my experience.

What's new in 2.6

(from the developer's site)

Major Changes

  • Project-wide intellisense support
  • Drag and drop files in solution view
  • IIS7 integration for creating, debugging PHP applications on IIS7
  • Handle very large projects with ease (10000+ files)

Minor Changes

  • Improved bracket matching support with custom background color
  • Zend Framework 1.7.3
  • Intellisense has two tabs, one for frequently used items and one for project wide items
  • Add more flexibility in customizing color coding of PHP tokens
  • Numerous performance improvements
  • Fix issues with updater on x64 systems
  • Use PHP CGI for built-in Apache for increased stability
  • Add MS SQL Server PHP module to the list of available modules for intellisense and built-in preview engine
  • Include PHP 5.2.6 and PHP 4.4.9
  • Include $argv and $argc for globals
  • Show disconnected overlay icon when there is no local copy of the file.
  • Speed up the solution refresh command, in particular which very large projects.
  • Allow remote server project wizard to continue even if the wizard fails to run phpinfo on the remote server to collect server information.
  • Many bug fixes!

 

More information: http://www.jcxsoftware.com/jcx/home

Tuesday, December 2, 2008

New Project

I have started a new project a few days ago. It's called "Plesk Localization".

I would like to maintain this project to provide the missing language packs for Parallels Plesk Control Panel. This software is used by webhosting companies. I think this is the best control panel.

Parallels stopped the language support for many languages after the 8.1 version. But they provide localization kits to those who want to create custom translations. Like me...

To read more info on my new project check these links:

Project Home: http://code.google.com/p/plesklocalization/

Tuesday, October 14, 2008

Mono 2.0

I was very excited when I heard that Mono 2.0 has been released! It supports C# 3.0 and LINQ! It's great! I will try to port some of my applications to Linux.

They promise that we can continue to develop on Windows platform, the binaries created by Visual Studio are binary compatible with Mono, these files can be used on the Linux server.

I will try it, and share my experience here.