Build lighttpd + php + sqlite and lighttpdsqlite on the linux ora linux platform
(1) lighttpd
1. Install
Yum install lighttpd
After the installation is complete, the system should have one more user lighttpd and a group lighttpd. This user is not allowed to log on by default.
Modify/etc/passwd to the following form.
Lighttpd: x: 489: 470: lighttpd web server:/home/lighttpd/:/bin/bash
Note that the number you see may not be 489,470. It doesn't matter, and you don't need to change it. Keep the original value.
2. Create a directory for lighttpd users and put the website content in
Mkdir/home/lighttpd
Chown lighttpd: lighttpd/home/lighttpd
Create Sub-directories and add them to the website.
Note that all operations in the/home/lighttpd directory are performed as lighttpd users. Otherwise, permission issues may occur during lighttpd running.
Su lighttpd
Cd/home/lighttpd
Mkdir www
Mkdir www/cgi-bin
Mkdir www/databases
Mkdir www/images
Mkdir www/log
Now, you can put content in various directories, such as web pages, images, php scripts, and sqlite database files.
Put index.html In the www directory.
3. Configuration
Modify the configuration file/etc/lighttpd. conf of lighttpd.
A) Enable the cgi function.
You can also enable other functions as needed. The modified server. modules is as follows.
Server. modules = (
"Mod_rewrite ",
"Mod_redirect ",
# "Mod_alias ",
"Mod_access ",
# "Mod_trigger_b4_dl ",
# "Mod_auth ",
# "Mod_status ",
# "Mod_setenv ",
# "Mod_fastcgi ",
# "Mod_proxy ",
# "Mod_simple_vhost ",
# "Mod_evhost ",
# "Mod_userdir ",
"Mod_cgi ",
"Mod_compress ",
# "Mod_ssi ",
"Mod_usertrack ",
# "Mod_expire ",
# "Mod_secdownload ",
# "Mod_rrdtool ",
"Mod_accesslog ")
B) default file name
Add default. xxx here.
Index-file.names = ("index. php", "index.html ",
"Index.htm", "default.htm", "default. php ")
C) set some paths
Server.doc ument-root = "/home/lighttpd/www /"
# Where to send error-messages
Server. errorlog = "/home/lighttpd/www/log/error. log"
Accesslog. filename = "/home/lighttpd/www/log/access. log"
#### Add the path of the php parser
Cgi. assign = (". pl" => "/usr/bin/perl ",
". Php" => "/usr/bin/php-cgi ")
4. Start lighttpd
Service lighttpd start
5. Set lighttpd to automatically start upon startup
Chkconfig -- add lighttpd
(2) sqlite
This is simple. Just install it.
Yum install sqlite
(3) php
1. Compile and install
Download the php source code package
Http://ar2.php.net/distributions/php-5.6.3.tar.bz2
Copy the source code package to the/root directory
Then go to the/root directory and execute the following command sequence:
Tar-xjf php-5.6.3.tar.bz2
Cd php-5.6.3
. /Configure -- prefix =/usr -- with-config-file-path =/etc -- enable-libxml -- with-libxml-dir =/usr/lib -- with-sqlite3 -- enable-pdo -- with-pdo-sqlite CLAGS =-O2
Make; make install
Note that this compilation method supports the pdo Method for accessing sqlite3. This method does not require any extension.
(4) test
A)
Use a lighttpd user to enter the/home/lighttpd/www/databases directory and create a database
[Lighttpd @ localhost databases] $ sqlite3 test. db
SQLite version 3.6.22
Enter ". help" for instructions
Enter SQL statements terminated with ";"
Sqlite> create table my_friends (name varchar (10), age smallint );
Sqlite> insert into my_friends values ('Tom ', 22 );
Sqlite> insert into my_friends values ('liany', 21 );
Enter ctrl + d to exit sqlite shell
B) Use lighttpd to enter the cig-bin directory and create a php script haha. php with the following content:
<! DOCTYPE html>
<Html>
<Body>
<? Php
// Phpinfo ();
Echo "hello my first php script \ n ";
Echo getcwd ();
$ File_db = new PDO ('sqlite: ../databases/test. db ');
$ Result = $ file_db-> query ('select * FROM my_friends ');
Foreach ($ result as $ row)
{
Echo "name:". $ row ['name']. "";
}
?>
</Body>
</Html>
C) use a browser to access haha. php :)
Http: // ip_of_lighttpd/cgi-bin/haha. php
If you encounter problems when debugging the php program, you can enable/etc/php. ini and set the following content to enable the php error reporting function:
Error_reporting = E_ALL &~ E_NOTICE
Display_errors = On