FreeBSD: Lighttpd + MySQL + PHP
From Wiki³
UNDER CONSTRUCTION: The document is currently being modified! |
<nowiki> # $Id: Lighttpd-HOWTO,v 1.6 2009/10/18 07:00:30 k Exp $ # # Lighttpd + MySQL + PHP HOWTO [1] MYSQL SETUP 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 \ /var/db/mysql/my.cnf www# chown mysql:wheel /var/db/mysql/my.cnf www# $EDITOR /var/db/mysql/my.cnf Add under 'port' the line 'bind-address = 1.2.3.4' www# /usr/local/etc/rc.d/mysql-server start www# /usr/local/bin/mysqladmin -u root password yourpassword [2] LIGHTTPD 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_access", "mod_accesslog", "mod_cgi", "mod_fastcgi", "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"] == "sub1.domain.com" { server.document-root = "/usr/local/www/sub1/" server.dir-listing = "disable" server.error-handler-404 = "/?404" } $HTTP["host"] == "sub2.domain.com" { 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/ \ /var/run/lighttpd/ 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 [3] PHP5 AND EXTENSIONS 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 +MYSQL +MYSQLI +ZIP +ZLIB 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 \ /usr/local/etc/php.ini www# cd /usr/ports/www/eaccelerator/ && make install clean www# $EDITOR /usr/local/etc/php.ini ;;;;;;;;;;;;;;;;;;;;;; ; Dynamic Extensions ; ;;;;;;;;;;;;;;;;;;;;;; zend_extension="/usr/local/lib/php/20060613/eaccelerator.so" [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 username@localhost \ IDENTIFIED BY 'yourpassword'; mysql> FLUSH PRIVILEGES; mysql> \q ------------------------------------------------------------------------ [A] REFERENCES http://redmine.lighttpd.net/wiki/lighttpd/Docs:Configuration http://dev.mysql.com/doc/refman/5.1-maria/en/adding-users.html
</nowiki>