PHP_环境配置_python脚本_2017

python

Apache配置

需要安装:VC2015

httpd-2.4.16-win32-VC14.zip VC14就是2015的环境。

又比如:php-5.6.12-Win32-VC11-x86 VC11就是2012的环境。

如果没有安装对应的环境,在配置php + apache时,提示内容会很奇怪。

可能会提示"提示NET HELPMSG 3547"在

语句填写正确的情况下,VC环境也是造成其原因之一,切记。

将Apache解压到C:\www\Apache24\,进入C:\www\Apache24\bin

httpd.exe -k install -n "Apache24"

rem httpd.exe -k uninstall -n "Apache24"

遇到错误:

查看apache错误日志:目录下的apache/logs/error.log

查看window系统日志:我的电脑——》右键管理——》系统工具——》事件查看器——》应用程序日志

在命令行中使用netstat -ano就可以很清楚的看到本地80口占用程序的PID    记下PID
然后打开任务管理器   在   进程    里查找到PID所对应的进程

修改C:\www\Apache24\httpd.conf里面的目录路径,将C: \Apache24更改为C:\www\Apache24

PHP配置

将php-5.6.12-Win32-VC11-x86.zip解压到目录,然后在httpd.conf中进行配置:

# php5 support

LoadModule php5_module "C: /php/php5apache2_4.dll"

AddHandler application/x-httpd-php .php

AddType application/x-httpd-php .html .htm

# configure thepath to php.ini

PHPIniDir " C:/php"

将上述行为写成一个脚本可以方便下次配置,并且省去总是改目录的问题。

MYSQL配置

[mysqld]

# These are commonly set, remove the # and set as required.

#mysql的根目录

basedir = "E:/BaiduBack/BaiduBack/PHPENV/mysql"

#mysql的根目录

datadir = "E:/data"

# 默认端口

port = 3306

# server_id = .....

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

# 服务端的编码方式

character-set-server = utf8

[client]

#客户端编码方式,最好和服务端保存一致

loose-default-character-set = utf8

注意:MySQL的管理员用户名为root,密码默认为空。

MySQL修改root密码的多种方法

方法1: 用SET PASSWORD命令

mysql -u root

mysql> SET PASSWORD FOR \'root\'@\'localhost\' = PASSWORD(\'newpass\');

方法2:用mysqladmin

mysqladmin -u root password "newpass"

如果root已经设置过密码,采用如下方法

mysqladmin -u root password oldpass "newpass"

方法3: 用UPDATE直接编辑user表

mysql -u root

mysql> use mysql;

mysql> UPDATE user SET Password = PASSWORD(\'newpass\') WHERE user = \'root\';

mysql> FLUSH PRIVILEGES;

在丢失root密码的时候,可以这样

mysqld_safe --skip-grant-tables&

mysql -u root mysql

mysql> UPDATE user SET password=PASSWORD("new password") WHERE user=\'root\';

mysql> FLUSH PRIVILEGES;

如何在本地配置两个站点:

让Apache在启动时能加载虚拟主机模块。

打开Apache安装目录下conf/httpd.conf文件,找到下面两行文字,把最前面的 # 号去掉,然后保存。

#LoadModule vhost_alias_module modules/mod_vhost_alias.so

#Include conf/extra/httpd-vhosts.conf

接着找到同一文件中的DocumentRoot和Directory,改为站点目录的上一级目录

例如站点放在 D:/Appserv/www/1 和 D:/Appserv/www/2,则改为以下形式

DocumentRoot"D:/Appserv/www"

<Directory"D:/Appserv/www">

配置完成后即可打开Apache安装目录下/conf/extra/httpd-vhosts.conf文件,在最后添加如下:

DocumentRoot是文件放置路径,ServerName是网站域名:

<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_环境配置_python脚本

import os

class 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/php.ini-production", "r").readlines()

f6 = open(os.path.abspath(".").replace("\\","/") + "/php/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("""# 服务端的编码方式

character-set-server = utf8

[client]

#客户端编码方式,最好和服务端保存一致

loose-default-character-set = utf8""")

f4.close()

s = os.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")

#改变appache路径

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)

#多个站点设置上级目录(这里直接写成根目录)

line = line.replace("Apache24/htdocs", "")

elif \'<IfModule unixd_module>\' in line:

s_temp = """# php5 support

LoadModule php5_module "%s/php/php5apache2_4.dll"

AddHandler application/x-httpd-php .php

AddType application/x-httpd-php .html .htm

# configure thepath to php.ini

PHPIniDir "%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")

#这里是多个站点设置

elif \'mod_vhost_alias.so\' in line:

line = line.replace("#","")

#这里是多个站点设置

elif \'httpd-vhosts.conf\' in line:

line = line.replace("#","")

else:

line = line

f2.write(line);

f2.close()

#将apache24添加到服务

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_1_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 "请修改hosts 127.0.0.1 www.1.com"

print "请修改hosts 127.0.0.1 www.2.com"

os.system("net stop apache24 & net start apache24 & pause")

以上是 PHP_环境配置_python脚本_2017 的全部内容, 来源链接: utcz.com/z/389184.html

回到顶部