by Andres Baravalle
This course will enable you to build dynamic web sites and web applications based on (part of) the LAMP/WAMP stacks (an n-tier architecture) and Drupal.
We will start with an introduction to the main elements of the software stack that we will be using:
Web servers are in charge of delivering static HTML pages and any additional content needed in the page to the clients.
When a web server receives a request for an URL (uniform resource locator), the web server will try to locate the request on the file system and send it to the client.
Here is what a simple HTTP request looks like (short screencast here):
telnet mastodon.uel.ac.uk 80
Trying 161.76.74.2...
Connected to mastodon.uel.ac.uk.
Escape character is '^]'.
GET / HTTP1.0
MySQL is one of the world's most widely used databases, and the most popular Open Source database server.
MySQL supports a broad subset of ANSI SQL 99, as well as extensions. By default, it ships with no GUI, and is normally administered either from the command line or with third-party tools as phpMyAdmin.
MySQL is currently owned by Oracle and the original developer of MySQL has now created a competing Open Source product, MariaDB. MariaDB is compatible with MySQL. Websites as google and wikipedia and Linux distributions as Fedora are migrating to MariaDB.
Mastodon is using MySQL - but you can decide to use MariaDB on your development environment.
PHP is a Open Source server-side scripting language; you will be integrating components written in PHP and/or writing your PHP scripts.
In the past years you have seen how to:
Content management systems are web applications that allows developers to quickly create on-line content.
We will learn more about Drupal and CMS in the next workshops.
Deployment on mastodon works from UEL only; the rest of the workshop is dedicated on setting up your own development environment, complete with Apache, MySQL, PHP and Drupal.
If you decide to work on your own development environment (rather than on mastodon), you will have to consider issues as syncronising your work with your teammates.
Your first step is to install the software that we are going to need to use Drupal effectively. We will proceed in this order:
This documentation will cover installing the software stack on Windows only. You can user WAMP distributions instead - as XAMPP, WampServer or EasyPHP.
They are suitable as a development environment - but for production you should install the individual packages (ideally, on Linux or on another Unix-like system).
You need to be able to install software in the system (be a "local administrator" in Windows) to be able to proceed with the installation of Apache and PHP.
If you are not a local administrator, skip to the next steps.
Download and install the latest stable version of Apache HTTPD from the Apache web site. You should be able to follow the links and find the right version: httpd-xyz-win32-x86-openssl-xyz.msi
(xyz will be numbers representing the Apache and OpenSSL versions).
You can use the default settings - the task shouldn't take over 15 minutes.
After you have installed the web server, try to open your defaul home page at http://localhost/.
The main web server configuration is located in conf/httpd.conf
(we will need to modify this when installing PHP).
The log files (access_log
and error_log
) are located in the logs
folder.
Open your error_log
file and verify if any errors have been logged.
Apache's global settings are in conf/httpd.conf
.
.htaccess
files can be used to override Apache settings on a per-directory basis, when root access on the server system is not available.
You will use .htaccess files later on when configuring Drupal; the documentation is available here.
You can stop the server to free resources and you must restart the server after any changes in the configuration. To start/stop/restart the server, you can use the Services administration tool or the command line (net start|stop apachexyz
).
For more details, follow the Microsoft documentation.
Download the latest stable, thread safe version of PHP from the PHP web site. Follow this documentation: https://www.php.net/manual/en/install.windows.apache2.php
Make sure that the version of PHP you are downloading matches your operating system (Windows) and architecture (e.g. x86 vs x64).
Install PHP as an "Apache handler" and make sure that you change your httpd.conf
file as per documentation.
Make sure that the DLL that you are loading matches both the version of Apache that you are using (e.g. 2.2) and they type of installation ("Apache handler"). E.g. for Apache 2.2 and PHP5, the files is php5apache2_2.dll
, and for Apache 2.4 and PHP5, the file is php5apache2_4.dll
.
Installing PHP on Windows can be troublesome and can take anything between 10 minutes and several hours.
The main PHP configuration is located in php.ini
. You will not need to modify the file now, but you may need to modify it if you are managing your web server.
Create a text file in your Apache root folder (htdocs
) with your notepad and call it test.php.
Include this code:
<?php
phpinfo();
?>
Restart Apache and open http://localhost/test.php.
Seeks help! You need to complete all the previous steps before moving forward.
We show now have:
The next step is to install a database server (MySQL) and a frontend for MySQL (phpMyAdmin).
Download the latest stable (Generally Available, using MySQL's therminology) version of MySQL (full name: MySQL Community Server) from the MySQL web site.
Follow this documentation: http://dev.mysql.com/doc/refman/5.6/en/mysql-installer.html
Make sure that the version of MySQL you are downloading matches your operating system (Windows) and architecture (e.g. x86 vs x64).
MySQL is a client-server architecture; to use MySQL you need a MySQL server running ("service" in Windows) and a MySQL client.
The most basic MySQL client is available from the command line.
Connect to your MySQL server with your command line mysql client (where is it installed?):
mysql -u user -ppassword
A video guiding you through the next activity is available here.
To be sure everything is working correctly, show the list of databases:
SHOW databases;
If everything is correct, you should get a list of the databases in the server.
You can select a database with use
:
USE mysql;
This selects the administrative database (where settings and passwords are stored) for mysql.
List user details:
SELECT Host, User, Password FROM user;
Add a user:
GRANT ALL PRIVILEGES ON dbname.* TO username@hostname IDENTIFIED BY 'userpassword'
Using MySQL is not dissimilar to use other tools that you have used before - as Oracle or Microsoft Access.
If you need further information, you can start from here.
Altough PHP is often used with MySQL, MySQL support in PHP is implemented in a separate module (also called extension), php_mysqli.
The PHP documentation includes extensive information on installing modules.
To use MySQL from PHP, you need to enable the MySQL extension (mysqli, NOT mysql).
This requires editing the php.ini file and loading the mysqli extension:
extension=php_mysqli.dll
You will need to use the same procedure to load any other PHP modules you may need.
After enabling the module, you will need to restart Apache.
Create a file to test your Apache, MySQL and PHP installation:
<?php
$mysqli = new mysqli("localhost", "root", "12ajkvxc", "mysql");
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
if ($result = $mysqli->query("SELECT Host, User, Password FROM user;")) {
$row = $result->fetch_array(MYSQLI_NUM);
print_r($row);
}
?>
This will list the main details of the first user registed on your MySQL server.
We are not going to cover PHP; you should be familiar with some type of server side development from your previous studies.
If you need to improve your PHP skills, you can use this as starting points:
Welling, L. and Thomson, L. (2008) PHP and MySQL web development. 4th edn. London: Addison Wesley.
Download the latest stable version of phpMyAdmin from the phpMyAdmin web site (select the English only version; download the zip archive).
You will have to:
Follow this documentation: http://docs.phpmyadmin.net/en/latest/setup.html#installing-on-windows
Download the latest stable version of Drupal (currently, version 7) from the Drupal web site.
As you did with phpMyAdmin, you will have to:
You should have already installed on your system these editors:
You'll start to use them shortly.
Notepad++ is a general-purpose lightweight text editor, that can be used to write code in a number of different programming languages.
Editing features include:
Additional plugins allow to extend the program and integrate further features.
Aptana Studio is a editor built on top of Eclipse, targeting development using Python and PHP
Aptana Studio is a more complete application compared to all the ones seen in the previous slides
You can use Apatana Studio to upload your files on your web server (mastodon) or you can use a custom application as WinSCP.
WinSCP is typically easier to use compared to Aptana.
Open Source is software released under a license that guarantees to its users the:
Software that is not Free Software is usually called proprietary
Free Software and Open Source are synonyms used by different groups that see a different role for Free Software/Open Source
Free to use means that Open Source software can be used without restrictions:
Other editors include:
eapp-win32 (eclipse/apatana/python/php) is a package we have compiled including:
and a few other bits 'n' pieces.
aptana-studio-x |
Aptana Studio (x is version number) |
eclipse-platform-x.y-win32 |
Eclipse (x.y is version number) |
notepad++ |
notepad++ |
portable-git-x.y.z |
git (used for versioning and configuration management; x.y.z is version number) |
php5.4 | python (includes IDLE; x.y is version number) |
hello.php | your Hello World in PHP |
winscp | To upload files on Mastodon |
other files/folders |
ignore – not relevant on this module |
You can use eapp-win32 in the KD labs:
You may find start-up errors when running Aptana Studio; you can normally ignore the start-up errors.
You do not need to configure Git support; please select "Check this if you do not want to be asked again".
Remember: eapp-win32 uses Open Source software only; that means that you can use the full software stack at home
Just download the software from here (about 580mb).
Copy in your c:\Program Files (x86) (or c:\Program Files) folder and start using it
Good! Download and install the individual components of eapp-win32 on your computer.
Make sure you download and install the Linux (or *nix) version and that it matches your architecture (32 vs 64 bits).
That's ok – we're against discrimination. Download and install the individual components of eapp-win32 on your computer
Make sure you download and install the Mac version and that it matches your architecture (32 vs 64 bits)
We would recommend that you download an install eapp-win32 on a USB stick too.
You will be able to use your software in any computer (including the library), without needing to install the software (but it is slower than a local copy).
Share your experience on twitter #uel #im3082
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License