Build server with DarwinPorts
From NetMusician Wiki
last updated: August 6, 2006
These instructions may not work in certain versions of OS X, since the Apple-provided Apache/mod_ssl were built against older versions of dependencies than the ones available within the DarwinPorts infrastructure. If you know of a way to circumvent this problem, please let us know
Why?
It is very easy to use Apple's supplied Apache, PHP, and MySQL services, but these services are often several versions behind the latest available from their respective open source project websites. Also, system administrators like myself appreciate making the choice themselves about when to upgrade a service, rather than simply waiting for an update from Apple and testing the provided services given such an unpredictable timetable. Administrators that are used to package management systems like FreeBSD's Ports or Gentoo's Portage will feel at home with using DarwinPorts, but unlike Ports or Portage it is often challenging putting compiled software built by these projects into production without it conflicting with Apple's preinstalled versions of these same components.
Basic Methodology
In this tutorial, we will replace everything but the included Apache install. This will allow us to continue to control Apache through the GUI, including the Server Admin GUI provided with OS X Server.
Using DarwinPorts to build a OS X or OS X Server running Apache 1.x, PHP 4.x, MySQL 4.x, and phpMyAdmin
- install Apple's XCode and DarwinPorts, add "/opt/local/bin" to your Shell's path as instructed.
sudo port -v install apache(we don't really need a new install of Apache, but this helps satisfy dependencies)sudo port -v install mysql4 +serversudo port -v install php4 +apache +mysql4sudo port -v install phpmyadmin +apache +php4 +mysql4sudo ln -s /opt/local/libexec/apache/libphp4.so /usr/libexec/httpd/DP_libphp4.so- modify /etc/httpd/httpd.conf, comment out:
LoadModule php4_module libexec/httpd/libphp4.so - directly above or below this line, add:
LoadModule php4_module libexec/httpd/DP_libphp4.so(this tells Apache to use the DarwinPorts installed PHP module, rather than the included Apple module) - uncomment
AddModule mod_php4.c, also within your httpd.conf file.
If this is a new MySQL database (i.e. there are no databases/tables you wish to preserve)
cd /opt/local/binsudo -u mysql ./mysql_install_db- create a root password for MySQL as instructed
If you are migrating from an existing set of MySQL databases
sudo rsync -av /var/mysql/ /opt/local/var/db/mysql/- edit /opt/local/var/db/mysql/my.cnf , replace the datadir with: "/opt/local/var/db/mysql" , change the basedir to "/opt"
- disable Apple's MySQL in /etc/hostconfig (change MYSQL and MYSQLCOM to equal "-NO-")
Final steps
rm /opt/local/etc/rc.d/apache.sh(this prevents the DarwinPorts installed version of Apache from running)- A port called "DarwinPortsStartup" was installed automatically as a dependency. It lives in /Library/StartupItems and automatically executes the startup rc scripts located in: /opt/local/etc/rc.d. You can run this script now:
/Library/StartupItems/DarwinPortsStartup/DarwinPortsStartup start, or simply reboot your machine sudo ln -s /opt/local/www/data/phpmyadmin /Library/WebServer/Documents/phpmyadmin
You should now be able to access phpMyAdmin by going to: http://localhost/phpmyadmin (make sure that your web server is enabled in System Preferences -> Sharing -> Services in OS X client, or the Server Admin tool in OS X Server).
It is recommended that you perform these same steps on another machine, then run: sudo port -v selfupdate to download new port files, port outdated to list outdated ports, and sudo port -va upgrade to upgrade all outdated ports, or sudo port -v upgrade [portname] to upgrade specific ports (substituting for "[portname]"). This will allow you to identify problems with the upgraded services or ports themselves before deploying these upgraded services on your production machine.
How did this guide work for you? Please let us know
