当前位置: 首页 > 技术支持 > 服务器维护>> ...我在更换机房后及时修改数据库连接代码 怎么更改(php网站的源码在上传到虚拟主机之前,需要做什么修改)

...我在更换机房后及时修改数据库连接代码 怎么更改(php网站的源码在上传到虚拟主机之前,需要做什么修改)

一般用DW软件改。最好是找网站设计师改。

大家好,今天小编关注到一个比较有意思的话题,就是关于虚拟主机里的代码怎么改的问题,于是小编就整理了6个相关介绍虚拟主机里的代码怎么改的解答,让我们一起看看吧。

...我在更换机房后及时修改数据库连接代码 怎么更改(php网站的源码在上传到虚拟主机之前,需要做什么修改)

文章目录:

  1. ...我在更换机房后及时修改数据库连接代码 怎么更改
  2. php网站的源码在上传到虚拟主机之前,需要做什么修改
  3. 怎么修改主机屋虚拟主机的mysql数据库的默认编码为utf8? 不是本地...
  4. 如何配置 Apache 的虚拟主机
  5. 云虚拟主机怎么设置php.ini
  6. 如何配置 Apache 的虚拟主机

一、...我在更换机房后及时修改数据库连接代码 怎么更改

要修改的是网站程序里面的数据库连接文件,我和他们回答的一样,找技术吧。

找技术吧 top

一般用DW软件改。最好是找网站设计师改。。

二、php网站的源码在上传到虚拟主机之前,需要做什么修改

$conn=mysql_connect("localhost","root","root");

mysql_select_db("phphtml"颂迟锋);

这2句都要野晌修改

修改成对应你空间数据库的旦渣相关参数即可

一般程序都有安装文件的,会自亮轮动将数据库信息写入,如果没有安装文件的话,就得手动填了localhost为数据库主机信息,一般都为localhost 中间那个填写数据库名斗键陵(是服务器的数据库名),后面的为密空戚码。

改成你的数据库地址和数据库名还有密码,你还得导入你设计好的数据库!

$conn=mysql_connect("localhost","root","root");是必须修改州则的。

这句话的作用是连接数据库,localhost=mysql数据库的服务器地址,root=数据库用户名,root=数据库用户密码。

mysql_query("set names 'gb2312'");

是设定数据库册册棚的字符格式:gb2312,同时常用的还有utf-8

mysql_select_db("姿春phphtml");

这句中phphtml是你要连接的数据库的名称

三、怎么修改主机屋虚拟主机的mysql数据库的默认编码为utf8? 不是本地...

似乎脊散只能在自己的应用修改了 mysql_query('set names utf8');

创建数据库 default character set utf8 ;

创建数据颂野基表野谨 default charset=utf8;

不然会乱码。

四、如何配置 Apache 的虚拟主机

配置 Apache 虚拟主机

现渣链在,我们虚拟了两个域名,让它们指向了本地的电脑,访问它们,打开的是同一个目录里的内容,下面这个练习,我们通过修改 Apache 的配置文件,让访问不同域名的时候,打开的是不同的目录。你首先要判断一下配置 Apache 虚拟主机的配置文件,一般是在 httpd.conf 这个主配置文件里面,不过,很多环境都会单独把虚拟主机放在一个配置文件里面,然后在 httpd.conf 文件里指定一下,包含这个单独配置虚拟主机的文件。

1. 找到配置虚拟主机的配置文件,如果你用的是 WAMP 搭建的环境,先找到并打开 httpd.conf ,在这个文件里,搜索 # Virtual hosts ,它下面有一行代码, #Include conf/extra/httpd-vhosts.conf... 你可以去掉它前面的 # ,这样,Apache 启动以后,也会去加载这个httpd-vhosts.conf 配置文件,这样做的好处就是可以保持 Apache 相关设置的整洁。当然,你完全可以在主配置文件 httpd.conf 里面去设置虚拟主机。

2. 打开 httpd-vhosts.conf 这个文件,没有这个文件也可以去创建一个,或者直接在 httpd.conf 文件里面去配置虚拟主机。配置虚拟主机的东西应该像这样:

3. 应该有两段这样的代码,每一段都是在配置一个虚拟主机,你可以复制其中的一段,然后粘贴到文件的最下面。再根据自己的需要去修改这段代码。理解它的意思,ServerAdmin 就是网站的管理员的邮箱,DocumentRoot 是虚拟主机的主目录,也就是访问这个虚拟主机所打开的那个目录,这个目录你可以自己去指定,要注意的是,如雀孙你需要先去创建这个目录,然后再在这里去指定这个目录的位置。ServerName 是主机名,比如之前我们虚拟的那个主机名 hello.com,ServerAlias 是主机的别名,你可以指定一个其它的主机名,访问它的时候也会打开这个虚拟主机的目录里的东西。ErrorLog 是错误的日志,也就是发生错误的时候,会把错误记录到哪个文件里。CustomLog 是虚拟主机访问的日志。

这样自己岁隐新添加的虚拟主机看起来应该像这样:

3

4. 在浏览器里打开 hello.com ,访问的是这个虚拟主机的配置里 DocumentRoot 所指定的 /Applications/MAMP/htdocs/hello 这个目录里的东西,你可以在这个目录里面放点东西,比如一个 WordPress 或者 Drupal 的网站等等。

注:配置虚拟主机的时候,第一个虚拟主机是默认的,你需要留着,配置自己的虚拟主机,可以从第二个开始配置,也就是第二段 <VirtualHost> 代码。

五、云虚拟主机怎么设置php.ini

云虚拟主机分为三种:

1、提供ip或链接地址,可以使用linux终端工具连接进入linux命令行,使用vim命令兄此燃编辑即可

2、云虚拟主扒扰机平台提供修改的功能羡虚,在web平台操作就行

3、不提供php配置文件修改,需要电话或工单联系客服修改

六、如何配置 Apache 的虚拟主机

1、基于ip地址的虚拟主机

复制代码代码如下:

Listen 80

<VirtualHost 172.20.30.40>

DocumentRoot /home/httpd/html1

ServerName www.ok1.com

ErrorLog /usr/local/apache/logs/error1_log

CustomLog /usr/local/apache/logs/access1_log combined

</VirtualHost>

<VirtualHost 172.20.30.50>

DocumentRoot /home/httpd/html2

ServerName www.ok2.com

ErrorLog /usr/local/apache/logs/error2_log

CustomLog /usr/local/apache/logs/access2_log combined

</VirtualHost>

2、基于IP 和多端口的虚拟主机配置

复制代码代码如下:

Listen 172.20.30.40:80

Listen 172.20.30.40:8080

Listen 172.20.30.50:80

Listen 172.20.30.50:8080

<VirtualHost 172.20.30.40:80>

DocumentRoot /www/example1-80

ServerName www.example1.com

</VirtualHost>

<VirtualHost 172.20.30.40:8080>

DocumentRoot /www/example1-8080

ServerName www.example1.com

</VirtualHost>

<VirtualHost 172.20.30.50:80>

DocumentRoot /www/example2-80

ServerName www.example1.org

</VirtualHost>

<VirtualHost 172.20.30.50:8080>

DocumentRoot /www/example2-8080

ServerName www.example2.org

</VirtualHost>

3、单个IP 地址的服务器上基于域名的虚拟主机配置

复制代码代码如下:

# Ensure that Apache listens on port 80

Listen 80

# Listen for virtual host requests on all IP addresses

NameVirtualHost *:80

<VirtualHost *:80>

DocumentRoot /www/example1

ServerName www.example1.com

ServerAlias example1.com. *.example1.com

# Other directives here

</VirtualHost>

<VirtualHost *:80>

DocumentRoot /www/example2

ServerName www.example2.org

# Other directives here

</VirtualHost>

如果您感觉上面的文章还不够详细可以看下下面的文章:

实验目标:在apache实现基于域名的虚拟主机

实验用的XAMPP版本为1.7.7,内含apache版本为2.2.21

实验前准备:

1. 为了测试不同的域名,在Windows/System32/drivers/etc/下觅得hosts文件,在其中添加实验用的域名若干,如 -

复制代码代码如下:

127.0.0.1 test1.net

127.0.0.1 test2.net

如此,则在浏览器中输入该俩域名时,Windows将其解析为127.0.0.1本地地址。即,在浏览器中访问localhost, test1.net, test2.net均可访问XAMPP的欢迎页。

2. 在apache目录下建立目录,以放置您不同的网站。为保护XAMPP原有的htdocs中的欢迎页内容,实验另外建立了与htdocs平级的htdocs1目录,在其下建立了test1.net, test2.net两个子目录用以放置实验用的网站。如下 -

apache/htdocs1/test1.net - 放置test1.net网站内容

apache/htdocs1/test2.net - 放置test2.net网站内容

在这两个目录中各新建hello world一网页 index.html,内容 -

复制代码代码如下:

<HTML>

<HEAD></HEAD>

<BODY>

<H1>hello~, 这是[对应的网站名,用以区别].net</H1></BODY>

</HTML>

实验步骤:

1. 找到apache/conf/httpd.conf, 将其中的

ServerAdmin

ServerName

DocumentRoot

注释掉。

2. 在httpd.conf中,找到行

Include "conf/extra/httpd-vhosts.conf"

如被注释则解注。该文件记载了虚拟主机的参数。[以前虚拟主机参数是直接填写在httpd.conf中的,为了更好地组织文件,将其分离出去,类似于某些编程语言一样。因此httpd.conf中include它,即相当于把它的内容填在了httpd.conf中。]

3. 这个httpd-vhosts.conf文件格式基本如下 -

复制代码代码如下:

#blah-blah

NameVirtualHost *:80

#blah-blah

#blah-blah

<VirtualHost *:80>

ServerAdmin XXXXXXXX

DocumentRoot "XXXXXXXX"

ServerName XXXXXXX

ServerAlias XXXXXX

ErrorLog "logs/XXXXXX-error.log"

CustomLog "logs/XXXXXXX-error.log" combined

</VirtualHost>

需要修改的,就是<VirtualHost>中的参数了。这个可以参见apache官方文档。根据实验域名,可以增加两个<VirtualHost>:

复制代码代码如下:

<VirtualHost *:80>

ServerAdmin adm@test1.net

DocumentRoot "C:/xampp/htdocs1/test1.net"

ServerName test1.net

ServerAlias www.test1.net

ErrorLog "logs/test1-error.log"

CustomLog "logs/test1-access.log" combined

<Directory "C:/xampp/htdocs1/test1.net">

order allow,deny

allow from all

</Directory>

</VirtualHost>

<VirtualHost *:80>

ServerAdmin adm@test2.net

DocumentRoot "C:/xampp/htdocs1/test2.net"

ServerName test2.net

ServerAlias www.test2.net

ErrorLog "logs/test1-error.log"

CustomLog "logs/test1-access.log" combined

<Directory "C:/xampp/htdocs1/test2.net">

order allow,deny

allow from all

</Directory>

</VirtualHost>

注意,如果不在各VirtualHost中定义Directory的可访问性,你将遇到的是Access Forbidden!就连原来的localhost也是。

4. 由于之前注释掉了httpd.conf中的ServerName, DocumentRoot等,为了仍然能以localhost访问原XAMPP欢迎页,就在增加一个VirtualHost,如下 -

复制代码代码如下:

<VirtualHost *:80>

ServerAdmin adm@localhost

DocumentRoot "C:/xampp/htdocs"

ServerName localhost

ErrorLog "logs/localhost-error.log"

CustomLog "logs/localhost-access.log" combined

<Directory "C:/xampp/htdocs">

order allow,deny

allow from all

</Directory>

</VirtualHost>

为了避免出错,把它放置在第一个Virtualhost位置。

至此,apache基于域名的虚拟主机配置完成。可以通过http://localhost访问XAMPP欢迎页,通过http://test1.net和http://test2.net访问各自的主页。

#

# Virtual Hosts

#

# If you want to maintain multiple domains/hostnames on your

# machine you can setup VirtualHost containers for them. Most configurations

# use only name-based virtual hosts so theserverdoesn't need to worry about

# IP addresses. This is indicated by the asterisks in the directives below.

#

# Please see the documentation at

# <URL:http://httpd.apache.org/docs/2.2/vhosts/>

# for further details before you try to setup virtual hosts.

#

# You may use the command line option '-S' to verify your virtual host

# configuration.

#

# Use name-based virtualhosting.

#

NameVirtualHost *:80

#

# VirtualHost example:

# Almost any Apache directive may go into a VirtualHost container.

# The first VirtualHost section is used for all requests that do not

# match a ServerName or ServerAlias in any <VirtualHost> block.

#

<VirtualHost *:80>

ServerAdmin kongdaoxian@gmail.com

DocumentRoot "E:/skydao/apache2/htdocs"

ServerName localhost

ServerAlias www.skydao.com

ErrorLog "logs/localhost-error.log"

CustomLog "logs/localhost-access.log" combined

<Directory "E:/skydao/apache2/htdocs">

order allow,deny

allow from all

</Directory>

</VirtualHost>

<VirtualHost *:80>

ServerAdmin kongdaoxian@gmail.com

DocumentRoot "E:/skydao/apache2/htdocs/project1"

ServerName project1.com

ServerAlias www.project1.com

ErrorLog "logs/project1-error.log"

CustomLog "logs/project1-access.log" combined

<Directory "E:/skydao/apache2/htdocs/project1">

order allow,deny

allow from all

</Directory>

</VirtualHost>

<VirtualHost *:80>

ServerAdmin kongdaoxian@gmail.com

DocumentRoot "E:/skydao/apache2/htdocs/zendTest/public"

ServerName zendTest.com

ServerAlias www.zendTest.com

DirectoryIndex index.php

<Directory />

Options FollowSymLinks

AllowOverride None

Order allow,deny

Allow from all

</Directory>

</VirtualHost>

<VirtualHost *:80>

ServerAdmin kongdaoxian@gmail.com

DocumentRoot "E:/skydao/apache2/htdocs/testRewrite"

ServerName testRewrite.com

ServerAlias www.testRewrite.com

# DirectoryIndex index.php

<Directory />

Options FollowSymLinks

AllowOverride None

Order allow,deny

Allow from all

</Directory>

</VirtualHost>

<VirtualHost *:80>

ServerAdmin kongdaoxian@gmail.com

DocumentRoot "E:/skydao/apache2/htdocs/test"

ServerName test.com

ServerAlias www.test.com

ErrorLog "logs/zendTest-error.log"

CustomLog "logs/zendTest-access.log" combined

<Directory "E:/skydao/apache2/htdocs/test">

order allow,deny

allow from all

</Directory>

</VirtualHost>

到此,以上就是小编对于虚拟主机里的代码怎么改的问题就介绍到这了,希望介绍关于虚拟主机里的代码怎么改的6点解答对大家有用。


服务器购买/咨询热线:1563700917115617636856

本文链接:http://43.134.181.216/jishuzhichiyuweihu/17979.html
tags:
腾讯云服务器特惠

  • 关注微信
是否收录:

猜你喜欢

微信公众号