PHP installation principles and procedures

Source: Internet
Author: User
Tags import database
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

  1. $ Files = "data/config. php ";
  2. If (! Is_writable ($ files )){
  3. Echo "cannot be written !!! ";
  4. } Else {
  5. Echo "writable ";
  6. }
  7. If (isset ($ _ POST [install]) {
  8. $ Config_str ="
  9. $ Config_str. = "";
  10. $ Config_str. = $ mysql_host = ". $ _ POST [db_host].";
  11. $ Config_str. = "";
  12. $ Config_str. = $ mysql_user = ". $ _ POST [db_user].";
  13. $ Config_str. = "";
  14. $ Config_str. = $ mysql_pass = ". $ _ POST [db_pass].";
  15. $ Config_str. = "";
  16. $ Config_str. = $ mysql_dbname = ". $ _ POST [db_dbname].";
  17. $ Config_str. = "";
  18. $ Config_str. = $ mysql_tag = ". $ _ POST [db_tag].";
  19. $ Config_str. = "";
  20. $ Config_str. =?>;
  21. $ Ff = fopen ($ files, "w ");
  22. Fwrite ($ ff, $ config_str );
  23. // ====================================
  24. Include_once ("data/config. php"); // embed the configuration file
  25. If (! @ $ Link = mysql_connect ($ mysql_host, $ mysql_user, $ mysql_pass) {// check the database connection status
  26. Echo "database connection failed! Please return to the previous page to check connection parameters and return to modify ";
  27. } Else {
  28. Mysql_query ("create database '$ mysql_dbname '");
  29. Mysql_select_db ($ mysql_dbname );
  30. $ SQL _query [] = "CREATE TABLE". $ mysql_tag. "admin_log1 '(
  31. 'Id' int (8) unsigned not null auto_increment,
  32. 'Username' varchar (40) not null comment operation user name,
  33. 'Types' varchar (60) not null,
  34. Primary key ('id ')
  35. );";
  36. $ SQL _query [] = "CREATE TABLE". $ mysql_tag. "admin_log2 '(
  37. 'Id' int (8) unsigned not null auto_increment,
  38. 'Username' varchar (40) not null comment operation user name,
  39. 'Types' varchar (60) not null,
  40. Primary key ('id ')
  41. );";
  42. $ SQL _query [] = "CREATE TABLE". $ mysql_tag. "admin_log3 '(
  43. 'Id' int (8) unsigned not null auto_increment,
  44. 'Username' varchar (40) not null comment operation user name,
  45. 'Types' varchar (60) not null,
  46. Primary key ('id ')
  47. );";
  48. Foreach ($ SQL _query as $ val ){
  49. Mysql_query ($ val );
  50. }
  51. Echo "script alert (installation successful !); Location. href = index. php script ";
  52. Rename ("install. php", "install. lock ");
  53. }
  54. }
  55. ?>


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...

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.