Bitnami Drupal Stack Virtual Machines Bitnami Virtual Machines contain a minimal Linux operating system with Drupal installed and configured. Using the Bitnami Virtual Machine image requires hypervisor software such as VMware Player or VirtualBox.Both of these hypervisors are available free of charge. I am developing on Mac OSX 10.10. I am not using MAMP, Aquia Desktop or anything like that. Instead, I am using the built in PHP/MySql in Mac (set up using this tutorial). When I run Drush, I get.
Drupal 7 Form_validate
Drupal 7 Machine Name Function
Installing Drupal on a Mac using MacPorts:
First steps:
1. Install Appleʼs “Development Tools” which youʼll find on the “Applications” DVDrom
that came with your Apple machine.
2. Run “Software Update” in “System Preferences” on your Mac to get the updates from
Apple for the Development Tools you just installed.
3. Download and install Macports from macports.org. This is a .dmg file that you
double-click on and go–easy.
To install Drupal7 on your Apple, we are going to use everything Macports. Everything
will be done on the command-line using Macʼs Terminal program (which youʼll find in
“Applications–>Utilities–>Terminal”). Many of the commands we type will require
superuser permissions and so weʼll be prefixing our commands with “sudo” and
sometimes it will make you type a password for a user with admin-level permissions on
the Mac.
Instead of macports, you can also use the default Apache that comes with every Apple,
and install a double-clickable mysql-server .dmg file from mysql.com and manually
install Drupal7 from drupal.org. Or you could instead install Drupal7 using the MAMP
method. Macports is a good option for two important reasons:
A. Macports is great software compiled for your Mac.
B. It is often used by experts and therefore the online help youʼll find is usually good.
4. Update Macports..in Terminal type this and wait a few hours:
sudo port selfupdate
5. Install apache2, php, mysql client, mysql-server, drupal7:
sudo port install apache2
sudo port install mysql5
sudo port install mysql5-server
sudo port install php52
cd /opt/local/apache2/modules
sudo /opt/local/apache2/bin/apxs -a -e -n “php5” libphp5.so
sudo port install drupal7
sudo port installed
sudo port list
sudo port list | grep agick
6. Setup mysql-server:
sudo port load mysql5-server
cd /opt/local/bin
sudo -u _mysql mysql_install_db5
cd /opt/local/; sudo /opt/local/lib/mysql5/bin/mysqld_safe &
/opt/local/lib/mysql5/bin/mysqladmin -u root password ʻs3kr3tʼ
cd /opt/local/bin/
mysql5 -u root -p
mysql> quit
7. Copy the Drupal files to apache2ʼs document directory:
cd /opt/local/www/data/drupal7/
sudo cp -a ./ /opt/local/apache2/htdocs/
sudo cp /opt/local/etc/php5/php.ini-dist /opt/local/etc/php5/php.ini
8. Restart apache2 and make changes to fix apache2:
sudo /opt/local/apache2/bin/apachectl -k restart
links http://localhost/ (gives you “It works” from index.html).
links http://localhost/index.php (gives you php source code)
….at this point two problems still exist:
1. Apache is returning index.html as default document, not index.php
2. Apache is not parsing PHP code, just returning the source code as text.
…to fix the index.html-vs-index.php problem we change DirectoryIndex ordering.
…to fix the PHP not parsing problem, add an “AddType PHP” directive to httpd.conf
Fix both problems like this:
******************************************************
sudo cp /opt/local/apache2/conf//httpd.conf /opt/local/apache2/conf/httpd.conf.ORIG
sudo vi /opt/local/apache2/conf//httpd.conf
sudo /opt/local/apache2/bin/apachectl -k restart
sudo cp /opt/local/apache2/conf//httpd.conf /opt/local/apache2/conf/httpd.conf.070611-
WORKS
links http://localhost/index.php (gives you Drupal page YAY!).
******************************************************
..if you donʼt know vi, try using nano or pico which are easier text editors to use.
..during our vi editing session, we commented-out one line and added two lines:
#DirectoryIndex index.html
DirectoryIndex index.php index.html
AddType application/x-httpd-php .php
…and now we have a working setup and backup httpd.conf. Notice that index.php
comes before index.html…this causes the php file to go out by default if both are
in the directory being requested by the user. The AddType line makes PHP work (that is,
it causes apache2 to execute the php source code instead of returning verbatim code to
the user).
9. One file that came with Drupal and is worth looking over is /.htaccess. Drupal follows
(or should be following) the directives in this file.
10. At this point, Drupal is working but is not setup. There are a few additional pieces of
administration necessary. What still needs to be fixed is not obvious. But because
Drupalʼs php code can execute, letʼs run it and see that it offers helpful
troubleshooting. When it complains about a problem, we will address and fix it until
it doesnʼt complain. At this point, Step #10 is the last “step”. From now on, we will
be clicking on links and filling out forms in our web browser and also running
command-line operations. These are easier to explain by discussion instead of
listing discrete steps.
On our fresh new site, when we visit http://localhost/ we get index.php, but it
in turn sends us to install.php (presumably because Drupal knows it hasn’t
been setup yet). The questions on the install.php page are:
———————–
Choose profile(active)
Choose language
Verify requirements
Set up database
Install profile
Configure site
Finished
———————–
…we should document our deployment choices. The first choice (profile)
asks us if we want “standard” or “minimal” and lets us click a button that
says “Save and Continue”.
…Now is a good time to read up on these choices so that we make good
choices…and then we’ll document them so we know which choices were made.
Continuing along, we are now at this Drupal location in our web browser:
http://localhost/install.php
…and we are making choices:
Choose Profile—–“Standard”
Choose Language—-“English”
Verify Requirements—NOT GOOD! These problems exist:
1. Database Support _NO
2. File System:”The directory sites/default/files does not exist”
3. Settings File:”./sites/default/settings.php file does not exist.”
…this is not too bad. To fix problems 2 and 3, we will make the “files” directory and will
copy in a default “settings.php” file to the proper location. We will also make the whole
directory owned by the apache2 user so that it has the permissions necessary to create
new files (so that users can upload files…and so that Drupal admins can add Drupal
modules). Run these commands in your command-line terminal:
******************************************************
cd /opt/local/apache2/htdocs/
ps -ef | egrep “PID|http”
cat /etc/passwd | grep 70
sudo mkdir sites/default/files
sudo cp sites/default/default.settings.php sites/default/settings.php
sudo chown -R _www ./
sudo /opt/local/apache2/bin/apachectl -k restart
******************************************************
…notice that we check (again) and see that apache is running as userid 70,
which on this MacOSX10.6 box’s /etc/passwd file indicates user “_www”. We
thus change the ownership of the htdocs directory recursively (all files/dirs below)
to new owner “_www”. Changing ownership is the only permissions change that we
should need to make because Drupal ships the files with the proper permissions by
default–for example–the “files” and “modules” and “themes” directories all ship owner-
writable so that users can upload files and admins can install modules and themes.
We also make a backup copy of the settings file and restart apache.
…after performing these steps and reloading our web browser on this page:
http://localhost/install.php
…both problems #2 and #3 went away.
…the first problem, “No Database Support”, was fixed like this:
******************************************************
sudo port uninstall php52
sudo port install php52 +apache2 +mysql5 +pear
cd /opt/local/apache2/modules
sudo /opt/local/apache2/bin/apxs -a -e -n “php5” libphp5.so
sudo /opt/local/apache2/bin/apachectl -k restart
******************************************************
…first we reinstalled php52 but added some extra “extensions”. The
macports php52 comes with several extensions, including:
curl, freetype, jpeg, libpng, libmcrypt, libxml2, libxslt, mhash, and tiff
…but we’re also going to want apache2, mysql5 and pear.
…after running the commands shown and reloading this Drupal setup page:
http://localhost/install.php
…the “Database Support” problem was fixed.
at this point in our Drupal7 setup, the “Verify Requirements” page reports “No
problems”–yay.
…continuing to go through the steps on the Drupal7 setup page at:
http://localhost/install.php
…we are now on the “Database Configuration” page. It wants to know:
1. Database name (and this database must already exist).
2. Database username
3. Database password
…this page won’t be successfully completed until we create the database
and a user/pass that has permissions on it. These steps were run to set that
up:
******************************************************
cd /opt/local/bin/
./mysql5 -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.1.57 Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the current input statement.
mysql> create database drupalseven;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL ON drupalseven.* TO ‘drupaluser’@’localhost’ IDENTIFIED BY
‘QW1ET’;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
******************************************************
…we may need to flush/reload/??? to get mysql to re-read its permissions.
Or maybe they work out of the box. Restarting mysqld does not appear to be
easy on this macports/osx10.6 box. To restart mysql, these steps were
run:
******************************************************
cd /opt/local/bin/
./mysql5 -u root -p
ps -ef | grep mysql (OUTPUT SHOWS mysqld_safe has PID 2424)
sudo kill -HUP 2424
./mysql5 -u drupaluser -p (WORKS)
******************************************************
…and with that we have a database named “drupalseven” and a user named
“drupaluser” whose password is “QW1ET”. User “drupaluser” was granted
all permissions on every table in the “drupalseven” database. We can now
continue by filling in these items on the “Database Configuration” portion
of the Drupal7 setup at:
http://localhost/install.php
DBNAME: drupalseven
DBUSER: drupaluser
DBPASS: QW1ET
…after entering this information, and clicking to continue, the
next page looked good, there was a status bar, and 28 of 28 things
got done…most of the text that went by said things about installing
modules, like this: “Installing the Toolbar Module”.
…The next page of the Drupal7 setup page at:
http://localhost/install.php
…is called “Configure Site” and asks for these things to be entered:
Site Name:
Site Email:
Site Maintenance Account:
—-user
—-email
—-pass
—-re-enter pass
Server Settings:
Default Country:
…at this point a good question is how the mail is going to work. If I paste
in a gmail address, how will I know if my machine and network will let it all
out. OSX10.6 does not ship with a running mail server because this
command just hangs:
******************************************************
mail -s “Testing RU There” `whoami`@`hostname`
telnet 127.0.0.1 25
Trying 127.0.0.1…
telnet: connect to address 127.0.0.1: Connection refused
telnet: Unable to connect to remote host
******************************************************
…try adding a gmail/yahoo and see if it lets you continue. Otherwise, these steps might
work:
******************************************************
sudo launchctl start org.postfix.master
telnet 127.0.0.1 25
sudo launchctl start org.postfix.master
telnet 127.0.0.1 25
mail localusername
less /var/mail/localusername
hostname
******************************************************
…whatever you get from the hostname command, write it down. Otherwise, you can
disable all of your networking (airport off, ethernet disabled, etc.) and type the
“hostname” command again to get a hostname like “Local-Usernames-Imac.local”.
When entering the Drupal-setup-email information, try one of these possibly-valid local
email addresses:
localuser@hostname.pitt.edu
localuser@Local-Usernames-Imac.local
…with any luck Drupal7 says:
“Drupal installation complete”
YAY!
…it prompts me with a link to “visit your new site”, that goes here:
http://localhost/
The Drupal7 setup will annoyingly not complete unless you can get past the Drupal7-
email-setup page. And the only way to do that is to enter a valid email address. This is
a drag because:
1. Your network might not let Drupal send out email (to yahoo for example).
2. Getting your local Mac to properly run an email server is not so simple especially
because your hostname is apple-unusual. Further, even if you do get it working
during drupal setup, most apple-hostnames change often. Your Mac laptopʼs
hostname this morning might have been “unpaiduser112@dhcp-forbes-
Pgh.starbucks.com” but later today it will be different and your Drupal7 email settings
willl be wrong.
3. Drupal7 disallows real and useable email addresses including these:
localuser@127.0.0.1
localuser@localhost
A good strategy is to just get past this portion of the setup process and worry about
fixing it later (or just look at logging information online instead of reading emails sent to
you by Drupal).
At this point, Drupal7 setup is complete. Very little will be necessary on the command-
line from now on. (Almost) everything Drupal is done via its web interface. Hence, this
is a good time to backup your Drupal site. Backing up Drupal can be done in many
ways including by using Drupalʼs “Backup & Migrate” Drupal module. Instead, we will
take a backup of the databases and the htdocs directory. All changes in Drupal will
manifest themselves (on this machine) at /opt/local/apache2/htdocs and /opt/local/var/
db/mysql5/. Notice that the htdocs directory might contain more web content than just
your Drupal stuff. Also notice that the mysql5 directory contains things other than your
Drupal databases–it contains all of the mysql databases. After taking this backup, we
will have an archive that can be used to restore our Drupal deployment to its exact state
at the time the backup was taken. Run these commands to take a backup:
******************************************************
ps -ef | egrep “PID|mysql”
sudo kill -9 560 (560 is the mysqld_safe PID)
sudo kill -9 561 (561 is the mysqld PID)
cd /opt/local/apache2/
sudo ./bin/apachectl stop
sudo tar -czf ./htdocsBackup070611.tar.gz ./htdocs/
cd /opt/local/var/db/
sudo tar -czf ./mysql5Backup070611.tar.gz ./mysql5/
******************************************************
…those two .tar.gz files contain our entire Drupal7 deployment so far and can be used to
restore the site to its current condition. To restart mysql and apache2, run these
commands:
******************************************************
cd /opt/local/; sudo /opt/local/lib/mysql5/bin/mysqld_safe &
cd /opt/local/apache2/
sudo ./bin/apachectl start
******************************************************
…your Drupal site should be running normally at http://localhost/.
When restoring a backup, typically you want to preserve the existing site. We will do
that. To restore your backups, run these commands:
******************************************************
ps -ef | egrep “PID|mysql”
sudo kill -9 560 (544 is the mysqld_safe PID)
sudo kill -9 561 (578 is the mysqld PID)
cd /opt/local/apache2/
sudo ./bin/apachectl stop
cd /opt/local/apache2/
mv htdocs htdocs_BrokenSite_070711
sudo tar -tzf ./htdocsBackup070611.tar.gz
sudo tar -xzf ./htdocsBackup070611.tar.gz
cd /opt/local/var/db/
mv mysql5 mysql5_BrokenSite_070711
sudo tar -tzf ./mysql5Backup070611.tar.gz
sudo tar -xzf ./mysql5Backup070611.tar.gz
cd /opt/local/; sudo /opt/local/lib/mysql5/bin/mysqld_safe &
cd /opt/local/apache2/
sudo ./bin/apachectl start
******************************************************
…the “mv” command is the rename command. Both times we ran it to preserve the
existing site by renaming the folder something besides htdocs or mysql5. When we run
the tar commands, we will be overwriting anything currently at htdocs or mysql5. tar
was run with -tzf which lists the files in the archives and -xzf which extracts the files from
the archives. Its always a good idea to run tar with the -t option first to make sure the
archive contains what you expect it does. If your site stays small, these backups wonʼt
be big and can be taken often. While under development, you can take a backup, then
do some risky/unknown Drupal development without worry. If things go badly, you can
just untar your trusty backup and start that risky part over again. Because Drupal and
mysql are relatively platform-independent, you should be able to take these two
archives to another machine (even a Linux machine) and untar them there and get your
site running elsewhere without too much trouble. Another reason to take backups is to
track development with documentation. Because most Drupal “administration” takes
place via its web interface, it is very easy to lose track of what administration has been
performed. Documenting Drupal administration will get very tedious because constantly
writing down what you are doing will result in dense, unreadable prose. A better way to
document Drupal administration might be like this:
1. Take a backup of Drupal.
2. Perform Drupal administration…module installation, etc. until you get it right, jot down
notes.
3. Restore backup taken in Step 1.
4. Redo successful steps taken in Step 2 (minus all the false leads/mistakes).
5. Write down the successful operations performed in Step 4.
…in this way, you can keep track of your Drupal site setup without having to remember
anything.
Backups like these are too easy and too useful to take that it never makes sense to not
get in the habit of doing it. If you only want to capture the Drupal mysql database (and
not the whole entire mysql directory), run instead this command sequence:
******************************************************
cd /opt/local/var/db/mysql5/
sudo tar -czf ./mysql5_drupalsevenBackup070611.tar.gz ./drupalseven
******************************************************