Use PHP and MySQL to build a database-driven website 2

Source: Internet
Author: User
Tags php software
Adding this script to the startup transaction is a complicated task. If you are not using RedHatLinux and you are not sure about it, you 'd better ask someone you know. In RedHatLinux, execute the following command (in the MySQL directory) to complete the job: % cpshare/mysql. seSyntaxHighli

Adding this script to the startup transaction is a complicated task. If you are not using RedHat Linux and you are not sure to do this, you 'd better ask people you know. In RedHat Linux, execute the following command (in the MySQL directory) to complete the job: % cp share/mysql. server/etc/rc. d/init. d/% cd/etc/rc. d/init. d % chmod 500 mysql. server % cd/etc/rc. d/rc3.d % ln-s .. /init. d/mysql. server S99mysql % cd/etc/rc. d/rc5.d % ln-s .. /init. d/mysql. server S99mysql is now all done! To test the job, you can restart your system and request the service to see if it works properly. Install PHP in Linux. As we mentioned earlier, PHP is not an independent program. It is actually a plug-in for your Web service (probably Apache. In fact, you have three ways to install the PHP plug-in Apache: as a CGI program, Apache runs it every time it needs to process the PHP page. Compile as a module into an Apache program. Load as a module at each Apache startup. The first method is the easiest to install and configure, but Apache calls PHP as a program every time it receives a request from the PHP page. This will definitely reduce the response time of your Web server, especially when more than one request is received at the same time. The second and third methods have the same performance, but it is very likely that you have installed Apache, and you probably do not want to download it again, re-compile and reinstall it. Therefore, we use the third method. First, we start from http://www.php.net/ (Or http://www.php.net/ Download the php software package from one of the mirror sites listed in mirrors. PHP. When we were writing this tutorial, PHP 4.0 was basically mature. I have tried PHP 4.0-RC2 myself and have not encountered any problems. It is estimated that the final stable version will be released soon (we may not finish this tutorial). I suggest you install the latest version, so that you do not need to make any changes when the official version is released. Here, we install 3.0. I will note that 3.0 and 4.0 may be different during installation. The name of the file you downloaded will be php-version.tar.gz. Our first step is to unmount this file: % tar xfz php-version.tar.gz % cd php-version to install PHP as an Apache load-able module, you need Apache apxs program. A program should have been included in most Apache versions, but if you are using a copy of the RedHat Linux installation, you need to install the Apache advanced RPM Package to obtain it. You can find this software package from your RedHat CD, you can also http://www.redhat.com/ Download. By default, RedHat will install the program to/usr/sbin/apxs. If you see this file, it proves that it has been installed. During the installation process, you must log on as a super user, because it includes some changes to the Apache configuration file. The next step is to configure the PHP installer so that it knows which options to choose and where to find the programs it needs (such as Apache and MySQL ). Unless you are sure, enter the following command (in the same line): %. /configure -- prefix =/usr/local/php -- with-config-file-path =/usr/local/php -- with-apxs =/usr/sbin/apxs -- enable- track-vars -- enable-magic-quotes -- enable-debugger if you have installed PHP 3.0 (not a 4.0 or later version ), you also need to use the following additional parameters to tell it where to find MySQL in your system: -- with-mysql =/usr/local/mysql/after several screen tests on the monitor, you will return to the command prompt. The following two commands will compile and install PHP: % make install PHP is now installed in/usr/local/php (unless you pass the above. /configure's -- prefix parameter specifies different directories), you should be able to be in the same directory (unless you pass the above. /configure's -- with-config-file-path parameter specifies a different directory) find the name php. ini configuration file, PHP provides a php. ini module file, whose file name is php. ini-optimized (php in PHP3.0. ini-dist ). Copy this file to the corresponding directory: % cp php. ini-optimized/usr/local/php. for PHP 3.0: % cp php. ini-dist/usr/local/php. ini. do not worry about php for the moment. ini optimization. Now, make sure that Apache knows where to find PHP so that it can be loaded at startup. Use the familiar text editor to open your Apache httpd. conf configuration file (in RedHat Linux, in/etc/httpd/conf/httpd. conf ). Find the following line: LoadModule php4_module lib/apache/libphp4.so. if you have installed PHP 3.0, replace php4 with php3 in this line. You should be looking for a new uncommented row (not a line starting with #), rather than the line you commented out before. Generally, it is displayed together with other LoadModule lines in the file. After finding it, you need to change the path so that it can match all other LoadModule lines in the file. In RedHat Linux, this means to change this line to LoadModule php4_module modules/libphp4.so and then look for rows starting with DirectoryIndex. This line tells Apache the name of the file used to search for the development page for a given directory. Generally, you will see index.html and other file names. php and index. add php3 to this line: DirectoryIndex index.html index. cgi... index. php index. finally, add a new line at the end of the file to tell Apache which file extensions are regarded as php files: AddType application/x-httpd-php. phtml. php. after everything is done in php3, save the changes and restart your Apache service. Apache should not have any error information at startup. After installation, after both PHP and MySQL are installed, whether in Windows, Linux, or other operating systems, the first thing is to set a "root password" for MySQL ". MySQL only allows authorized users to access and operate the information stored in its database. Therefore, you must let MySQL know who is authorized and who is unauthorized. When MySQL is installed for the first time, it generates a user named "root", which can access everything without a password. Your first task is to set a password for the root user so that no one can mess up your database. You must realize the importance of MySQL. just like Web services and FTP services, any machine on the same network can access it. If you work on a computer connected to the Internet, it means that anyone in the world can try to connect to your MySQL server! You must immediately select a password that is difficult to guess! To set the root password in MySQL, enter the following command (including quotation marks) in the bin subdirectory of the MySQL installation directory ): mysqladmin-u root password "your new password" to make sure MySQL accepts this change, you must tell it to reload the list of demonstrated users and passwords: mysqladmin-u root reload: if this command displays an error message indicating that the command is inaccessible, do not worry. this only proves that the password has taken effect. To test your new password, you can request the MySQL server to tell you about its current status: mysqladmin-u root-p status. when a prompt is displayed, enter the password. You will see some simple information that includes the current status of the service. -U root parameter tells the program that you want to log on as a "root" user. The-p parameter tells the program to prompt you to enter your password before connection. The status parameter tells the program that you want to check the system status. If you need to shut down the MySQL server, you can use the following command. Note that the-u root and-p parameters here are the same: mysqladmin-u root-p shutdown. now your MySQL database system is running securely, now the rest is to configure PHP. PHP is configured using a text file named php. ini. If you install PHP in Windows, you should have copied php. ini to your Windows directory. If you use the above instructions to install PHP in Linux, you should have copied php. ini to the PHP installation directory (/usr/local/php ). Open php. ini in a text editor that you are familiar with and take a rough look. The vast majority of settings have been well described, and the vast majority of default settings can also meet your requirements. Check and confirm that your configuration matches the following: magic_quotes_gpc = Ondoc_root = extension_dir = if you are running PHP 4.0, you also need to check the following line: register_globals = On if you are running PHP 3.0 in Windows, remove the ';' at the beginning to cancel the following line of comments (4.0 not required): extension = php_mysql.dll to save php. ini changes, and then restart your Web server. In Linux, if you log on as a super user, you can restart Apache:/etc/rc. d/init. d/httpd restart. now everything is ready! Now the only thing left is to test and check if everything is okay (see your first PHP script ). If your Web host provides PHP and MySQL, if the host that provides Web space for you has installed and configured MySQL and PHP for you, you only want to learn how to use them, there are not many facts you need to do. Now you should contact your host provider to obtain information on how to access these services. In particular, you need to obtain the user name and password you set to access the MySQL service. They may have already set up an empty database for you (this will prevent confusion between you and other users on the same MySQL server). you also need to know the database name. There are two methods to access the MySQL service. The first method is to use telnet to log on to the host and install the MySQL client program (mysql, mysqladmin, mysqldump, etc.) to directly interact with the MySQL service. The second method is to install those client programs on your computer and connect them to the MySQL server. Your Web host may support one or two methods. If they support telnet login for your work, you also need a user name and password for telnet login (this user name and password may be different from your access to the MySQL service ). You need to clarify the two settings. If they support remote access to the MySQL service, you need to download a program to connect and interact with the server. This tutorial assumes that you have http://www.mysql.com/ Download a MySQL client program. This package can be run either in windows or Unix, and is free of charge. The installation instructions included in the software package are very simple. If you prefer some graphical interfaces, you can download http://www.mysql.com/ ). I recommend that you first learn to use basic client programs, although the commands used in these programs are similar to the scripts used to access the MySQL database in the PHP script. Your first PHP script tells you so much about installation, but it's unfair for me to try the PHP-driven web pages.

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.