PHP _ environment configuration _ python script _ 2017, _ python_2017
Apache configuration
Installation required: VC2015
Httpd-2.4.16-win32-VC14.zip VC14 is 2015 environment.
For example: php-5.6.12-Win32-VC11-x86 VC11 is 2012 environment.
If the corresponding environment is not installed, the prompt content will be very strange When configuring php + apache.
The system prompts "net helpmsg 3547" in
When the statement is entered correctly, the VC environment is also one of the causes. Remember.
Decompress Apache to C: \ www \ Apache24 \ and enter C: \ www \ Apache24 \ bin.
httpd.exe -k install -n "Apache24"rem httpd.exe -k uninstall -n "Apache24"
Encountered error:
View apache error logs: apache/logs/error. log under the Directory
View windows system logs: My computer -- Right-click Management -- System Tools -- Event Viewer -- application logs
Use netstat-ano in the command line to clearly see the PID of the local 80 port occupation program.
Open the task manager and check the process corresponding to the PID in the process.
Change C: \ www \ Apache24 \ httpd. conf to C: \ Apache24
PHP configuration
Decompress php-5.6.12-win32-vc11-x86.zip to the directory and configure it in httpd. conf:
# php5 supportLoadModule php5_module "C: /php/php5apache2_4.dll"AddHandler application/x-httpd-php .phpAddType application/x-httpd-php .html .htm# configure thepath to php.iniPHPIniDir " C:/php"
Writing the above behavior into a script can facilitate the next configuration and eliminate the problem of always changing the directory.
MYSQL Configuration
[Mysqld] # These are commonly set, remove the # and set as required. # mysql root directory basedir = "E:/BaiduBack/PHPENV/mysql" # mysql root directory datadir = "E: /data "# default port = 3306 # server_id = ..... SQL _mode = NO_ENGINE_SUBSTITUTION, STRICT_TRANS_TABLES # server-side encoding mode character-set-server = utf8 [client] # client encoding mode. It is best to keep the same loose-default-character-set = utf8 as the server-
Note: The MySQL administrator username is root, and the password is blank by default.
Multiple methods for changing the root password of MySQL
Method 1: use the set password command
mysql -u rootmysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
Method 2: Use mysqladmin
Mysqladmin-u root password "newpass" if the root user has set a password, use the following method: mysqladmin-u root password oldpass "newpass"
Method 3: Use UPDATE to directly edit the user table
Mysql-u rootmysql> use mysql; mysql> UPDATE user SET Password = PASSWORD ('newpass') WHERE user = 'root'; mysql> flush privileges; when the root Password is lost, mysqld_safe -- skip-grant-tables & mysql-u root mysqlmysql> UPDATE user SET password = PASSWORD ("new password") WHERE user = 'root'; mysql> flush privileges;How to configure two sites locally:
Let Apache load the Virtual Host module at startup.
Open the conf/httpd. conf file in the Apache installation directory, find the following two lines of text, remove the first #, and save.
#LoadModule vhost_alias_module modules/mod_vhost_alias.so#Include conf/extra/httpd-vhosts.conf
Then find the DocumentRoot and Directory in the same file and change it to the upper-level Directory of the site Directory.
For example, if the site is stored in D:/Appserv/www/1 and D:/Appserv/www/2, the format is changed to the following:
DocumentRoot"D:/Appserv/www"<Directory"D:/Appserv/www">
After the configuration is complete, open the/conf/extra/httpd-vhosts.conf file under the Apache installation directory and add the following at the end:
DocumentRoot is the file placement path, and ServerName is the website Domain Name:
<VirtualHost*:80>DocumentRoot"D:/Appserv/www/1"ServerName www.xxx.com</VirtualHost><VirtualHost*:80>DocumentRoot"D:/Appserv/www/2"ServerName www.xxx2.com</VirtualHost>
PHP _ environment configuration_python script
Import osclass Moments: def _ init _ (self): print ("Hello Moments"); pass def configApache24 (self, pathname = "Apache24"): if OS. path. exists (pathname): print ("Find path % s" % pathname) else: return false; f5 = open (OS. path. abspath (". "). replace ("\", "/") + "/php. ini-production "," r "). readlines () f6 = open (OS. path. abspath (". "). replace ("\", "/") + "/php. ini "," w ") for line in f5: if '''extension _ dir =" ext "''' in line: line = "extension_dir =" ext "\ n" elif "; extension = php_mysql.dll" in line: line = "extension = php_mysql.dll \ n" elif "; extension = php_mysqli.dll" in line: line = "extension = php_mysqli.dll \ n" elif "; extension = php_pdo_mysql.dll" in line: line = "extension = php_pdo_mysql.dll \ n" else: line = line f6.write (line) f6.close () f3 = open (OS. path. abspath (". "). replace ("\", "/") + "/mysql/my-default.ini", "r "). readlines () f4 = open (OS. path. abspath (". "). replace ("\", "/") + "/mysql/my. ini "," w ") for line in f3: if" basedir "in line: line =" basedir = % s \ n "% (OS. path. abspath (". "). replace ("\", "/") + "/mysql") elif "datadir" in line: line = "datadir = % s \ n" % (OS. path. abspath (". "). replace ("\", "/") + "/mysql/data") elif "port" in line: line = "port = 3306 \ n" else: line = line f4.write (line) f4.write ("# server-side encoding method character-set-server = utf8 [client] # client encoding method, it is best to save the same loose-default-character-set = utf8 ") f4.close () s = OS as the server. path. abspath (". "). replace ("\", "/") + "/mysql/bin/mysqld.exe -- remove mysql" OS. system (s) s = OS. path. abspath (". "). replace ("\", "/") + "/mysql/bin/mysqld.exe -- install mysql" OS. system (s) OS. system ("net stop mysql & net start mysql & pause") if OS. path. exists (pathname + "/conf/httpd. conf. bak "): OS. remove (pathname + "/conf/httpd. conf ") # OS. rename (pathname + "/conf/httpd. conf. bak ", pathname +"/conf/httpd. conf ") else: OS. rename (pathname + "/conf/httpd. conf ", pathname +"/conf/httpd. conf. bak ") f = open (pathname +"/conf/httpd. conf. bak "," r "). readlines () f2 = open (pathname + "/conf/httpd_new.conf", "w") # change the appache path for line in f: if 'C:/apache24' in line: # line = "#" + line + "\ n" + "ServerRoot" + OS. path. abspath (". "). replace ("\", "/") + "/" + pathname line = line. replace ("c:/Apache24", OS. path. abspath (". "). replace ("\", "/") + "/" + pathname) # Set the parent directory for multiple sites (the root directory is written here) line = line. replace ("Apache24/htdocs", "") el'if '<IfModule unixd_module>' in line: s_temp = "# php5 supportLoadModule php5_module" % s/php/php5apache2_4.dll "AddHandler application/x-httpd-php. phpAddType application/x-httpd-php. html. htm # configure thepath to php. iniPHPIniDir "% s/php" % (OS. path. abspath (". "). replace ("\", "/"), OS. path. abspath (". "). replace ("\", "/") if OS. path. exists (OS. path. abspath (". "). replace ("\", "/") + "/php/php5apache2_4.dll"): line = s_temp + line; else: print ("### ERROR: can not find "+ OS. path. abspath (". "). replace ("\", "/") + "/php/php5apache2_4.dll") # Set elif 'mod _ vhost_alias.so 'in line: line = line for multiple sites. replace ("#", "") # Set elif 'httpd-vhosts for multiple sites. conf 'in line: line = line. replace ("#", "") else: line = line f2.write (line); f2.close () # Add apache24 to service s = OS. path. abspath (". "). replace ("\", "/") + "/" + pathname + '/bin/httpd.exe-k uninstall-n "Apache24"' OS. system (s) s = OS. path. abspath (". "). replace ("\", "/") + "/" + pathname + '/bin/httpd.exe-k install-n "Apache24"' OS. system (s) print (s) OS. rename (pathname + "/conf/httpd_new.conf", pathname + "/conf/httpd. conf ") f = open (pathname +"/conf/extra/httpd-vhosts.conf "," a ") f. write ("<VirtualHost *: 80> DocumentRoot" % swww_1_com "ServerName www.1.com </VirtualHost> <VirtualHost *: 80> DocumentRoot "% swww_2_com" ServerName www.2.com </VirtualHost> "" % (OS. path. abspath (". "). replace ("\", "/"), OS. path. abspath (". "). replace ("\", "/") OS. mkdir ("% swww_w.com" % OS. path. abspath (". ") OS. mkdir ("% swww_2_com" % OS. path. abspath (". ") OS. system ("net stop apache24 & net start apache24 & pause") if _ name _ = "_ main _": mo = Moments (); mo. configApache24 ("Apache24"); print "Modify hosts 127.0.0.1 www.1.com" print ". Modify hosts 127.0.0.1 www.2.com" OS. system ("net stop apache24 & net start apache24 & pause ")