"Debian Server Settings Getting Started" series tutorial first chapter
Blue forest http://www.lslnet.com, November 29, 2002 16:04
Author: kanaka [Cold Gang China] Contact: kanaka @ yeah.net, leng haier.com @ version: 0.2.1 Copyright: GPL Last Review: November 26, 2002
List
Forehead
Chapter 1 Configuring Apache MySQL PHP4 on Debian
Chapter II configure the FTP server with WU-FTPD on Debian
Chapter 3 Configuring the Mail Server with EXIM on Debian
Chapter 4 Configures Samba Server on Debian
Chapter 5 Configures DNS Server with BIND on Debian
The first chapter of the "Debian Server Settings" series of tutorials: Web Server Database Server
Chapter 1 Configuring Apache MySQL PHP4 on Debian
This chapter directory
1 Select Apache MySQL PHP4
2 installation
3 configuration
4 comprehensive test
5 Conclusion
1 Select Apache MySQL PHP4 You may ask me: Why don't you choose other software, not to choose the combination of Apache MySQL PHP4? Oh, I want to tell you, the famous Free Lamp combination is Linux / Apache / MySQL / PHP / Perl / Python, you can go to www.freeeelamp.com to see. The application of PHP on the Internet is being brought into the power. If you make Web development, in my opinion, don't choose, it is PHP. Details can be found on www.php.net. MySQL is very light, performance excellent. Apache doesn't have to say more, there are no several web sites on the Internet don't need it. 2 Installing software installed on Debian is really simple. No need for Configure, do not need Make, do not need Make Install, the staff of Debian around the world has done everything. You can put all these software all in a breath:
# APT-GET Install Apache PHP4 PHP4-GD PHP4-MySQL MySQL-Server MySQL-Client
Among them, PHP-GD is a great graphics library. If you don't need to use a PHP to generate a dynamic picture, it is not to be installed. At this time, the system will automatically list some related software, and then ask you to continue (say Debian, this is one point: automatic lookup software association, automatic supplementation) - Debian gives you a chance to repent, if You don't want to install it now, then press N, you will return it. Of course, we have to press Enter and continue to install. Now Debian will download these software to the site you specified in your Sources.list. After downloading, you will automatically configure it. You will ask for your advice during the configuration process, ask you a few questions. For example, now he ask you: Do you want to run mysql when you start? Of course, I'm choose Yes, otherwise I will start every time I have to use it. Ask you: Do you want to run apacheconfig scripts? The default is n, but we entered Y to configure it for us. After configuring, ask if you save the configuration, of course, huh, huh. Then, he will ask if you want to launch Apache, ok, start it. Next, the system will automatically configure PHP. Since you have selected PHP-GD and PHP-MySQL, he will ask if you write GD.so and mysql.so to php.ini, answer is. Look, Debian is smart. 3 Configuration 3.1 Configuration Apache3.1.1 Provides PHP Support Apache just installing PHP support. When you click on a .php script, the browser will download this script :-( Modify /etc/apache/httpd.conf to provide PHP support. Run: # nano /etc/apache/httpd.conf
By the way, I really like this editor called Nano, it is easy to get started. Find this line using NANO's Ctrl W function:
# Loadingmodule php4_module /usr/lib/apache/1.3/libphp4.so
Remove the front of this line so that Apache loads this libphp4.so module. Then, configure the default page, find:
DirectoryIndex index.html index.htm index.shtml index.cgi
Change to:
DirectoryIndex index.php index.php3 index.html index.htm index.shtml index.cgi
Then add the .php3 extension support and PHP source code support, find:
## and for php 4.x, use: ## addtype application / x-httpd-php .php # addtype coplication / x-httpd-php-source .phps
Modify the back two lines:
## and for php 4.x, use: #addtype application / x-httpd-php .php .php3addtype application / x-httpd-php-source .phps
3.1.2 Modifying the default character set Let Apache use Simplified Chinese as the default character set. Find this line:
AddDefaultcharset on ADDDEFAULTCHARSET ON
changed to:
AdddefaultCharset GB2312
Ok, Apache is configured, press Ctrl O, press Ctrl X to exit NANO. In order to make our changes, you need to restart Apache, run: # apachectl restart
Apache 1.3 provides this ApachectL tool, but 2.0 is gone. Also, pay attention to a trick: The server package provided by Debian will provide a script to start / terminate / restart this service. All scripts are all in /etc/init.d/ below. For example, Apache, can be controlled by the following command:
# /etc/init.d/apache restart
Other services can also be operated.
3.2 MySQL Configuration 3.2.1 Modify Mysql Password Because MySQL has no password, for security, you must modify your password! Let's take a look at your MySQL is really no password:
$ mysqladmin Version
If you can see MySQL version information, prove that mysql has no password. Ok, run the mysqladmin password xxxxxx to modify your password:
# mysqladmin Password XXXXXX
Here XXXXXX is your new password. Now you need to run mysqladmin version --user = root --pass, then enter the password to view the version number and other information. Note that the -user = root -pars in the above command can be short-written as -u root -p. Let's test it, see if the password is effective:
# mysqladmin version --u root -penter password:
3.2.2 Opening 3306 Port Listening This work should be cautious. In terms of safety, by default, Debian turns off 3306 port. Because many hackers attacked your system through it. If you don't access the database through other machines, don't open this port. Modify /etc/mysql/my.cnf, find:
SKIP-NETWORKING
Comment it out:
# Skip-networking
3.2.3 Modifying the default character set Let MySQL use Simplified Chinese as the default character set. Edit /etc/init.d/mysql, find this line:
/ usr / bin / safe_mysqld> / dev / null 2> & 1
Change to:
/ usr / bin / safe_mysqld> --default-character-set = GB2312> / dev / null 2> & 1 & 1
Ok, restart MySQL:
# /etc/init.d/mysql restart
3.3 PHP configuration
Mainly to modify the default character set of PHP and change it into Simplified Chinese. Edit /etc/php4/apache/php.ini:
# nano /etc/php4/apache/php.ini
Find; default_charset = "ISO-8859-1" this line:
; default_charset = "ISO-8859-1"
Remove the previous semicolons and change: default_charset = "GB2312"
Default_Charset = "GB2312"
4 Comprehensive test is ok, installed, let's test it. This part, the master can be skilled. I mainly considering beginners, I wrote this. 4.1 Creating a Database Let's create a simple database. There is only one table in this library called User to store username / express password / birth dates / activation. # Mysql -u root -pEnter password: mysql> CREATE DATABASE mytest; Query OK, 1 row affacted (0.00 sec) mysql> USE mytest; Database changed mysql> CREATE TABLE user (-> username varchar (16) NOT NULL default ', 1975-12-31', 1975-12-31 ', 1975-12-31', ', , 0); Query OK, 1 ROW Affected (0.01 Sec) MySQL> INSERT INTO USER VALUES ('ATFA', 'Atfapswd', '1977-10-30', 1); Query Ok, 1 Row Affected (0.00 sec) Mysql> quitbye
Note that by default, all databases are placed on / var / lib / mysql / below. Each database accounts for a directory, the directory name is the database name. When you create a database, the system automatically puts it below this directory. 4.2 Write a PHP Script Let's write a simple PHP script to call the contents of the above database. File names are called MyTest.php.
php $ dbname = 'mytest'; $ TABLENAME = 'user'; $ Page = 0; $ rowperpage = 20; mysql_connect ("localhost", "root", "your password"); // below this ViewData function It is a copy of yourself, used to show data // to some extent, this program is a key role: ViewData ($ DBNAME, $ TABLENAME, $ PAGE, $ ROWPAGE); //// Just define two functions, you don't want to see him /////// define a function, used to return query statly function echoqueryResult () {Global $ querystr, $ errmsg; ife ($ errmsg == " ") $ errmsg =" success "; if ($ querystr! =") {echo "
query: td> | $ querystr td> tr> / n "; echo" | |||||
Result: td> | $ errmsg td> tr> / n "; echo" table> < P> / N ";}} // Define a function to display data Function ViewData ($ DBNAME, $ TABLENAME, $ PAGE, $ ROWPAGE) {Global $ mysqlhandle, $ PHP_SELF, $ Errmsg, $ Orderby; Echo < H2> Below is the data you check: h2> / n "; $ querystr = StripsLashes ($ querystr); if ($ querystr ==") {$ querystr = "SELECT * from $ TABLENAME"; if ( $ ORDERBY! = "" "$ querystr. =" ORDER BY $ ORDERBY "; $ PRESULT = mysql_db_query ($ dbname, $ querystr); $ errmsg = mysql_error (); $ globals [querystr] = $ queryStr; if ($ PRESULT == false) {echoqueryResult (); return;} if ($ preSult == 1) {$ Errmsg = "success"; echoqueryResult (); return;} echo " / n"; $ row = mysql_num_rows ($ put); $ col = mysql_num_fields ($ presult); if ($ row == 0) {echo "no data! The form is empty. ";}}}} ($ rowperpage ==") $ rowperpage = 20; if ($ page == ") $ Page = 0; Else $ page -; mysql_data_seek ($ PRESULT, $ Page * $ ROWPAGE) Echo "
|