ก๊วนซอฟท์แวร์ </softganz> SoftGang (Gang Software)

Web &amp; Software Developer Gang.

Make Macbook Pro to be Web Server

by Little Bear @10 ก.ค. 58 16:43 ( IP : 49...89 ) | Tags : Macbook , Apache , Server

แก้ config ของ Apache

sudo nano /etc/apache2/httpd.conf
AllowOverride All

เปิดใช้งาน mod_rewrite

LoadModule rewrite_module libexec/apache2/mod_rewrite.so

Install PHP

brew update
brew install php@7.3
brew link php@7.3
brew services start php@7.3

เปิดใช้งาน php

LoadModule php7_module libexec/apache2/libphp7.so

เปลี่ยน DocumentRoot ของ web

sudo mv /Library/WebServer/Documents /Library/WebServer/Documents.old
sudo ln -s /New/Web/Folder /Library/WebServer/Documents

แก้ php config โดย cp /etc/php.ini.default /etc/php.ini

post_max_size = 16M
upload_max_filesize = 1024M

date.timezone = Asia/Bangkok

Restart Apache

sudo apachectl configtest
sudo apachectl -k restart

ที่มา macOS 10.15 Catalina Apache Setup: SSL


Install MariaDB

brew install mariadb

Start MariaDB

Service start

brew services start mariadb

Start without service

mysql.server start

Link data to new location

sudo ln -s /Users/mysql /usr/local/var/mysql
sudo chown -h user:group /usr/local/var/mysql

แก้ไข config file ~/.my.cnf

sql_mode = NO _ ENGINE _ SUBSTITUTION,STRICT _ TRANS _ TABLES

default-storage-engine = MYISAM
collation-server = utf8_unicode_ci
character-set-server = utf8

Auto Start

launchd In MacOS, create a file called /Library/LaunchDaemons/com.mariadb.server.plist with the following contents (edit to suit):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key> <string>com.mariadb.server</string>
        <key>KeepAlive</key><true/>
    <key>RunAtLoad</key><true/>
    <key>LaunchOnlyOnce</key><false/>
    <key>ExitTimeOut</key><integer>600</integer>
        <key>WorkingDirectory</key><string>/usr/local/var</string>
        <key>Program</key><string>/usr/local/bin/mysqld</string>
        <key>ProgramArguments</key>
        <array>
        <string>/usr/local/bin/mysqld</string>
        <string>--user=_mysql</string>
        <string>--basedir=/usr/local/opt/mariadb</string>
        <string>--plugin-dir=/usr/local/opt/mariadb/lib/plugin</string>
        <string>--datadir=/usr/local/var/mysql</string>
        <string>--log-error=/usr/local/var/mysql/Data-Server.local.err</string>
        <string>--pid-file=/usr/local/var/mysql/Data-Server.local.pid</string>
        <string>--sql-mode=ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION</string>
        </array>
</dict>
</plist>

Then from a shell, run launchctl load /Library/LaunchDaemons/com.mariadb.server.plist and MariaDB will run immediately, and also upon reboot.


Fix the 2002 socket error first if you haven’t done so from the MySQL section-

sudo mkdir /var/mysql

Location -> /usr/local/Cellar/mariadb/{version}

Data location /usr/local/var/mysql/


sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

Start MySQL

sudo /usr/local/mysql/support-files/mysql.server start

Stop MySQL

sudo /usr/local/mysql/support-files/mysql.server stop

Restart MySQL

sudo /usr/local/mysql/support-files/mysql.server restart

Relate topics