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/

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/

เปลี่ยน 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


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" "">
<plist version="1.0">
        <key>Label</key> <string>com.mariadb.server</string>

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