小皮博客 | Xiaopi's Blog

3-Lighttpd+PHP5+slqite3搭建轻量级Web生产环境

Lighttpd+PHP5+slqite3搭建轻量级Web生产环境,适用于需要在性能较差的机器上搭建Web服务的场景

1.安装sqlite3

下载安装包,解压缩

./configure

1
2
3
4
5
6
...
configure: creating ./config.status
config.status: creating Makefile
config.status: creating sqlite3.pc
config.status: executing depfiles commands
config.status: executing libtool commands

安装

sudo apt-get install make
make

1
2
3
4
...
=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DHAVE_FDATASYNC=1 -DHAVE_USLEEP=1 -DHAVE_LOCALTIME_R=1 -DHAVE_GMTIME_R=1 -DHAVE_DECL_STRERROR_R=1 -DHAVE_STRERROR_R=1 -DHAVE_POSIX_FALLOCATE=1 -I. -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_RTREE -g -O2 -c shell.c
/bin/bash ./libtool --tag=CC --mode=link gcc -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_RTREE -g -O2 -o sqlite3 shell.o ./libsqlite3.la -ldl -lpthread
libtool: link: gcc -D_REENTRANT=1 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_RTREE -g -O2 -o .libs/sqlite3 shell.o ./.libs/libsqlite3.so -ldl -lpthread

make install

1
2
3
4
5
6
7
8
9
10
11
12
13
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
/bin/mkdir -p '/usr/local/bin'
/bin/bash ./libtool --mode=install /usr/bin/install -c sqlite3 '/usr/local/bin'
libtool: install: /usr/bin/install -c .libs/sqlite3 /usr/local/bin/sqlite3
/bin/mkdir -p '/usr/local/include'
/usr/bin/install -c -m 644 sqlite3.h sqlite3ext.h '/usr/local/include'
/bin/mkdir -p '/usr/local/share/man/man1'
/usr/bin/install -c -m 644 sqlite3.1 '/usr/local/share/man/man1'
/bin/mkdir -p '/usr/local/lib/pkgconfig'
/usr/bin/install -c -m 644 sqlite3.pc '/usr/local/lib/pkgconfig'
make[1]: Leaving directory `/opt/lightServer/sqlite-autoconf-3080803'

sqlite基本操作

root@ubuntu:/opt/lightServer/sqlite-autoconf-3080803# sqlite3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
SQLite version 3.8.8.3 2015-02-25 13:29:11
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> exit
...> .exit
...> ^C
...> ;
Error: near "exit": syntax error
sqlite> .exit
root@ubuntu:/opt/lightServer/sqlite-autoconf-3080803# cd ..
root@ubuntu:/opt/lightServer# ls
sqlite-autoconf-3080803
root@ubuntu:/opt/lightServer# sqlite3 shengl
SQLite version 3.8.8.3 2015-02-25 13:29:11
Enter ".help" for usage hints.
sqlite> .databases
seq name file
--- --------------- ----------------------------------------------------------
0 main /opt/lightServer/shengl
sqlite> create table mytable(id,name,age);
sqlite> create table user(id,name,age);
sqlite> INSERT INTO user(id,name,age) VALUES(1,"shengl",25);
sqlite> SELECT * FROM user;
1|shengl|25
sqlite> .mode column
sqlite> SELECT * FROM user;
1 shengl 25
sqlite> .header on
sqlite> SELECT * FROM user;
id name age
---------- ---------- ----------
1 shengl 25
sqlite> .exit
root@ubuntu:/opt/lightServer# sqlite3 shengl
SQLite version 3.8.8.3 2015-02-25 13:29:11
Enter ".help" for usage hints.
sqlite> .databases
seq name file
--- --------------- ----------------------------------------------------------
0 main /opt/lightServer/shengl
sqlite> .tables
mytable user
sqlite>

安装lighttpd

sudo apt-get install libpcre3-dev zlib1g-dev libbz2-dev
./configure

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
config.status: executing libtool commands

Plugins:

enabled:
mod_access
mod_accesslog
mod_alias
mod_auth
mod_cgi
mod_compress
mod_dirlisting
mod_evhost
mod_expire
mod_extforward
mod_fastcgi
mod_flv_streaming
mod_indexfile
mod_proxy
mod_redirect
mod_rewrite
mod_rrdtool
mod_scgi
mod_secdownload
mod_setenv
mod_simple_vhost
mod_ssi
mod_staticfile
mod_status
mod_trigger_b4_dl
mod_userdir
mod_usertrack
mod_webdav
disabled:
mod_cml
mod_magnet
mod_mysql_vhost

Features:

enabled:
auth-crypt
compress-bzip2
compress-deflate
compress-gzip
large-files
network-ipv6
regex-conditionals
disabled:
auth-ldap
network-openssl
stat-cache-fam
storage-gdbm
storage-memcache
webdav-locks
webdav-properties

make & make install

1
2
3
4
5
6
7
make[1]: Leaving directory `/opt/lightServer/lighttpd-1.4.35/tests'
make[1]: Entering directory `/opt/lightServer/lighttpd-1.4.35'
make[2]: Entering directory `/opt/lightServer/lighttpd-1.4.35'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/opt/lightServer/lighttpd-1.4.35'
make[1]: Leaving directory `/opt/lightServer/lighttpd-1.4.35'

sudo apt-get install lighttpd
vim /etc/lighttpd/lighttpd.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
server.modules = (
"mod_access",
"mod_alias",
"mod_compress",
"mod_redirect",
"mod_rewrite",
)

server.document-root = "/var/www"
server.upload-dirs = ( "/var/cache/lighttpd/uploads" )
server.errorlog = "/var/log/lighttpd/error.log"
server.pid-file = "/var/run/lighttpd.pid"
server.username = "www-data"
server.groupname = "www-data"
server.port = 2180


index-file.names = ( "index.php", "index.html", "index.lighttpd.html" )
url.access-deny = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

compress.cache-dir = "/var/cache/lighttpd/compress/"
compress.filetype = ( "application/javascript", "text/css", "text/html", "text/plain" )

# default listening port for IPv6 falls back to the IPv4 port
## Use ipv6 if available
#include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"

/opt/lightServer/lighttpd/sbin/lighttpd -f lighttpd.conf # 使用前面配置的配置文件

安装PHP

./configure \
–prefix=/opt/lightServer/php5 \
–enable-cgi \
–enable-force-cgi-redirect \
–enable-soap \
–enable-sockets \
–enable-sqlite-utf8

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+

Thank you for using PHP.

config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
configure: WARNING: unrecognized options: --enable-fastcgi, --enable-force-cgi-redirect, --enable-sqlite-utf8

make
make & make install
修改lighttpd配置文件 vim /etc/lighttpd/lighttpd.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
server.modules += ("mod_fastcgi")

fastcgi.server =( ".php" =>
((
"socket" => "/tmp/php.socket",
"bin-path" => "/usr/local/php5/bin/php-cgi",
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "16",
"PHP_FCGI_MAX_REQUESTS" => "10000"
),
"min-procs" => 1,
"max-procs" => 1,
"idle-timeout" => 20
))
)

/usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf

浏览器中访问http://localhost:2180/lighttpd.php,效果如标题图所示

<!–

阅读量
–>

版权声明

本文标题:3-Lighttpd+PHP5+slqite3搭建轻量级Web生产环境

文章作者:盛领

发布时间:2015年02月27日 - 00:25:55

原始链接:http://blog.xiaoyuyu.net/post/6eaca5ac.html

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

如您有任何商业合作或者授权方面的协商,请给我留言:sunsetxiao@126.com

盛领 wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
坚持原创技术分享,您的支持将鼓励我继续创作!