Difference between revisions of "PHPUnit installation in OS X"

Jump to: navigation, search
(Install and configure OpenLDAP)
(Kill this page - it's has nothing of value which relates to PHPUnit.)
 
(27 intermediate revisions by 2 users not shown)
Line 1: Line 1:
'''This step-by-step guide is intended for developers only, it can not be used for production servers!'''
+
<p class="note">NOT UPDATED ANY MORE!!! This step-by-step guide is intended for developers only, it cannot be used for production servers!</p>
  
=MacPorts=
+
No special installation instructions are required for installation of PHPUnit on OS X.
The MacPorts Project is an open-source community initiative to design an easy-to-use system for compiling, installing, and upgrading open-source software on the Mac OS X operating system.
 
 
 
Installation:
 
* Install the latest version of Xcode from Mac App Store.
 
* In the meantime, register on the Apple Developer Connection for free (https://developer.apple.com/).
 
* Launch Xcode and go to "Xcode / Preferences... / Downloads" and install "Command Line Tools" (you will be asked for your developer id and password).
 
* Download the dmg image from http://www.macports.org/install.php (for example MacPorts-2.1.2-10.8-MountainLion.dmg) and install it.
 
* Open a terminal application and update MacPorts
 
 
 
$ sudo port selfupdate
 
 
 
* If you see "Warning: xcodebuild exists but failed to execute" execute
 
 
$ sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
 
 
 
Optionally add ports binaries as the first path <code>/opt/local/bin</code> in default system paths in
 
 
 
$ sudo vi /etc/paths
 
 
 
=Install Apache, PHP and PostgreSQL=
 
 
 
In older OSX versions disable the built-in web server by:
 
 
 
* opening System Preferences,
 
* clicking Sharing, and
 
* making sure "Web Sharing" is disabled.
 
 
 
In OSX 10.8 unload the default Apache server
 
 
 
$ sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
 
 
 
Quit terminal application and launch it again to get updated PATH in bash.
 
 
 
===Install and configure PHP===
 
 
 
Install PHP from MacPorts
 
 
 
$ sudo port install php54 php54-gd php54-mbstring php54-iconv php54-curl php54-zip php54-soap php54-intl php54-xmlrpc php54-openssl php54-ldap php54-xdebug
 
$ sudo port select --set php php54
 
 
 
Configure PHP
 
 
 
$ sudo cp /opt/local/etc/php54/php.ini-development /opt/local/etc/php54/php.ini
 
 
 
Verify PHP installation by executing the binary
 
 
 
$ php -v
 
 
 
Expected result is something like: <code>PHP 5.4.10 (cli) (built: Dec 20 2012 19:30:08)</code>
 
 
 
===Install and configure Apache===
 
Install Apache from MacPorts
 
 
 
$ sudo port install php54-apache2handler apache2
 
 
 
Configure Apache
 
 
 
$ cd /opt/local/apache2/modules
 
$ sudo /opt/local/apache2/bin/apxs -a -e -n php5 mod_php54.so
 
 
 
* Edit the Apache configuration file by running
 
 
 
$ sudo vi /opt/local/apache2/conf/httpd.conf
 
 
 
* In the document, add the following content, which will change the document root, add index.php as a directory index file and add the php type handler.
 
 
 
DocumentRoot "/server/workspace"
 
<Directory "/server/workspace">
 
    Options FollowSymLinks
 
    AllowOverride All
 
    Order allow,deny
 
    Allow from all
 
</Directory>
 
 
  <IfModule dir_module>
 
    DirectoryIndex index.php index.html
 
</IfModule>
 
AddType application/x-httpd-php .php
 
 
 
Create workspace directory and set permissions to allow both developer and Apache to write to server directory
 
 
$ sudo mkdir /server
 
$ sudo mkdir /server/workspace
 
 
$ sudo chmod -R +a "_www allow read,delete,write,append,file_inherit,directory_inherit" /server
 
$ sudo chmod -R +a "`whoami` allow read,delete,write,append,file_inherit,directory_inherit" /server
 
 
 
Create a test file
 
 
 
$ vi /server/workspace/index.php
 
 
 
<code php>
 
<?php
 
echo "test";
 
</code>
 
 
 
Start apache server and enable autostart
 
 
 
$ sudo port load apache2
 
 
 
Test that apache displays the "test" message on http://127.0.0.1/
 
 
 
===Install and configure PostgreSQL===
 
 
 
Install PostgreSQL from MacPorts
 
 
 
$ sudo port install postgresql92-server php54-postgresql
 
$ sudo port select --set postgresql postgresql92
 
 
 
Run the following commands to configure PostgreSQL
 
 
 
$ sudo mkdir -p /opt/local/var/db/postgresql92/defaultdb
 
$ sudo chown postgres:postgres /opt/local/var/db/postgresql92/defaultdb
 
$ sudo su postgres -c '/opt/local/lib/postgresql92/bin/initdb -D /opt/local/var/db/postgresql92/defaultdb'
 
 
$ sudo port load postgresql92-server
 
 
 
* Create new "moodle" database
 
 
 
$ sudo -u postgres createdb -E utf8 moodle
 
 
 
* Optionally set password and protect connection to your server via TCP/IP by changing "trust" to "md5" on the line containing 127.0.0.1 in pg_hba.conf.
 
 
 
$ sudo vi /opt/local/var/db/postgresql92/defaultdb/pg_hba.conf
 
 
 
# IPv4 local connections:
 
host    all            all            127.0.0.1/32            md5
 
 
 
* Restart the PostgreSQL server
 
 
 
$ sudo /opt/local/etc/LaunchDaemons/org.macports.postgresql92-server/postgresql92-server.wrapper restart
 
 
 
* Restart Apache server
 
 
 
$ sudo /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper restart
 
 
 
===Install and configure MariaDB===
 
 
 
Install MariaDB from MacPorts
 
 
 
$ sudo port install mariadb-server php54-mysql
 
$ sudo port select --set mysql mariadb
 
 
 
Run the following commands to configure and secure MariaDB
 
 
 
$ sudo -u _mysql /opt/local/lib/mariadb/bin/mysql_install_db
 
$ sudo port load mariadb-server
 
$ /opt/local/lib/mariadb/bin/mysql_secure_installation
 
 
 
* Create new "moodle" database
 
 
 
$ mysql -u root -p --execute="create database moodle;"
 
 
 
* Optionally set default mysql socket in PHP.ini to  '/opt/local/var/run/mariadb/mysqld.sock'
 
* Restart Apache server
 
 
 
$ sudo /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper restart
 
 
 
===Install and configure OpenLDAP===
 
 
 
Install OpenLDAP server from MacPorts
 
 
 
$ sudo port install openldap
 
 
 
Configure OpenLDAP
 
$ cd cd /opt/local/etc/openldap/
 
$ sudo cp /opt/local/var/openldap-data/DB_CONFIG.example /opt/local/var/openldap-data/DB_CONFIG
 
$ sudo cp DB_CONFIG.example DB_CONFIG
 
$ sudo cp ldap.conf.default ldap.conf
 
$ sudo cp slapd.conf.default slapd.conf
 
 
 
Alter slapd.conf to include following settings
 
 
 
$ sudo vi slapd.conf
 
 
 
include        /opt/local/etc/openldap/schema/core.schema
 
include        /opt/local/etc/openldap/schema/cosine.schema
 
include        /opt/local/etc/openldap/schema/nis.schema
 
include        /opt/local/etc/openldap/schema/inetorgperson.schema
 
modulepath      /opt/local/libexec/openldap
 
moduleload      back_bdb.la
 
suffix          "dc=yourcomputer,dc=local"
 
rootdn          "cn=admin,dc=yourcomputer,dc=local"
 
rootpw  yourpassword
 
 
 
Unfortunately there are permission problems in openldap port, you need to start the server manually each time you use it or change permissions of openldap dirs and /opt/local/var
 
 
 
$ sudo /opt/local/libexec/slapd -d 3
 
 
 
or another option is to edit the launcher file to use root account instead of ldap
 
 
 
$ sudo vi /opt/local/etc/LaunchDaemons/org.macports.slapd/slapd.wrapper
 
 
 
  /opt/local/libexec/slapd -u root -f /opt/local/etc/openldap/slapd.conf
 
 
 
$ sudo port load openldap
 
 
 
Build LDAP tree structure in a new shell prompt
 
 
 
$ ldapadd -H ldap://127.0.0.1 -D "cn=admin,dc=yourcomputer,dc=local" -W
 
dn:dc=yourcomputer,dc=local
 
objectClass:dcObject
 
objectClass:organizationalUnit
 
dc:yourcomputer
 
ou:YOURCOMPUTER
 
 
 
and press CRTL-D to finish input.
 
 
 
=Configure Moodle=
 
* Create workspace directories
 
 
 
$ sudo mkdir /server/moodledata
 
$ sudo mkdir /server/phpu_moodledata
 
 
 
* Clone the Moodle git master as follows
 
 
 
$ cd /server/workspace
 
$ git clone git://github.com/moodle/moodle.git
 
 
 
* Add a config.php file
 
 
 
$ vi /server/workspace/moodle/config.php
 
 
 
with the following content:
 
 
 
<code php>
 
<?php  // Moodle configuration file
 
unset($CFG);
 
global $CFG;
 
$CFG = new stdClass();
 
$CFG->dbtype    = 'pgsql';
 
$CFG->dblibrary = 'native';
 
$CFG->dbhost    = 'localhost';
 
$CFG->dbname    = 'moodle';
 
$CFG->dbuser    = 'postgres';
 
$CFG->dbpass    = ''; // set password here if used
 
$CFG->prefix    = 'mdl_';
 
$CFG->dboptions = array (
 
  'dbsocket' => '/tmp/',
 
);
 
 
 
/*
 
// Uncomment to test MySQL compatibility.
 
$CFG->dbtype    = 'mysqli';
 
$CFG->dblibrary = 'native';
 
$CFG->dbhost    = 'localhost';
 
$CFG->dbname    = 'moodle';
 
$CFG->dbuser    = 'root';
 
$CFG->dbpass    = ''; // set password here if used
 
$CFG->prefix    = 'mdl_';
 
$CFG->dboptions = array (
 
  'dbsocket' => '/opt/local/var/run/mariadb/mysqld.sock',
 
);
 
*/
 
 
 
$CFG->wwwroot  = 'http://127.0.0.1/moodle';
 
$CFG->dataroot  = '/server/moodledata';
 
$CFG->passwordsaltmain = 'some random rubbish goes here';
 
 
$CFG->debug = (E_ALL | E_STRICT);
 
$CFG->debugdisplay = 1;
 
$CFG->phpunit_prefix = 'phpu_';
 
$CFG->phpunit_dataroot = '/server/phpu_moodledata';
 
 
 
// Optionally fix and uncomment settings for external LDAP tests
 
//define('TEST_ENROL_LDAP_HOST_URL', 'ldap://127.0.0.1');
 
//define('TEST_ENROL_LDAP_BIND_DN', 'cn=admin,dc=yourcomputer,dc=local');
 
//define('TEST_ENROL_LDAP_BIND_PW', 'yourpassword');
 
//define('TEST_ENROL_LDAP_DOMAIN', 'dc=yourcomputer,dc=local');
 
 
 
//define('TEST_AUTH_LDAP_HOST_URL', 'ldap://127.0.0.1');
 
//define('TEST_AUTH_LDAP_BIND_DN', 'cn=admin,dc=yourcomputer,dc=local');
 
//define('TEST_AUTH_LDAP_BIND_PW', 'yourpassword');
 
//define('TEST_AUTH_LDAP_DOMAIN', 'dc=yourcomputer,dc=local');
 
 
 
 
require_once(dirname(__FILE__) . '/lib/setup.php');
 
</code>
 
 
 
=Install PHPUnit=
 
Since Moodle 2.3.4 it is recommended to use Composer dependency manager instead of PEAR for PHPUnit installation.
 
 
 
==Composer dependency manager==
 
 
 
$ cd /server/workspace/moodle
 
$ curl -s https://getcomposer.org/installer | php
 
$ php composer.phar install --dev
 
 
 
=Initialise test environment=
 
 
 
Open a terminal application and run the following commands
 
 
 
$ cd /server/workspace/moodle
 
$ php admin/tool/phpunit/cli/init.php
 
 
 
=Execute all tests=
 
 
 
Open a terminal application and run the following commands
 
 
 
$ cd /server/workspace/moodle
 
$ vendor/bin/phpunit --colors
 
 
 
=Other tasks=
 
 
 
==Configure PHP error logging==
 
 
 
Create log directory
 
 
 
$ mkdir /server/logs
 
 
 
Redirect error logging to log file by editing php.ini file
 
 
 
$ sudo vi /opt/local/etc/php54/php.ini
 
 
 
Add following line:
 
 
 
error_log = /server/logs/php_errors.log
 
 
 
Restart apache
 
 
 
$ sudo /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper restart
 
 
 
Display error log
 
 
 
$ tail -f /server/logs/php_errors.log
 
 
 
Test that error is added to the log
 
 
 
$ php -r echoooo
 
 
 
=Other useful applications=
 
* pgAdmin III for PostgreSQL database management - http://www.pgadmin.org/download/macosx.php
 
* Sequel Pro for MySQL database management - http://www.sequelpro.com
 
* SourceTre Git GUI - http://www.sourcetreeapp.com
 
* Tower Git GUI - http://www.git-tower.com
 
* PHPStorm IDE - http://www.jetbrains.com/phpstorm/
 
* Apache Directory Studio - http://directory.apache.org/studio/
 
 
 
[[Category:Unit testing]]
 

Latest revision as of 06:20, 16 October 2015

NOT UPDATED ANY MORE!!! This step-by-step guide is intended for developers only, it cannot be used for production servers!

No special installation instructions are required for installation of PHPUnit on OS X.