mac 安装xampp如果要用localhost打开apache怎么办

也可以看一下这个网址 http://blog.sina.com.cn/s/blog_9592635a0102uy87.html

Tips: 

要想关掉本机自带的apache需要在终端里:

sudo /usr/sbin/apachectl start

sudo /usr/sbin/apachectl stop



首先 要把mac自带的apache关闭掉(其实关掉是不管用的

)要改虚拟机的

我使用的Mac OS X版本是10.8.2,Mac自带了Apache环境。

  1. 启动Apache
  2. 设置虚拟主机

 

启动Apache

打开“终端(terminal)”,输入 sudo apachectl -v,(可能需要输入机器秘密)。如下显示Apache的版本

 

接着输入 sudo apachectl start,这样Apache就启动了。打开Safari浏览器地址栏输入 “http://localhost”,可以看到内容为“It works!”的页面。其位于“/Library(资源库)/WebServer/Documents/”下,这就是Apache的默认根目录。

Apache的安装目录在:/etc/apache2/,etc默认是隐藏的。有三种方式查看:

  1. dock下右键Finder,选择"前往文件夹",输入"/etc"
  2. 在finder下----》前往---》前往文件夹,然后输入/etc
  3. 可以在terminal 输入 "open /etc"

 

设置虚拟主机

  1. 在终端运行“sudo vi /etc/apache2/httpd.conf”,打开Apche的配置文件
  2. 在httpd.conf中找到“#Include /private/etc/apache2/extra/httpd-vhosts.conf”,去掉前面的“”,保存并退出。
  3. 运行“sudo apachectl restart”,重启Apache后就开启了虚拟主机配置功能。
  4. 运行“sudo vi /etc/apache2/extra/httpd-vhosts.conf”,就打开了配置虚拟主机文件httpd-vhost.conf,配置虚拟主机了。需要注意的是该文件默认开启了两个作为例子的虚拟主机:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    < VirtualHost  *:80>
         ServerAdmin webmaster@dummy-host.example.com
         DocumentRoot "/usr/docs/dummy-host.example.com"
         ServerName dummy-host.example.com
         ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
         CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
    </ VirtualHost >
     
    < VirtualHost  *:80>
         ServerAdmin webmaster@dummy-host2.example.com
         DocumentRoot "/usr/docs/dummy-host2.example.com"
         ServerName dummy-host2.example.com
         ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
         CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
    </ VirtualHost >

    而实际上,这两个虚拟主机是不存在的,在没有配置任何其他虚拟主机时,可能会导致访问localhost时出现如下提示:

    Forbidden
    You don't have permission to access /index.php on this server

    最简单的办法就是在它们每行前面加上#,注释掉就好了,这样既能参考又不导致其他问题。

  5. 增加如下配置
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    < VirtualHost  *:80>
         DocumentRoot "/Library/WebServer/Documents"
         ServerName localhost
         ErrorLog "/private/var/log/apache2/localhost-error_log"
         CustomLog "/private/var/log/apache2/localhost-access_log" common
    </ VirtualHost
     
    < VirtualHost  *:80>
         DocumentRoot "/Users/snandy/work"
         ServerName mysites
         ErrorLog "/private/var/log/apache2/sites-error_log"
         CustomLog "/private/var/log/apache2/sites-access_log" common
         < Directory  />
                     Options Indexes FollowSymLinks MultiViews
                     AllowOverride None
                     Order deny,allow
                     Allow from all
           </ Directory >
    </ VirtualHost >

    保存退出,并重启Apache。

  6. 运行“sudo vi /etc/hosts”,打开hosts配置文件,加入"127.0.0.1 mysites",这样就可以配置完成sites虚拟主机了,可以访问“http://mysites”了,在10.8之前Mac OS X版本其内容和“http://localhost/~[用户名]”完全一致。
  7. 注意,记录log的“ErrorLog "/private/var/log/apache2/sites-error_log"”也可以删掉,但记录日志其实是一个好习惯,在出现问题时可以帮助我们判断。如果保留这些log代码,一定log文件路径都是存在的,如果随便修改一个不存在的,会导致Apache无法服务而没有错误提示,这个比较恶心。


=============================================

ollow the steps below to create a virtual host:

  1. Open a new terminal and ensure you are logged in as an administrator.

  2. Change to your XAMPP installation directory (typically, /Applications/XAMPP) and open the httpd.conf file in the etc/subdirectory using a text editor.

  3. Within the file, find the following line and uncomment it by removing the hash symbol (#) at the beginning of the line.

    Include etc/extra/httpd-vhosts.conf

  4. Next, open the httpd-vhosts.conf file in the etc/extra/ subdirectory of your XAMPP installation directory. Replace the contents of this file with the following directives:

    <VirtualHost *:80>
           DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/"
           ServerName localhost
    </VirtualHost>
    <VirtualHost *:80>
           DocumentRoot "/Applications/XAMPP/xamppfiles/apps/wordpress/htdocs"
           ServerName wordpress.localhost
    </VirtualHost>

    This contains two virtual host configuration blocks:

    • The first block is the default or fallback virtual host, which is used for all requests that are not matched by subsequent blocks.

    • The second block sets up a virtual host named wordpress.localhost. The DocumentRoot directive specifies the directory to be used when serving requests for this virtual host (in this case, the WordPress installation directory), while the ServerName directive specifies the custom domain name for the virtual host.


    To add more virtual hosts, simply duplicate the second virtual host block and modify the port number, DocumentRoot and ServerName directives as per your requirements. For example, if you want to use SSL with your custom domain name, you can add a new virtual host block for port 443.

    If you plan to have a large number of virtual hosts with very similar configuration, consider using wildcard-based subdomains with your virtual hosts.
  5. Restart Apache using the XAMPP control panel for your changes to take effect.


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 要在Linux上安装XAMPP,您可以按照以下步骤进行操作: 1. 下载XAMPP安装包。您可以从Apache Friends网站上下载适用于Linux的XAMPP安装程序。 2. 打开终端。在Linux中,您可以使用终端进行大多数任务。打开终端并转到您下载XAMPP安装包的目录。 3. 解压缩XAMPP安装包。在终端中输入以下命令:`tar xvfz xampp-linux-x64-<版本号>-installer.run.tar.gz`。 4. 运行安装程序。在终端中输入以下命令:`sudo ./xampp-linux-x64-<版本号>-installer.run`。根据提示,选择要安装的组件和安装目录。 5. 启动XAMPP。在终端中输入以下命令:`sudo /opt/lampp/lampp start`。 6. 检查XAMPP是否运行正常。在浏览器中输入`http://localhost`,应该可以看到XAMPP欢迎页面。 ### 回答2: 在Linux系统下安装XAMPP是一个比较简单的过程,但需要有一定的Linux基础知识才能操作。 首先,需要到官网上下载XAMPP的压缩包,下载地址为“https://www.apachefriends.org/download.html ”。 下载完成后,需要解压缩该文件到Linux系统中,可以将其解压缩到/opt/xampp目录下。 接下来,需要打开终端,切换到/opt/xampp目录下,并执行命令sudo ./xampp start,然后就可以启动Apache和MySQL服务器了。 如果需要启动其他XAMPP组件如PHP等,可以在/opt/xampp目录下运行相应的命令。 安装过程中可能遇到以下问题: 1.权限问题:需要切换到root用户进行安装。 2.端口占用问题:需要在/opt/xampp/etc/httpd.conf中修改Apache服务的端口号,避免与已经运行的服务端口相冲突。 3.防火墙问题:需要在Linux系统上打开相关端口以供外网访问。 总体上,Linux系统下安装XAMPP是一件相对简单的事情,只需要下载压缩包、解压缩到指定目录,然后运行相应的命令即可。在安装过程中需要注意的是权限、端口和防火墙等相关问题,避免因为这些问题导致安装不成功。 ### 回答3: Linux是一个开源操作系统,可以免费使用。XAMPPApache + MySQL + PHP + Perl)是一种流行的服务器开发环境,可以在Linux操作系统中使用。 下面是安装XAMPP的步骤: 1.首先,我们需要下载XAMPP的Linux安装包。可以从Apache Friends网站上下载。 2.在下载完XAMPP文件后,将其保存在Linux中的任何位置。 3.打开终端窗口并转到XAMPP安装文件所在的目录。可以使用命令“cd”跳转到所需的目录。 4.找到XAMPP安装文件并解压缩它。使用命令“tar -xvf xampp-linux-x64-7.2.23-0-installer.run.tar.gz”解压文件。 5.然后转到安装程序所在的目录并运行安装程序。输入命令“sudo ./xampp-linux-x64-7.2.23-0-installer.run”运行XAMPP安装程序。 6.安装程序将显示一条消息,询问是否要继续安装XAMPP。选择“是”并按下Enter键。 7.然后安装程序将在Linux上安装XAMPP。无需用户交互。 8.安装完成后,可以从终端中启动XAMPP。使用命令“sudo /opt/lampp/lampp start”启动XAMPP。 9.打开浏览器,输入http://localhost,将看到XAMPP的欢迎页面。 10.现在,可以在Linux上使用XAMPP安装和运行Apache,MySQL和PHP等Web服务器软件。 总之,以上是在Linux上安装XAMPP的步骤。这个过程很简单,只需要按照步骤操作即可。这样,就可以将Web开发环境搭建在自己的Linux系统上,方便进行网站开发和测试。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值