Mac下XAMPP虚拟主机配置及常见问题解决方案

2018-12-05  本文已影响93人  ibunny

Apache

配置虚拟主机

  1. /etc/hosts中添加virtual-host-name1virtual-host-name2的host配置:
127.0.0.1 virtual-host-name1
127.0.0.1 virtual-host-name2
  1. 打开/Applications/XAMPP/xamppfiles/etc/httpd.conf文件,取消下面这一行Include前面的注释:
# Virtual hosts
Include etc/extra/httpd-vhosts.conf
  1. 再打开/Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf文件,先注释掉默认的两个虚拟主机配置,再添加自己的虚拟主机配置:
#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot "/opt/lampp/docs/dummy-host.example.com"
#    ServerName dummy-host.example.com
#    ServerAlias www.dummy-host.example.com
#    ErrorLog "logs/dummy-host.example.com-error_log"
#    CustomLog "logs/dummy-host.example.com-access_log" common
#</VirtualHost>
#
#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host2.example.com
#    DocumentRoot "/opt/lampp/docs/dummy-host2.example.com"
#    ServerName dummy-host2.example.com
#    ErrorLog "logs/dummy-host2.example.com-error_log"
#    CustomLog "logs/dummy-host2.example.com-access_log" common
#</VirtualHost>

<virtualhost *:80>
    ServerName virtual-host-name1
    DocumentRoot "your-path1"
    <directory "your-path1">
        Options Indexes FollowSymLinks ExecCGI Includes
        AllowOverride All
        Require all granted
    </directory>
</virtualhost>

<virtualhost *:80>
    ServerName virtual-host-name2
    DocumentRoot "your-path2"
    <directory "your-path2">
        Options Indexes FollowSymLinks ExecCGI Includes
        AllowOverride All
        Require all granted
    </directory>
</virtualhost>
  1. 重启Apache服务,最后通过 http://virtual-host-name*:80就可以访问网页了;

XAMPP-VM中如果配置虚拟主机后网页无法打开:

  • 打开Network标签
  • Disable port 后再 Enable

src: https://www.dyclassroom.com/howto-mac/how-to-install-apache-mysql-php-on-macos-mojave-10-14

Mysql

1. 解决 mysql command not found 的问题:

sudo ln -s /Applications/XAMPP/xamppfiles/bin/mysql /usr/local/bin

2. 修改mysql默认密码:

sudo /Applications/XAMPP/xamppfiles/xampp security

根据提示操作。

3. mysql中文查询结果显示为乱码问题

打开/Applications/XAMPP/xamppfiles/etc/my.cnf文件,
在下面对应位置分别添加default-character-set=utf8character-set-server=utf8

# The following options will be passed to all MySQL clients
[client]
#password= your_password
port = 3306
socket = /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
default-character-set=utf8


# Here follows entries for some specific programs

# The MySQL server
[mysqld]
user = mysql
port = 3306
socket = /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
character-set-server=utf8
上一篇下一篇

猜你喜欢

热点阅读