Drupal 7 provides great support for SQL Server as a backend and there are a lot of reasons why you'll like this combination. This webcast starts by showing you how to install a Drupal 7 web site with a SQL Server Express backend in a few clicks with WebPi and then discusses how to create and manage databases, logins and users using SQL Server Management Studio (SSMS) and the command line (SQLCMD).
Human Factors of XR: Using Human Factors to Design XR Systems
Drupal on IIS with SQL Server
1. Drupal on IIS with a
SQL Server database
Alessandro Pilotti
@alexpilotti
MVP ASP.NET / IIS
MCSD, MCAD, MCSE, MCDBA, MCT
Red Hat Certified Engineer
2. SQL Server and Drupal
Drupal offers the option to choose the database backend
No more limited to MySQL
Drupal 7 provides great support for SQL Server 2008
All major modules nowadays use PDO and portable SQL
Works as well with SQL Server 2008 R2 and 2012
MS provides a PHP PDO driver for SQL Server
There’s a free Express edition
Limited to 10GB per database
SQL Azure
3. SQL Server for MySQL devs /
admins
SQL Server is a relational database like MySQL
You can write SQL queries
(SELECT, INSERT, UPDATE DELETE)
Like for every other DBMS there are some tricky
differences
E.g. MySQL is more forgiving in the GROUP BY clause
Management tools:
Management Studio
sqlcmd.exe
4. Edition comparison
Express (free)
Contains everything you need for the average Drupal site
Limited to 10GB database size, 1GB memory, 1 socket / 4
cores
Web
Standard
Enterprise
Feature comparison charts:
http://msdn.microsoft.com/en-us/library/cc645993.aspx
5. SQL Server useful features
Online backup (included also in express edition!)
Full
Differential
Log
Replication
Min. standard edition, web and express only as subscribers
Mirroring
Min. standard edition
Log shipping
Min. web editition
Great profiling tools
UI tools in standard edition
6. Instances
You can install multiple isolated instances on the same
server
Only one can be the default unnamed instance
All the others are named
It means that you connect to the server with a name:
E.g. yourserverSQLEXPRESS
7. Databases
SQL Server instances, like MySQL, contain multiple
databases
Every Drupal site has usually a separate database
Or you can use table_prefix of course
Databases can be moved to different instances
detached from one
Attached to the other
Databases can be put individually offline
8. Authentication
Login
Credentials needed to connect to the instance
Windows account (integrated)
No password, best security approach
SQL server (mixed mode)
Classic username and password
Instance wide roles can be assigned to logins
Database users
Specific to each database
Logins are mapped to database users
Object level (table, etc) permissions are granted to users
Roles
A collection of permissions
Users can be assigned to roles
9. Main database roles
db_owner
Can do everything on the database (not the instance!)
db_datareader
Can run SELECT on any table / view
db_datawriter
Can run INSERT, UPDATE, DELETE
db_ddladmin
Can run any DDL command (CREATE, DROP, etc)
10. How to create a database
Very easily with Management Studio
Via command line:
sqlcmd –S .SQLEXPRESS –E
create database drupal7
create login drupal7 with password = 'Passw0rd’
go
use drupal7
go
create user drupal7 for login drupal7
exec sp_addrolemember db_owner, drupal7
go
11. Drupal 7 site with SQL Server
using WebPi
With just a few click using WebPi
Add also:
SQL Server 2008 R2 Management Studio Express with
SP1
12. Drupal 7 site with SQL Server
w/o WebPi
Create web site
Download and install SQL Server PDO driver:
http://www.microsoft.com/en-
us/download/details.aspx?id=20098
Enable PHP extensions php_sqlsrv and
php_pdo_sqlsrv
Drush @drupal7 dl sqlsrv
cd your_drupal_site_path
xcopy /i sitesallmodulessqlsrvsqlsrv
includesdatabasesqlsrv
13. Database management
Schedule proper backup policy
With or without transaction log
Schedule maintenance tasks
Update statistics
Reindex
Shrink database
14. Backup policy
Schedule a proper backup policy, e.g.:
Full database backup every night
Log every 5’ (or more, depending on your db)
This way you will not lose more than 5’ of data!
To be able to backup the transaction log, set the
database recovery model to
Full or Bulk-Logged
Default is Simple
15. Backup
Use Management Studio
or
BACKUP DATABASE [drupal7] TO DISK =
N'c:backupdrupal7_backup.bak' WITH INIT, NAME =
N'drupal7-Full Database Backup’
Store backups on a remote file share!
To do that run the SQL service with an ad hoc user
Create the same user on the server with the network
share
16. Set recovery model
Management Studio (very easy)
T-SQL (e.g. sqlcmd):
USE [master]
GO
ALTER DATABASE [drupal7] SET RECOVERY FULL
WITH NO_WAIT
17. How to schedule a backup
The express edition of SQL Server doesn’t have a UI to schedule
backups and other tasks
We can use the windows scheduler to schedule:
Full backup every night
Log backup every 5’
Delete of old backups every night
schtasks.exe /create /tn drupal7_db_backup_full /tr "sqlcmd -S
.SQLExpress -E -i c:backupdrupal7_backup_full.sql" /sc DAILY /ru
Administrator /rp /st 02:00:00
Useful task commands:
schtasks.exe /run /tn drupal7_db_backup_full
schtasks.exe /delete /tn drupal7_db_backup_full
18. To schedule a log backup
E.g.: every 15’:
schtasks.exe /create /tn drupal7_dbbackup_log /tr
"sqlcmd -S .SQLExpress -E -i
c:backupdrupal7_backup_log.sql" /sc MINUTE /MO 15
/ru administrator /rp
19. Restore a database
Best done via Management Studio
Or manually (here’s a complete sample):
RESTORE DATABASE [drupal7] FROM DISK =
N'c:backupdrupal7_backup_full_2012_05_15_14_53_06_470.bak' WITH FILE =
1, NORECOVERY
GO
RESTORE DATABASE [drupal7] FROM DISK =
N'c:backupdrupal7_backup_diff_2012_05_15_14_53_09_867.bak' WITH FILE =
1, NORECOVERY
GO
RESTORE LOG [drupal7] FROM DISK =
N'c:backupdrupal7_backup_log_2012_05_15_14_53_13_913.trn' WITH FILE =
1, NORECOVERY
GO
RESTORE LOG [drupal7] FROM DISK =
N'c:backupdrupal7_backup_log_2012_05_15_14_53_15_200.trn' WITH FILE = 1
GO