Build a lightweight server environment Lighttpd + MySQL + PhP (FAST-CGI)

Source: Internet
Author: User
Tags zts

Lighttp is a new web server software with high security, efficiency, and compatibility. Compared with Apache, Lighttpd features a very low memory usage and a very fast response speed. Today, I configured it on Linux. I 'd like to share it with you here. The following software packages must be pre-installed before Lighttpd is installed:

PCRE
Zlib
PCRE-devel
Zlib-devel

1. install and configure Lighttpd

1.1 create a user and group that runs Lighttpd

# Groupadd Lighttpd
# Useradd-G Lighttpd-S/sbin/nologin-D/dev/null Lighttpd

1.2 start Lighttpd Installation

# Wget http://www.lighttpd.net/download/lighttpd-1.4.8.tar.gz
# Tar-zxvf lighttpd-1.4.8.tar.gz
# Cd lighttpd-1.4.8
#./Configure -- prefix =/usr/local/Lighttpd

# Make
# Make install

# Mkdir/usr/local/Lighttpd/Conf
# Mkdir/usr/local/Lighttpd/log

# Mv./doc/Lighttpd. CONF/usr/local/Lighttpd/CONF/
# Cp./doc/rc. Lighttpd. RedHat/etc/init. d/Lighttpd

1.3 configure Lighttpd

# Vi/usr/local/Lighttpd/CONF/Lighttpd. conf
=========================== ==========
Server. Modules = (
"Mod_rewrite ",
"Mod_redirect ",
"Mod_access ",
"Mod_fastcgi ",
"Mod_compress ",
"Mod_accesslog ")
# $ HTTP ["url"] = ~ "/. Pdf $ "{
# Server. Range-Requests = "Disable"
#}

Server.doc ument-root = "/usr/local/Lighttpd/html"
Server. errorlog = "/usr/local/Lighttpd/log/Lighttpd. Error. log"
Accesslog. filename = "/usr/local/Lighttpd/log/access. log"
Server. PID-file = "/var/run/Lighttpd. PID"

Server. Username = "Lighttpd"
Server. groupname = "Lighttpd"

Compress. cache-Dir = "/tmp"
Compress. filetype = ("text/plain", "text/html ")

FastCGI. Server = (". php" =>
("Localhost" =>
(
"Socket" => "/tmp/php-fastcgi.socket ",
"Bin-path" => "/usr/local/PHP-fcgi/bin/PHP"
)
)
)
=========================== ==========

# CP ../doc/spawn-php.sh/usr/local/Lighttpd/bin/
# Chown-r Lighttpd: Lighttpd/usr/local/Lighttpd

2. install and configure the MySQL server

# Yum install mysql-Server
# Yum install MySQL
# Service mysqld start

3. install and configure PHP (FAST-CGI)

3.1 download and install PHP

# CD ..
# Wget http://mirrors.easynews.com/php/php-4.3.10.tar.gz
# Tar-zxvf php-4.3.10.tar.gz
# Cd php-4.3.10
#./Configure/
-- Prefix =/usr/local/PHP-fcgi/
-- Enable-FastCGI -- With-MySQL/
-- Enable-Zend-multibyte/
-- With-config-file-Path =/etc/
-- Enable-discard-path/
-- Enable-force-CGI-Redirect

# Make
# Make install

# Cp PHP. ini-Dist/etc/PHP. ini

4. install and configure eaccelerator (PhP accelerator)

4.1 download and install eaccelerator

# CD ..
# Wget http://kent.dl.sourceforge.net/sourceforge/eaccelerator/
Eaccelerator-0.9.4-rc1.tar.bz2
# Bunzip2-D eaccelerator-0.9.4-rc1.tar.bz2
# Tar-xvf eaccelerator-0.9.4-rc1.tar
# Cd eaccelerator-0.9.4-rc1

# Export php_prefix = "/usr/local/PHP-fcgi"
# $ Php_prefix/bin/phpize
#./Configure/
-- Enable-eaccelerator = shared/
-- With-PHP-Config = $ php_prefix/bin/PHP-config
# Make
# Make install
# Cat eaccelerator. ini>/etc/PHP. ini

4.2 configure PHP Variables

# Vi/etc/PHP. ini
=========================== ==========
CGI. fix_pathinfo = 1
Extension_dir = "/usr/local/PHP-fcgi/lib/PHP/extensions //
No-debug-non-zts-20020429 /"
Zlib. output_compression = on
CGI. fix_pathinfo = 1
Eaccelerator. cache_dir = "/tmp"

//// The following describes the eaccelerator configuration ////

Zend_extension = "/usr/local/PHP-fcgi/lib/PHP/extensions/no-debug-non-zts-20020429/eaccelerator. So"
Eaccelerator. shm_size = "0"
Eaccelerator. cache_dir = "/tmp"
Eaccelerator. Enable = "1"
Eaccelerator. optimizer = "1"
Eaccelerator. DEBUG = 0
Eaccelerator. LOG_FILE = "/var/log/eaccelerator_log"
Eaccelerator. name_space = ""
Eaccelerator. check_mtime = "1"
Eaccelerator. Filter = ""
Eaccelerator. shm_max = "0"
Eaccelerator. shm_ttl = "0"
Eaccelerator. shm_prune_period = "0"
Eaccelerator. shm_only = "0"
Eaccelerator. Compress = "1"
Eaccelerator. compress_level = "9"
Eaccelerator. Keys = "shm_and_disk"
Eaccelerator. Sessions = "shm_and_disk"
Eaccelerator. content = "shm_and_disk"
Eaccelerator. admin. Name = "yourusername"
Eaccelerator. admin. Password = "yourpassword"
=========================== ==========

4.3 initialize PHP with FastCGI

# Vi/usr/local/Lighttpd/bin/spawn-php.sh
=========================== ==========
Spawnfcgi = "/usr/local/Lighttpd/bin/spawn-fcgi"
Fcgiprogram = "/usr/local/PHP-fcgi/bin/PHP"
Userid = Lighttpd
Groupid = Lighttpd
=========================== ==========

#/Usr/local/Lighttpd/bin/spawn-php.sh

5. Test

Change the path that does not match the/etc/init. d/Lighttpd file.

# Chmod 755/etc/init. d/Lighttpd
# Chown root: Root/etc/init. d/Lighttpd
# Chkconfig -- add Lighttpd
# Chkconfig Lighttpd on
# Service Lighttpd start

# Ps afx | grep PHP

12222 pts/2 S/_ grep PHP
12193? S 0: 00/usr/local/PHP-fcgi/bin/PHP
12194? S 0: 00/_/usr/local/PHP-fcgi/bin/PHP
12195? S 0: 00/_/usr/local/PHP-fcgi/bin/PHP
12196? S 0: 00/_/usr/local/PHP-fcgi/bin/PHP
12197? S 0: 00/_/usr/local/PHP-fcgi/bin/PHP
12198? S 0: 00/_/usr/local/PHP-fcgi/bin/PHP
12199? S 0: 00/_/usr/local/PHP-fcgi/bin/PHP
12200? S 0: 00/_/usr/local/PHP-fcgi/bin/PHP
12201? S 0: 00/_/usr/local/PHP-fcgi/bin/PHP
12202? S 0: 00/_/usr/local/PHP-fcgi/bin/PHP
12203? S 0: 00/_/usr/local/PHP-fcgi/bin/PHP

Put test. php In the server.doc ument-root directory and check the result in a browser.

This article Reprinted from Song's computer technology worry-free: http://www.pc51.net/server/web/apache/2007-02-25/7081.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.