Development environment » History » Version 5
Jon Goldberg, 05/04/2013 01:05 PM
1 | 2 | Benjamin Doherty | h1. Development environment |
---|---|---|---|
2 | |||
3 | 1 | Benjamin Doherty | h2. Goals |
4 | |||
5 | One Drupal installation can support many separate sites through Drupal's multi-site functionality. We want you to use this multi-site set up because it imposes some constraints on your development environment that will ensure that your work will migrate to other environments without a hitch. |
||
6 | |||
7 | Developing in a multi-site environment immediately shakes out a common class of problems related to paths and URLs. If the site you're developing is hosted in sites/mysite but in other environments it's hosted in sites/myhost.com, you'll have to use url() and drupal_get_path() functions to reliably load PHP include files or theme assets across all of your environments. |
||
8 | |||
9 | Drupal-specific deployment systems (AEgir) rely on sites' ability to deploy into a multi-site environment. |
||
10 | |||
11 | Finally, the development environment you build will be one that suits your skills and needs. There are minimums you need to accomplish, but we will indicate when you can stop if you're satisfied for now. If you want to build a more sophisticated, complex and automated development environment, keep following along. |
||
12 | |||
13 | h3. Hacking core |
||
14 | |||
15 | Relying on a multisite-oriented environment enforces another good Drupal developer practice: don't hack core. If your Drupal projects share a common Drupal core, any core hacks you make will also be shared by all of these other projects. If a core hack is good enough for multiple sites, it's good enough to submit as a patch to core! |
||
16 | |||
17 | At the same time, it's justified to make some patches to core just for your development environment. For example, see the section about Xdebug. |
||
18 | |||
19 | Even though Devel module will override core's minified version of jQuery with an uncompressed copy, serious jQuery debugging will require that all of your scripts be uncompressed, which means you will need to replace jQuery UI with an uncompressed version. |
||
20 | |||
21 | Multisite : Each Drupal platform (core and any install profiles) will support |
||
22 | |||
23 | Uniformity : We explain how to set up a development environment which is uniform regardless of your preferred operating system. Only installation and upgrades are different depending on your operating system. Configuration and usage are consistent regardless of whether you use Windows, Mac OS X or Linux. |
||
24 | |||
25 | Maintenance : The development environment will be set up so that all of your web development projects are stored in the same part of your file system: a directory named workspace. |
||
26 | |||
27 | TODO: Create a directory inside your home directory named “workspace” |
||
28 | |||
29 | h3. Credit |
||
30 | |||
31 | This development environment is directly inspired by the “sandbox” design used by CivicActions. This was developed by Owen Barton, Fen Labalme and the staff of OpenWall. The same principles for organizing the development environment are used for easily deploying sites in staging, testing and production environments by CivicActions. |
||
32 | |||
33 | Drubuntu also inherits from this design, and it's highly recommended for users who are already using Ubuntu 10.10. |
||
34 | |||
35 | You need to create a LAMP stack on your computer. LAMP is an acronym for Linux, Apache HTTP Server, MySQL and Perl/PHP/Python. Most Drupal sites are deployed on this software. |
||
36 | |||
37 | Drupal can run in other server environments and other platforms. Obviously, we are not going to insist that you switch your personal operating system to Linux just to develop Drupal sites, so Windows and Mac can be substituted for Linux. Solaris and FreeBSD are also suitable platforms for Drupal, but if you are developing sites in this environment, you will need to translate the Linux instructions using your own know-how. On Windows, IIS is supported, but it's not recommended. Drupal 7 supports MySQL, PostgreSQL and SQLite, but most Drupal sites use MySQL and there's a tremendous amount of documentation, GUI client software and support for MySQL. We're going to omit Perl and Python, because Drupal only needs PHP. You will still be able to install Perl or Python if you need it. |
||
38 | |||
39 | h2. Platform specific |
||
40 | |||
41 | The main differences about configuring your development environment are the location of configuration files and the default settings in those configuration files. Use the table to identify the configuration files you may need to edit. If your files are located in another spot, note this because you'll need this information in the future. |
||
42 | |||
43 | | | MAMP | Homebrew | Windows | Ubuntu Linux | |
||
44 | | http.conf | /Applications/MAMP/conf/apache/httpd.conf | /private/etc/apache2/httpd.conf | | /etc/apache2/httpd.conf | |
||
45 | | my.cnf | /Applications/MAMP/db/mysql/my.cnf | /usr/local/var/mysql | | /var/lib/db/mysql | |
||
46 | | php.ini | /Applications/MAMP/conf/php5.3/php.inii | /opt/local/etc/php5/php.ini | | /etc/php5/conf.d/php.ini | |
||
47 | |||
48 | Some of us use version control to track changes and maintain a backup history for our configuration files |
||
49 | |||
50 | h3. Windows |
||
51 | |||
52 | For Windows, we will use WampServer. http://www.wampserver.com/en/ |
||
53 | |||
54 | WampServer 2.1 meets all the requirements for Drupal 7. For earlier versions of Drupal, you will need to also download an older version of PHP to install. |
||
55 | |||
56 | http://en.wikipedia.org/wiki/Comparison_of_WAMPs |
||
57 | |||
58 | WAMP's default httpd.conf needs to have mod rewrite enabled. |
||
59 | |||
60 | Wrap paths in quotation marks. |
||
61 | |||
62 | WAMP already loads configuration files from an aliases directory, so instead of including the file in httpd.conf, copy it to the directory named in the include. |
||
63 | |||
64 | Vhost_alias_module needed. |
||
65 | |||
66 | h3. Mac |
||
67 | |||
68 | For Mac, there are two strategies for maintaining a Drupal development environment with their own strengths and weaknesses. Mac OS X could support Drupal on a the default system distributed by Apple Inc. It has Apache HTTPD Server and PHP already installed, and each user has a home directory named “Sites” which is Apache's user home directory. However, it does not have MySQL. |
||
69 | |||
70 | The Macintosh software community has provided two kinds of LAMP stacks: binary application packages and package managers. MAMP is an application package, which you download and install by copying. It is by far the quickest and easiest way to set up a development environment. However, it requires configuration after it has been installed. When you upgrade MAMP, you will need to remember to revisit these instructions so that your development environment does not break. |
||
71 | |||
72 | The alternative and more complicated method relies on a package manager. All package managers require that you install the Mac OS X Developer Tools. These developer tools are distributed on Mac OS X Install DVDs and also downloadable from http://developer.apple.com. We encourage you to customize the installation so that you can exclude documentation or extras you don't want, because the developer tools are very large. The documentation does include UNIX manual pages and Apple Developer documentation for Safari and Mobile Safari and a useful amount of web standards documentation. Likewise, XCode could be an IDE for your Drupal sites, but it's missing some simple features available in free and better tools. |
||
73 | |||
74 | As you improve in your web development skills in Drupal, you will confront the need to compile any number of new tools or servers for your environment. People in the Drupal community use more than just Drupal, and we will introduce you to new things like Compass, Solr, Memcached, Cucumber or a PECL add-ons. We urge you to use a package manager for these other tools because otherwise you risk destroying or disabling your development environment whenever you upgrade Mac OS X. Not every piece of useful web development software is distributed as a compiled binary for Mac OS X. |
||
75 | |||
76 | h4. MAMP |
||
77 | |||
78 | MAMP from http://www.mamp.info/ is an application that you will copy into your Applications folder. Although it is running system services, it's attaching them to high-number, non-standard ports. MAMP's preferences are user specific, but MAMP may not run correctly if multiple users on the same computer want to use MAMP. It can run concurrently with Mac OS X's own Apache server (the “Web server” controlled by the Sharing preference pane), though you hopefully do not need to run both at the same time. !MAMP.png(MAMP.png)! |
||
79 | |||
80 | After copying MAMP to your Applications folder, run it. You will be greeted by the MAMP application window and the MAMP start page in your default web browser as served by MAMP. The start page for MAMP gives you access to phpMyAdmin, various PHP info pages and some documentation. It also shows the default MYSQL credentials. |
||
81 | |||
82 | MAMP runs as the logged in user, and any files it creates (MySQL database files, log files, files uploaded through your Drupal development sites, Imagecache generated files) will be owned by the logged in users. This makes backup very simple and reliable, but it could lead to problems if two users on the same computer want to use MAMP for their own projects. |
||
83 | |||
84 | The MAMP application window allows you to turn on and off the servers, open the start page, and set preferences. By default, MAMP will start and stop all of its services whenever the MAMP application is opened or closed. We like these preferences for MAMP. MAMP currently is distributed with PHP 5.2 and 5.3, and you may need to switch between these PHP versions if you're supporting Drupal 6 or other PHP applications. For Drupal 7, all of MAMP's default settings are appropriate. |
||
85 | |||
86 | h4. Homebrew |
||
87 | |||
88 | Homebrew is a Mac OS X package manager that compiles from source and leverages software already installed as part of Mac OS X. Apache HTTPD Server and PHP 5.3 are already installed on Mac OS X Snow Leopard. Mac OS X Leopard uses PHP 5.2, which is also supported in Drupal 7. The only piece missing is MySQL. |
||
89 | |||
90 | You must install the Mac OS X Developer Tools before attempting to set up a development environment with Homebrew. If you are already suing MacPorts or Fink, you should avoid running both Homebrew and another package manager. |
||
91 | |||
92 | Install Homebrew from http://mxcl.github.com/homebrew/ |
||
93 | |||
94 | In the terminal, run “brew install mysql.” |
||
95 | |||
96 | h3. Ubuntu Linux |
||
97 | |||
98 | Users of Ubuntu Linux are fortunate to have access to a high-quality LAMP from within their package manager (usually Synaptic). Using the package manager, install these packages and their dependencies: |
||
99 | |||
100 | * Apache2 |
||
101 | ** apache2 |
||
102 | ** apache2-mpm-prefork |
||
103 | * MySQL |
||
104 | ** mysql-server |
||
105 | * PHP |
||
106 | ** curl |
||
107 | ** libapache2-mod-php5 |
||
108 | ** php5-cli |
||
109 | ** php5-common |
||
110 | ** php5-curl |
||
111 | ** php5-dev |
||
112 | ** php5-gd |
||
113 | ** php5-mcrypt |
||
114 | ** php5-mysql |
||
115 | ** php5-sqlite |
||
116 | ** php5-xdebug |
||
117 | ** php5-xsl |
||
118 | ** php-apc |
||
119 | ** php-pear |
||
120 | |||
121 | 4 | Jon Goldberg | <pre> |
122 | apt-get install apache2 apache2-mpm-prefork mysql-server curl |
||
123 | libapache2-mod-php5 php5-cli php5-common php5-curl php5-dev php5-mcrypt |
||
124 | php5-mysql php5-sqlite php5-xdebug php5-xsl php-apc php-pear |
||
125 | </pre> |
||
126 | |||
127 | 1 | Benjamin Doherty | h2. Apache |
128 | |||
129 | Drupal prefers Apache HTTPD Server. Core Drupal features like clean URLs are usually supported with no additional configuration. |
||
130 | |||
131 | Because Apache sometimes runs as a system user (usually www, www-data, apache or httpd), you may need to edit a few configuration files as the superuser or Administrator. |
||
132 | |||
133 | For your environment, Apache virtual host configurations will define at least one Drupal platform in which individual sites will be developed. A Drupal platform is the set of files that constitute Drupal core, any installation profiles, and any shared modules, themes or libraries located in sites/all. |
||
134 | |||
135 | In your workspace, create a new directory named conf.d. |
||
136 | |||
137 | In this directory, create these files. These configuration files define virtual hosts for each Drupal platform in your workspace. |
||
138 | |||
139 | "https://github.com/bangpound/webdev-workspace/blob/master/workspace/conf.d/000-default.conf":https://github.com/bangpound/webdev-workspace/blob/master/workspace/conf.d/000-default.conf |
||
140 | |||
141 | This sets up some blanket options that apply to every project in your workspace, so that essential URL rewriting and access permissions are set correctly. |
||
142 | |||
143 | "https://github.com/bangpound/webdev-workspace/blob/master/workspace/conf.d/drupal-7.conf":https://github.com/bangpound/webdev-workspace/blob/master/workspace/conf.d/drupal-7.conf |
||
144 | |||
145 | This tells Apache about Drupal 7. When you access your development environment's sites through your web browser, you will be navigating a URL that only your computer can access, for example http://new-site.7/. This configuration file tells Apache that any request it receives for a URL where the host name ends with .7, it should serve files from your Drupal 7 site directory. |
||
146 | |||
147 | "https://github.com/bangpound/webdev-workspace/blob/master/workspace/conf.d/localhost.conf":https://github.com/bangpound/webdev-workspace/blob/master/workspace/conf.d/localhost.conf |
||
148 | |||
149 | This file gives you some flexibility to break out of the rigid structure of this development environment. If you need to engineer on new Drupal platform or maintain a site that for whatever reason does not function in a multisite environment, you can add that project to your workspace. For example, if you want to set up Tattler http://tattlerapp.com/, you can put its directory in your workspace as tattlerapp, and it will be accessed as http://tattlerapp.localhost/. |
||
150 | |||
151 | Typical, current Apache HTTPD installations use a modular configuration file arrangement. This allows us to modify httpd.conf as little as possible, because this may be rewritten in a software upgrade. In your Apache configuration directory /etc/apache2, there is httpd.conf and an extra directory. |
||
152 | |||
153 | In your Apache's httpd.conf, add the following: |
||
154 | |||
155 | bc. # |
||
156 | # Include workspace configurations |
||
157 | # |
||
158 | Include /PATH/TO/extra/webdev-workspace.conf |
||
159 | |||
160 | |||
161 | Then create the webdev-workspace.conf file in your extra directory. This simply loads the configuration files from your workspace. |
||
162 | |||
163 | <pre> |
||
164 | # |
||
165 | # Include workspace configurations |
||
166 | # |
||
167 | |||
168 | Include /PATH/TO/YOUR/workspace/conf.d/*.conf |
||
169 | </pre> |
||
170 | |||
171 | h2. Hosts |
||
172 | |||
173 | The hosts file exists on every operating system http://en.wikipedia.org/wiki/Hosts_(file), and it's usually the last place your computer looks to resolve a domain name. The hosts file is what gives your system the name “localhost,” and it's very important that you never remove entries from the file that you didn't put there yourself. |
||
174 | |||
175 | Each project in your development environment needs to be accessible at the root of a unique host name, because this is how your project will likely be deployed. If your project will be deployed in a subdirectory of a larger site or in a user's home directory, you will want to recreate this too so you can catch any path name errors. |
||
176 | |||
177 | Edit /etc/hosts |
||
178 | |||
179 | Add a block comment to indicate where your changes begin and add the first hostname. |
||
180 | |||
181 | bc. # |
||
182 | # Webdev-workspace project |
||
183 | # |
||
184 | 127.0.0.1 d7 |
||
185 | |||
186 | |||
187 | h2. PHP |
||
188 | |||
189 | Usually when PHP is installed, it's set up for a development environment. Certain settings are unsuitable for a production environment, so you should make sure you have the right php.ini file installed. |
||
190 | |||
191 | Often, two configuration files come with PHP. php.ini-dist contains settings appropriate for your development environment. php.ini-recommended contains a few changes that hide error messages. The files have only a handful of differences to address the security and performance requirements of development and production environments. |
||
192 | |||
193 | Your development environment exists to show you how bad your work might be, and this is a better plan than letting your production environment show everyone in the world how bad your code actually is! |
||
194 | |||
195 | Verify that your php.ini file is configured with these settings: |
||
196 | |||
197 | bc. display_errors = On |
||
198 | |||
199 | |||
200 | PHP has a customizable error system, which Drupal 7 takes advantage of, which allows applications to handle non-fatal errors themselves and to change settings that affect output and thresholds. |
||
201 | |||
202 | Prior to Drupal 7, release versions of Drupal would not display PHP notice errors (E_NOTICE) and you either had to hack core or use a development release to display these error messages. Notices are useful because they reveal simple but hard to spot mistakes such as using variables that you've not assigned or using ambiguous syntax. http://drupal.org/node/34341 |
||
203 | |||
204 | Error reporting may be annoying when the error has no apparent impact on the site's functionality, but notices often appear because of mistakes that are not going to cause fatal errors but which lead to buggy behavior. |
||
205 | |||
206 | h2. MySQL |
||
207 | |||
208 | MySQL really has no special problems for setting up. Recommendations are to install from a package or build from source using a package manager. |
||
209 | 3 | Benjamin Doherty | |
210 | Editing your server's my.conf file to enable "innodb_file_per_table":http://dev.mysql.com/doc/refman/5.0/en/innodb-multiple-tablespaces.html to make the InnoDB files smaller and fragmented, which is friendlier to a development environment. |