FreeBSD: Lighttpd + MySQL + PHP

From Wiki³
Jump to: navigation, search

IconUNDER CONSTRUCTION: The code monkeys are on the loose! Check back for updates!
# $Id: Lighttpd-HOWTO,v 1.6 2009/10/18 07:00:30 k Exp $
# Lighttpd + MySQL + PHP HOWTO


  Begin the installation of the first daemon, mysql. You will need to 
  build the default permissions database, add mysql to the startup at 
  boot, and set the MySQL root password. When done go ahead and start 
  the daemon. Note that 'yourpassword' should represent your password 
  of choice and not actually 'yourpassword'.

	www# cd /usr/ports/databases/mysql51-server/ && make \
		BUILD_OPTIMIZED=yes install clean
	www# /usr/local/bin/mysql_install_db
	www# chown -R mysql:mysql /var/db/mysql/
	www# echo 'mysql_enable="YES"' >> /etc/rc.conf
	www# cp /usr/local/share/mysql/my-medium.cnf \
	www# chown mysql:wheel /var/db/mysql/my.cnf
	www# $EDITOR /var/db/mysql/my.cnf
		Add under 'port' the line 'bind-address ='
	www# /usr/local/etc/rc.d/mysql-server start
	www# /usr/local/bin/mysqladmin -u root password yourpassword


  Continue via installing lighttpd from the ports collection. Then 
  setup a very basic daemon configuration file. The only lines in the 
  config that need your attention are the ones shown below.

	www# cd /usr/ports/www/lighttpd/ && make install clean
	www# $EDITOR /usr/local/etc/lighttpd.conf

	server.modules		= (
		"mod_redirect" )
	server.document-root	= "/usr/local/www/_base/"
	server.errorlog		= "/usr/local/www/lighttpd.error.log"
	index-file.names	= ( "index.php", "index.html",
				    "index.htm", "default.htm" )
	server.event-handler	= "freebsd-kqueue"
	accesslog.filename	= "/usr/local/www/lighttpd.access.log"
	fastcgi.server = ( ".php" => ( "localhost" => (
		"socket" => "/var/run/lighttpd/php-fastcgi.socket",
		"bin-path" => "/usr/local/bin/php-cgi"
	) ) )
	cgi.assign		= ( ".pl"  => "/usr/bin/perl",
				    ".cgi" => "/usr/bin/perl" )
	include			"/usr/local/etc/lighttpd-mime.conf"
	include			"/usr/local/etc/lighttpd-vhosts.conf"

  If you notice I have included I file for all my mime's and removed 
  them from the main config file for readability sake. There is also 
  a file included at the end for all of your vhosts. I won't get too 
  far into detail about vhost setup but I will leave you with the 
  following example.

	$HTTP["host"]	== "" {
		server.document-root = "/usr/local/www/sub1/"
		server.dir-listing = "disable"
		server.error-handler-404 = "/?404"
	$HTTP["host"]	== "" {
		server.document-root = "/usr/local/www/sub2/"

  Make the directories for document-root and logs, set permissions, 
  and then start the daemon. Be sure to also make directories that 
  match any virtual hosts that you may or may not have added.

	www# mkdir -p /usr/local/www/_base/ /usr/local/www/_log/ \
	www# touch /var/run/lighttpd/php-fastcgi.socket
	www# chown -R www:www /usr/local/www/ /var/run/lighttpd/
	www# /usr/local/etc/rc.d/lighttpd start


  Install php5 & php5-extensions from the ports tree. Make sure the 
  following options are used when building.

	www# cd /usr/ports/lang/php5/ && make WITH_MULTIBYTE=yes \
		WITHOUT_IPV6 install clean
	www# cd /usr/ports/lang/php5-extensions/
	www# make config-recusive

		Add Options: +BZ2 +CURL +FTP +GD +MCRYPT +MHASH

	www# make install clean

  Set the standard configuration file for php and then install the 
  eAccelerator PHP extension. Add the extension into the php.ini. 
  Note that actual location of extension if printed on screen at the 
  end of eAccelerator install.

	www# cp /usr/local/etc/php.ini-recommended \
	www# cd /usr/ports/www/eaccelerator/ && make install clean
	www# $EDITOR /usr/local/etc/php.ini

	; Dynamic Extensions ;

  [4] FINISH!

  Now that the web server is installed go ahead and restart the web 
  daemon. Then feel free to add mysql user accounts as necessary.

	www# /usr/local/etc/rc.d/lighttpd reload
	www# mysql -p
	mysql> GRANT ALL ON db.* TO [email protected] \
		IDENTIFIED BY 'yourpassword';
	mysql> \q