Abstract In this article, we will start to solve the problems that will be encountered in the process of building a database-driven website. And we will only use two new tools, PHP and MySQL. If your web host supports PHP/MySQL, you will save yourself a lot of trouble. If not, don't worry, we'll also learn how to install the corresponding programs under Unix and Windows. This article is intended for intermediate and advanced web designers who may be able to learn server-side program development. We assume that our readers are familiar with HTML, so we won't give any explanation when using HTML. In addition, we may use a small amount of JavaScript in some places, but we will try to ensure that it is simple enough even for novices. (2002-08-29 14:10:35) ----------------------------------------------- --------------------------------------------- By Wing, Source: Linuxaid Original: Kevin Yank Translation: Everywhere For today's Web, content is the most important. When you are proficient in HTML and have learned some tricks with JavaScript and DHTML, you may now be able to design a beautiful website that will make people fall in love at first sight. The next step is to add some real information to the page. Many sites have to be constantly updated to successfully attract repeat visitors. In traditional website building, this means constantly updating numerous HTML files. Now the problem arises. In more cases, the person who provides content to the site is not the person who designed the web page. The provider of the content doesn't even know HTML yet. So how does the content provider add content to the website? Not all companies have a full-time Webmaster, and it is really a waste to have a Webmaster busy copying Word files into HTML templates all day long. Maintaining a text-driven site is a real pain. Many sites (yours included?) are plagued by outdated information. Because to ensure that the information is updated normally, you will have to rewrite hundreds of HTML files. Server-side includes (SSI: commands or pointers in HTML files that can be called via comment lines) may alleviate some of the trouble. But you still have to deal with hundreds of HTML files, even if you just want to make some basic changes to your site. The solution to these headaches is to design a database site. By keeping your site's content and settings completely separate, you can work on one without affecting the other. You will no longer need to write an HTML page for each piece of information, you only need to write an HTML page for a type of information. You no longer need to constantly add new content to your pages. All you have to do now is to build a simple information management system through which authors can add new content themselves without going through HTML. In this article, we will start to solve the problems that will be encountered in the process of building a database-driven website. And we will only use two new tools, PHP and MySQL. If your web host supports PHP/MySQL, you will save yourself a lot of trouble. If not, don't worry, we'll also learn how to install the corresponding programs under Unix and Windows. This article is intended for intermediate and advanced web designers who may be able to learn server-side program development. We assume that our readers are familiar with HTML, so we won't give any explanation when using HTML. In addition, we may use a small amount of JavaScript in some places, but we will try to ensure that it is simple enough even for novices. After reading this article, you should have understood how to build a database-driven website, and you should have basically learned PHP and SQL. Most importantly, you'll learn how to start building your own database-driven website. Chapter 1: Installation Preface First of all, thank you for reading this tutorial! Over the next few months, I'll take you beyond client-side design into the world of HTML and JavaScript. Text-driven websites are so successful right now, and what we have to learn here is how to solve the problem of maintenance. Before we begin, it is necessary for us to understand the two tools we need for our work. In Chapter 1, we will learn to download and install the two software packages we will use: PHP and MySQL. PHP is a server-side scripting language. You can think of it as a "plug-in". Through this "plug-in", your web server can no longer just send out a text web page after receiving a request from the browser. After installing PHP, your web server can read a new type of file (PHP script). Through this file, the server can read real-time information from the database and add it to the database before responding to the browser's request. Go to the Web page. PHP is completely free, you can download and use it freely. To get information from a database, you first need to have a database, and then we have to mention MySQL. MySQL is a relational database management system (RDBMS). What role it plays and how it works will be explained in detail below.Basically, it is a software package that can organize and manage large amounts of data very well. MySQL also makes it easy to retrieve information through server-side scripting languages like PHP. Non-commercial applications of MySQL for Unix-based platforms (such as Linux) are free. If you are lucky, your web host may have installed MySQL and PHP for you. If this is the case, some of the chapters will not be useful to you and you can skip directly to If your web host offers PHP and MySQL. Most of what we discuss in this tutorial applies to Windows-based or Unix-based servers. However, the installation process will be different depending on the type of server you are using. The next section explains how to install it on a Windows-based Web server. The following section explains how to install it under Linux (and other Unix-based platforms). If you are not particularly interested in the installation process, you just need to read the section that applies to you. To install under Windows you can go to http://www.mysql.com/ (or one of the mirror sites listed at http://www.mysql.com/mirrors.html) and select Downloads for Windows MySQL related software ->Downloads->Register and download shareware version of MySQL-Win32. After downloading the file, unzip it and run the setup.exe in it. After you install it, MySQL is ready to use (excluding some configuration we will perform soon). Like your Web service, MySQL is a service that can run in the background, so it can respond to requests for information at any time. You can find this service program in the bin subdirectory of the directory where you installed MySQL. If you are using a shared version, this service is called mysqld-shareware.exe. Before executing, rename it to mysqld.exe. At the MS-DOS prompt, start this service with the following command: C:mysql in> mysqld To ensure that this service is started when Windows starts, you need to create a shortcut and add it to the startup program group. In addition, you can also install it as a service on Windows NT/2000 with this command: C:mysql in> mysqld-nt --install If you have problems running the shared version under Windows NT/2000, you can try stand-alone mode Run this service: C:mysql in> mysqld --standalone The next step is to install PHP. At the time of writing this tutorial, PHP 4.0 is basically mature. I myself have tried PHP 4.0-RC2 and encountered no problems. It is estimated that the final stable version will be released soon (perhaps we have not finished writing this tutorial by then). I recommend that you install the latest version so that you will not need to make any changes when the official version comes out. PHP can be downloaded for free from http://www.php.net/ (or one of the mirror sites listed at http://www.php.net/mirrors.php). You need the "binaries for Win32" package. You can get a good installation guide for PHP 3.0 for Windows at: http://www.umesd.k12.or.us/php/win32install.html. You may need to upgrade when PHP 4.0 is finally released, but installation for 4.0 is basically the same as for 3.0. You won't have any trouble depending on which version you choose. After MySQL and PHP are installed, you can enter the installation configuration. Installation under Linux This section describes the process of installing PHP and MySQL under RedHat Linux. If you are using a different version of Linux, or another Unix-based operating system, the steps are very similar, if not identical. As a user of RedHat Linux, you may be interested in downloading and installing the RPM distributions of PHP and MySQL. RPM is indeed excellent and the pre-packaged software is very easy to install. Unfortunately, they also limit your options for how to configure the software. For this reason, I think using the RPM versions of PHP and MySQL is more trouble than it's worth. Because some of the default configurations of RedHat Linux will automatically install PHP for you, the first step is to remove the old versions of PHP and MySQL from your system. You need to be logged in as superuser to execute the following commands. Note that in the following command, "%" represents the shell prompt, which does not require you to enter it. % rpm -e mysql % rpm -e php If these two commands or one of them shows that the program is not installed, don’t worry. If the second command is executed successfully (that is, no information is displayed), then it proves that an older version of PHP is indeed installed and you must completely remove it. Use your favorite text editor to open the Apache configuration file (usually /etc/httpd/conf/httpd.conf) and look for the following two lines. These two lines are usually in different places in the file, so if these two lines are not together, there is really nothing to worry about. LoadModule php3_module modules/libphp3.so AddModule mod_php3.c These two lines are used to tell Apache to load PHP as a plug-in module. When you uninstall this module, you still need to delete these two lines to ensure that Apache works properly. You can also add (#) at the beginning of these two lines to make them comments.To make sure Apache is still working properly, you must now restart it without the PHP plugin: % /etc/rc.d/init.d/httpd stop % /etc/rc.d/init.d/httpd start Everything After everything is arranged, you are ready to download and install MySQL and PHP. Installing MySQL under Linux The version of MySQL for Linux is free and you can download it from the mirror sites listed at http://www.mysql.com/ (or http://www.mysql.com/downloads/mirrors.html 1) Download the last stable version (listed in "recommended" on the download page). You should get the version from "tarball source download" and its file name is mysql-version.tar.gz. After downloading the file, you must be sure to log in as superuser to install it, unless you only want to install MySQL in your own home directory. Begin to unpack the downloaded file and enter the directory you just created: % tar xfz mysql-version.tar.gz % cd mysql-version Next you need to configure the MySQL installation. Unless you are absolutely sure, you need to specify the installation directory. I recommend using /usr/local/mysql: % ./configure --prefix=/usr/local/mysql After testing the monitor and monitor configuration, you will eventually be returned to the command prompt. Now you can compile MySQL: % make After compiling, you will be returned to the command prompt. Now you can install your newly compiled program: % make install MySQL is now installed, but