drupal wet on windows server 2008 r2 with iis 7...postgresql or mssql), web servers (apache, nginx...
TRANSCRIPT
Drupal WET on Windows Server 2008 R2 with IIS7.5
Installation Guide
By: OpenConcept Consulting Inc. http://openconcept.cafor Parks Canada
Author: Mike Gifford <[email protected]>Contributors: Rob Johnston (Action Plan), Mike Mallett
<[email protected]>, Denis Fung (Parks Canada),Editor: Lee Hunter http://streamoflight.com
Abstract
This document describes setting up the Drupal WET Variant within a Windows Serverenvironment. Security, configuration and performance issues are addressed.
CopyrightThis document is licensed under the Open Government Licence as specified inhttp://www.data.gc.ca/eng/opengovernmentlicencecanada
This is a Living Document. Please contribute enhancements1
Table of ContentsIntroductionHardware and Software RequirementsSoftware SummarySteps for Configuration
Step 1: Install PHP/IIS/MSSQLStep 2: Set Up the Drupal EnvironmentStep 3: Install Acquia Drupal 7Step 4: Preparing WETStep 5: Add a Web SiteStep 6: Configure settings.phpStep 7: Set up the MSSQL Database
Create a blank databaseCreate a new login and map it to the databaseNote there are a few known issues with MSSQL:
Step 8: Installing WETAdditional Notes
Migrating an Existing WET InstanceOther Server Configs: CronInstall Drush (Strongly recommended)Git, Memcache (Optional)
Other ConfigurationDisabling execution of PHP in useruploaded fileshttps://groups.drupal.org/node/226059Install PHP APC (optional)Check SMTP settingsInstall WinCacheDrupal Modules for Windows environments
Videos and PresentationsRelated LinksRelated BooksTroubleshooting
Fatal error: Undefined class constant 'SQLSRV_ATTR_DIRECT_QUERY'Troubleshooting File Permissions
This is a Living Document. Please contribute enhancements2
IntroductionDrupal is a leading content management system, widely used by governments around the world,including the Government of Canada, who are looking to meet increasing citizen demands forwebbased services, to address challenges with accessibility and mobile computing, and to doso with ever smaller budgets.
Drupal requires PHP but can be run with a variety of database servers (MySQL, SQLite,PostgreSQL or MSSQL), web servers (Apache, Nginx & IIS) and operating systems (Linux,UNIX, Windows and MacOS). This guide is designed to help a Windows System Administratorset up Drupal in their environment.
At the moment, the best practice for installing Drupal on a Windows server is to target IIS andMSSQL.
As with the majority of Internet tools, Drupal primarily targets the open source LAMP stack, whichmeans that there is relatively less community support and documentation for a Windowsbasedstack. This means that installing Drupal on Windows is not considered a best practice. However,if there is no alternative for your department, Drupal can be deployed successfully on Windows.
Please note that testing for this document was done on an Amazon EC2 Web Server. Theremay be substantial differences between an EC2 Windows 2008 instance and other virtualizedserver environments. This document should also apply to physical servers with no virtualization.
Hardware and Software Requirements
If you do not have physical access to the server, you will need a remote desktop tool in order tobe able to administer the server.
Windows Server 2008 RC28G RAM (recommended)100G+ HD (10k RPM recommended)
This is a Living Document. Please contribute enhancements3
Software Summary
Microsoft’s Web Platform Installer version 4.6 or greater IIS IIS Manager SQL Server PHP Acquia Drupal (Recommended) WinCache URL Rewrite module
GNUwin32 (Recommended) Unzipping tool Text editor Drupal WxTDrupal Distribution Git (recommended) Drush (recommended) Couchbase (or memcache)
This is a Living Document. Please contribute enhancements4
Steps for Configuration
Step 1: Install PHP/IIS/MSSQL
The following procedure installs the IIS server in a configuration recommended for Drupal(including the URLRewrite module and PHP SQL Server Driver 2.0).
Before you begin, ensure that your Windows server installation is up to date and that you candownload files from the Internet. You also may need to enable downloads.
1. From the web server, install the Web Platform Installer by navigating in IE to thisWindows webpage and clicking on the Launch Web Platform Installer link.
2. This will download a program that you will need to run as the administrator to completethe installation process.
3. Choose Windows Azure SDK for PHP, PowerShell & Crossplatform Command LineTools and then Finish IIS, PHP, MSSQL Installation.
More information on installing Drupal with the Windows Platform Installer is available fromhttps://drupal.org/node/1130898
It is beneficial to install the GNUwin32 tools so that you can have additional control at thecommand line.
This is a Living Document. Please contribute enhancements5
Step 2: Set Up the Drupal EnvironmentWith PHP / MSSQL installed you can now set up the Acquia Drupal 7 environment with the WebPlatform Installer to ensure that Drupalspecific elements are applied. Drupal 7 now ships withan IIS web.config file, making this easier.
1. In your browser, visit http://www.microsoft.com/web/drupal, choose Acquia Drupal andfollow the online instructions.The Acquia installer provides you with a database user/password that is displayed at thebottom of the final screen.
2. Record the paths and the login credentials3. Finish the installation and launch the site.
This profile uses MSSQL, but you may also decide to deviate from this later and install Drupal oneither MySQL or PostgreSQL. This script modifies your php.ini file to ensure that each page isgiven sufficient memory to load.
This is a Living Document. Please contribute enhancements6
Step 3: Install Acquia Drupal 7Your Drupal code & database is now in place, but you will need to go through the process ofinstalling Acquia’s Drupal 7. Ultimately this is a test environment to verify that your server isproperly configured for Drupal core. This will also generate some files and folders that you cancopy later into your Drupal WET installation. First let’s complete the installation process to verifythat Drupal core is working properly.
The installer above should load IE with http://localhost/acquiadrupal/install.php which will thenwalk through a standard Drupal 7 installation:
There are a number of useful videos from MSDN where you can learn more about using PHPwithin Windows. One steps through how to deploy Drupal with the Web Platform Installer.
http://channel9.msdn.com/Series/PHPatScaleontheMicrosoftPlatform
This should give you a fully operational Drupal install. Checkhttp://localhost/acquiadrupal/admin/reports/status for configuration errors.
This is a Living Document. Please contribute enhancements7
If there aren’t errors, you will be able to leverage these two directories for your new WETkit installand in Step 4:
C:/inetpub/wwwroot/acquiadrupal/includes/database/sqlsrv/C:/inetpub/wwwroot/acquiadrupal/sites/default/
At this point you should verify that “clean URLs” (i.e. URLs that do not contain PHP syntax suchas ?q=) are generated for your site. If not, consult the Clean URL documentation on Drupal.orgor Chris Larson’s blog.
This is a Living Document. Please contribute enhancements8
Step 4: Preparing WET
Download the Web Experience Toolkit from Drupal.org, decompress the file, and move theresulting folder to
C:\inetpub\wwwroot\wetkit
Copy the sqlsrv directory found inside the Acquia installation fromC:\inetpub\wwwroot\acquiadrupal\includes\databases\sqlsrv
to the Wetkit equivalent atC:\inetpub\wwwroot\wetkit\includes\databases\sqlsrv
Copy over the default sites folder from:C:/inetpub/wwwroot/acquiadrupal/sites/default/
to the Wetkit equivalent at:C:/inetpub/wwwroot/wetkit/sites/default/
You will need to edit the settings.php folder in this directory in Step 6.
A tool such as 7Zip or WinZip may be required to decompress the WETkit Drupal distribution.
This is a Living Document. Please contribute enhancements9
Step 5: Add a Web Site1. Open IIS Manager2. Right click on Sites, select Add Web Site and follow the prompts.
Alternatively, you can add a site from the command prompt:
%systemroot%\system32\inetsrv\APPCMD add site /name:MyNewSite/bindings:"http/*:81:" /physicalPath:"C:\MyNewSite"
More information on Appcmd.exe is available from:http://technet.microsoft.com/enus/library/cc772200(v=ws.10).aspx
There is more information on configuring IIS using the IIS Manager here:http://www.trainsignal.com/blog/windowsserver2008iis7
This is a Living Document. Please contribute enhancements10
Step 6: Configure settings.php
Edit the default settings directory provided by Acquia in the new wetkit directory:C:\inetpub\wwwroot\wetkit\sites\default\settings.php
Edit the settings.php file to specify the database configuration, the following is based on theAcquia Drupal 7 settings.php file:
$databases = array( 'default' => array( 'default' => array ('database' =>'acquiadrupal7665', 'username' => 'ad7user665', 'password' => 'K#|!]ctdV5aj', 'host' =>'.\SQLExpress', 'driver' => 'sqlsrv', 'prefix' => '' ) ) );
Note that you will want to have a unique database, username & password for each Drupal site.
In the settings.php file uncomment this line:$conf['allow_authorize_operations'] = FALSE;
To specify the temp directory, add this line:$conf['file_temporary_path'] = 'C:\inetpub\temp';
Give IIS_User write permissions to C:\inetpub\temp. Drupal often needs access to a temporaryfolder like this to store uploaded files or session information.
It is a best practice to set a salt outside of the document root for security reasons. Drupal willfunction if you leave it blank, but adding a line like this (with a random string in the salt.txt file) willbe more secure:
$drupal_hash_salt = file_get_contents('C:\inetpub\salt.txt');
This is a Living Document. Please contribute enhancements11
Step 7: Set up the MSSQL Database
You will want to set up an empty MSSQL database for each instance of Drupal.
The database must use a unicode caseinsensitive collation (e.g.SQL_Latin1_General_CP1_CI_AI).
Create a blank database
1. Open Microsoft SQL Management Studio.2. Connect to the database engine using database administrator credentials.3. Expand the server node.4. Right click Databases and select New Database.5. Enter a database name and click OK..
Create a new login and map it to the database
1. In Object Explorer, expand the folder of the server instance in which you want to createthe new login.
2. Rightclick the Security folder, point to New, and select Login.3. In the Login – New dialog box, on the General page, enter the name of a user in the Login
name box.4. Select SQL Server authentication.5. In the Password box, enter a password for the new user. Enter that password again into
the Confirm Password box. Do not enforce password reset.6. Select User Mapping on the left, then select the database created in the previous step.
Select db_owner at the bottom.
Note there are a few known issues with MSSQL:
https://github.com/wetboew/wetboewdrupal/issues/946 https://github.com/wetboew/wetboewdrupal/issues/379#issuecomment870503
0
Step 8: Installing WET
This is a Living Document. Please contribute enhancements12
In a web browser navigate to http://locahost/wetkit/install.php
Once you are sure that your vanilla instance of WET is running properly on your serverenvironment then you should be confident that your server will be able to run your department’slive web server. You can develop your WET site locally and then transfer your content from yourdevelopment site to your production Windows server.
If you have an external IP address pointed at this server, you can also navigate to it directly andverify that it is working at this time. If you want to compare the install with a generic installation,you can quickly launch a sandbox to compare online:
http://www.simplytest.me/project/wetkit
Note: You may need to increase your PHP memory_limit to 512M and the max_execution_timeto 300 for the installation.
This is a Living Document. Please contribute enhancements13
Additional Notes
Migrating an Existing WET InstanceIf you are migrating an existing installation of WET you can simply copy over the Drupal rootfilesystem and database. Make sure to clear cache after doing so.
drush @sites cc all
Login and ensure that your site is behaving as expected. Check the logs & Status report pagesto verify that all is behaving properly.
Other Server Configs: CronCron is a general purpose Linux program to run regularly occurring events. It’s just a daemon toexecute scheduled commands.There are a number of options documented here for setting up cron in Windows(https://drupal.org/node/31506), but this worked well for me:Run cmd.exe as Administrator, then enter the command:
C:\Windows\system32>schtasks /create /sc HOURLY /tn DevCron /tr "cmd.exe 'curl silentcompressed http://[[hostname]]/cron.php?cron_key=EXAMPLE_RANDOM_KEY'" /ru SYSTEM
Install Drush (Strongly recommended)Use the Drush installer to set up Drush 6.x.
http://www.drush.org/drush_windows_installer
This is a Living Document. Please contribute enhancements14
Navigate to the Drupal root directory and test to see that Drush works and which version you arerunning by running drush version.
Run C:\Program Files (x86)\Drush\DrushEnv.bat after installation to add drush.exeto the PATH
You may need to set the system PATHS by going to Control Panel > System > Advanced System
Settings > Environment Variables
Git, Memcache (Optional)Most Drupal developers use Git for version control. You can install Git from:http://gitscm.com/download/winYou can keep the defaults except the installation path and select "Run Git from the WindowsCommand Prompt"
Drupal can cache database queries and other chunks in Memcache or Couchbase. Both can beinstalled, but Couchbase seems to be better supported for Windows:
This is a Living Document. Please contribute enhancements15
Agree to increasing the number of ephemeral ports (MaxUserPort). Full installation instructionsare available.
If you’re using Windows and can’t move to Git then you’re probably using Team FoundationServer for source control. There's a TFS plugin available from Microsoft for Eclipse but if onewishes to use another IDE then it must go through a subversion bridge.
This is a Living Document. Please contribute enhancements16
Other Configuration
Disabling execution of PHP in user-uploaded files
https://groups.drupal.org/node/226059Web.config content to be put in the "files" directory:
<configuration> <system.webServer>
<handlers><clear /><addname="StaticFile"path="* "verb="* "modules="StaticFileModule"resourceType="Either"requireAccess="Read"/></handlers>
</system.webServer></configuration>
Install PHP APC (optional)The Alternative PHP Cache (APC) provides a free, open, and robust framework for caching andoptimizing PHP intermediate code.http://docs.moodle.org/22/en/Installing_APC_in_Windows
Check SMTP settingshttps://groups.drupal.org/node/241213#comment781593
Install WinCachehttp://ruslany.net/2011/04/wincacheandwordpresspluginupgradeproblem/
Drupal Modules for Windows environments LDAP Driver for SQL Server
Videos and Presentations Australian Gov http://www.youtube.com/watch?v=XeNke3KI9mc&feature=youtu.be Install PHP, MySQL & Drupal on Windows Server 2008
This is a Living Document. Please contribute enhancements17
http://www.youtube.com/watch?v=tSRV87ivUg Windows Loves Drupal http://www.slideshare.net/AcquiaInc/windowslovesdrupal
Related Links Drupal.org Wiki on Installing Drupal on Windows Drupal Groups Discussion on Drupal on Windows IISAID: Your Authoritative and Independent IIS Resource Install Drupal on IIS from IIS.net CSE COTS Security Guidance for Windows CSE Windows Server 2003 Recommended Baseline Security Brian Swan’s Blog on Deploying Drupal at Scale on the Microsoft Platform Micah Webner’s Blog on Drupal 7 on Microsoft Windows Server Bill Speers’ blog on Installing Drupal on IIS7 / Server 2008 R2 Amazon EC2 Running Microsoft Windows Server & SQL Server Stack Exchange Question on Applying a Security Baseline for Windows 2008
Related Books Integrating PHP With Windows Windows Server 2008: Security Resource Kit
Troubleshooting
Fatal error: Undefined class constant 'SQLSRV_ATTR_DIRECT_QUERY'Run a PHP file that contains the code <?php phpinfo(); ?> and check the location of the LoadedConfiguration File. Make sure you are working on the right version of PHP. Next check to see ifthe SQLSRV PDO driver is installed
C:\Program Files (x86)\PHP\v5.3\extCheck that Microsoft Drivers 3.0 for PHP for SQL Server are downloaded and installed properlyto the right directory. You may have PHP installed in more than one place and if so you need tospecify the right directory.Look to see if the PHP PDO modules are available by typing at the command prompt:
php mThe PHP directive "extension_dir" should contain an absolute file path.The 3.x version of the PHP drivers can be downloaded from:
https://www.microsoft.com/enca/download/details.aspx?id=20098Install and restart PHP from the IIS Manager.
Troubleshooting File PermissionsA common point of difficulties is ensuring that you have proper file permissions. With icacls you
This is a Living Document. Please contribute enhancements18
can grant access to Drupal’s settings.php and the files directory.
Set permissions using something like:cd C:\inetpub\wwwroot
icacls sites\default\settings.php /grant BUILTIN\IIS_IUSRS:(W)
icacls sites\default\files /grant BUILTIN\IIS_IUSRS:(W)
icacls sites\default /grant IIS_IUSRS:(OI)(CI)(RX,W)
or
icacls sites\default\settings.php /grant BUILTIN\IIS_IUSRS:(M)
icacls sites\default\settings.php /reset
md sites\default\files
icacls sites\default\files /grant BUILTIN\IIS_IUSRS:(OI)(CI)(M)
Notice that in the file properties for the sites/default directory, that the IUSR user has writepermissions.
Ensure that write permission on settings.php is removed after the installation is complete. If writepermission was not removed automatically by the installer, execute the following:
icacls sites\default\settings.php /reset
This is a Living Document. Please contribute enhancements19