The principles and steps of PHP installation are described in detail. This article explains the principles and steps of PHP installation. 1. the principle of PHP installation is to import the database structure and content to the corresponding database, this article explains the principles and steps for creating and installing PHP programs.
1. how to create a PHP installation program
The installation principle of the PHP program is to import the database structure and content to the corresponding database, and reconfigure the parameters and files for connecting to the database from this process, to prevent malicious use of the installation file, you must modify the installation file after installation.
2. create a PHP installation procedure
Step 1 check the directory or file permissions
Step 2 modify or add the configuration file
Step 3 check the correctness of the configuration file
Step 4 import database
Step 5 lock or delete the installation file
3. create PHP functions for installation
Check whether the file is writable. The return value is is_writable ("data/config. php ");
Check whether the file is readable and return a Boolean value: is_readable ("data/config. php ");
Fopen () file operation function to open a file or create a new
Fwrite () file operation function, write content to the file
Rename () file operation function, rename the file
4. Notes
(1). check the permissions of files and related folders, such as caching, generating files, and configuring files.
(2) Install files as independent as possible, which can be deleted and renamed.
(3) During database import, check:
A. Check whether you have the permission to create a database.
B. whether a database with the same name exists
C. check whether the database import size is segmented.
(4) Check the configuration environment and support of various modules, such as gd2, pdo, and rewirte.
5. instance code
-
- $ Files = "data/config. php ";
- If (! Is_writable ($ files )){
- Echo "cannot be written !!! ";
- } Else {
- Echo "writable ";
- }
- If (isset ($ _ POST [install]) {
- $ Config_str ="
- $ Config_str. = "";
- $ Config_str. = $ mysql_host = ". $ _ POST [db_host].";
- $ Config_str. = "";
- $ Config_str. = $ mysql_user = ". $ _ POST [db_user].";
- $ Config_str. = "";
- $ Config_str. = $ mysql_pass = ". $ _ POST [db_pass].";
- $ Config_str. = "";
- $ Config_str. = $ mysql_dbname = ". $ _ POST [db_dbname].";
- $ Config_str. = "";
- $ Config_str. = $ mysql_tag = ". $ _ POST [db_tag].";
- $ Config_str. = "";
- $ Config_str. =?>;
- $ Ff = fopen ($ files, "w ");
- Fwrite ($ ff, $ config_str );
- // ====================================
- Include_once ("data/config. php"); // embed the configuration file
- If (! @ $ Link = mysql_connect ($ mysql_host, $ mysql_user, $ mysql_pass) {// check the database connection status
- Echo "database connection failed! Please return to the previous page to check connection parameters and return to modify ";
- } Else {
- Mysql_query ("create database '$ mysql_dbname '");
- Mysql_select_db ($ mysql_dbname );
- $ SQL _query [] = "CREATE TABLE". $ mysql_tag. "admin_log1 '(
- 'Id' int (8) unsigned not null auto_increment,
- 'Username' varchar (40) not null comment operation user name,
- 'Types' varchar (60) not null,
- Primary key ('id ')
- );";
- $ SQL _query [] = "CREATE TABLE". $ mysql_tag. "admin_log2 '(
- 'Id' int (8) unsigned not null auto_increment,
- 'Username' varchar (40) not null comment operation user name,
- 'Types' varchar (60) not null,
- Primary key ('id ')
- );";
- $ SQL _query [] = "CREATE TABLE". $ mysql_tag. "admin_log3 '(
- 'Id' int (8) unsigned not null auto_increment,
- 'Username' varchar (40) not null comment operation user name,
- 'Types' varchar (60) not null,
- Primary key ('id ')
- );";
- Foreach ($ SQL _query as $ val ){
- Mysql_query ($ val );
- }
- Echo "script alert (installation successful !); Location. href = index. php script ";
- Rename ("install. php", "install. lock ");
- }
- }
- ?>
-
-
I hope this article will be helpful to you.
Tips 1. how to create a PHP installation program the PHP installation principle is to import the database structure and content to the corresponding database...