WebDev Handbook

C O N T E N T S

  1. Macports
  2. Apache
  3. MySQL
  4. PHP
  5. SSH
  6. Domain
  7. Troubleshooting
  8. References

  1. Macports
    1. Install Macports
    2. Go to page: https://www.macports.org/install.php
      Select to download package: macOS Monterey v12
      Install package: MacPorts-2.7.2-12-Monterey.pkg
      

    3. Unintall Macports
    4. sudo port -fp uninstall installed sudo dscl . -delete /Users/macports sudo dscl . -delete /Groups/macports sudo rm -rf \ /opt/local \ /Applications/DarwinPorts \ /Applications/MacPorts \ /Library/LaunchDaemons/org.macports.* \ /Library/Receipts/DarwinPorts*.pkg \ /Library/Receipts/MacPorts*.pkg \ /Library/StartupItems/DarwinPortsStartup \ /Library/Tcl/darwinports1.0 \ /Library/Tcl/macports1.0 \ ~/.macports

  2. Apache
    1. Check If Builtin Apache Is Running
    2. ps ax | grep httpd 799 S 0:00.01 /usr/sbin/httpd -D FOREGROUND 393 S 0:00.00 /usr/sbin/httpd -D FOREGROUND 122 Ss 0:00.43 /usr/sbin/httpd -D FOREGROUND 22630 S+ 0:00.00 grep httpd

    3. Disable Builtin Apache
    4. sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist

    5. Check If Builtin Apache Has Been Disabled
    6. ps ax | grep httpd 22663 s001 S+ 0:00.00 grep httpd

    7. Install Apache
    8. sudo port install apache2

    9. Start Apache
    10. sudo port load apache2

    11. Access Apache in Browser
    12. http://localhost/

    13. Edit Apache Document Root File
    14. sudo vi /opt/local/www/apache2/html/index.html

    15. Edit Apache Config File
    16. sudo vi /opt/local/etc/apache2/httpd.conf

    17. Set Server Name in Config File
    18. ServerName localhost:80

    19. Enable User Directories
    20. Uncomment the following lines in config file:
      LoadModule userdir_module lib/apache2/modules/mod_userdir.so Include etc/apache2/extra/httpd-userdir.conf

    21. Add config file
    22. cd /opt/local/etc/apache2/extra/ sudo cp httpd-userdir.conf.orig httpd-userdir.conf

    23. Add Your Virtual Hosts
    24. sudo cp httpd-vhosts.conf.orig httpd-vhosts.conf sudo vi /opt/local/etc/apache2/extra/httpd-vhosts.conf

    25. Restart Apache
    26. sudo apachectl -t sudo port unload apache2 sudo port load apache2

  3. MySQL
    1. Install MySQL
    2. sudo port install mysql8-server

    3. Set Default Version
    4. sudo port select mysql mysql8

    5. Initialize Database
    6. sudo /opt/local/lib/mysql8/bin/mysqld --initialize --user=_mysql sudo port load mysql8-server /opt/local/lib/mysql8/bin/mysql_secure_installation sudo chown -R _mysql:_mysql /opt/local/var/db/mysql8/ sudo chown -R _mysql:_mysql /opt/local/var/run/mysql8/ sudo chown -R _mysql:_mysql /opt/local/var/log/mysql8/

    7. Start MySQL
    8. sudo port load mysql8-server

    9. Check If MySQL Is Running
    10. ps -ax | grep mysql 23688 ?? 0:00.97 /opt/local/lib/mysql8/bin/mysqld 23727 ttys002 0:00.00 grep mysql

    11. Set MySQL Password
    12. /opt/local/lib/mysql8/bin/mysqladmin -u root -p password

    13. Log Into MySQL
    14. mysql -u root -p

    15. Fix "Method Unknown to the Client" error
    16. ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'PASSWORD';

    17. Create Test Databases
    18. CREATE DATABASE IF NOT EXISTS test; SHOW DATABASES; USE test; SHOW TABLES; EXIT;

    19. Restart MySQL
    20. sudo port load mysql8-server sudo port umload mysql8-server

    21. Remove MySQL
    22. sudo port uninstall mysql8 sudo port uninstall mysql8-server sudo port uninstall mysql_select sudo rm -rf /opt/local/var/db/mysql8

  4. PHP
    1. Install PHP
    2. sudo port install php80 sudo port list installed argon2 @20190702 devel/argon2 bzip2 @1.0.8 archivers/bzip2 gettext-runtime @0.21 devel/gettext gsed @4.8 textproc/gsed icu @71.1 devel/icu libedit @20210910-3.1 devel/libedit libiconv @1.17 textproc/libiconv libxml2 @2.10.2 textproc/libxml2 mhash @0.9.9.9 devel/mhash ncurses @6.3 devel/ncurses pcre2 @10.40 devel/pcre php80 @8.0.23 lang/php php_select @1.0 sysutils/php_select pkgconfig @0.29.2 devel/pkgconfig xz @5.2.6 archivers/xz zlib @1.2.12 archivers/zlib

    3. Install PHP SAPIs
    4. sudo port install php80 sudo port install php80-apache2handler cd /opt/local/lib/apache2/modules sudo /opt/local/bin/apxs -a -e -n php mod_php80.so sudo port install php80-cgi sudo port install php80-fpm cd /opt/local/etc/php80/ sudo cp php-fpm.conf.default php-fpm.conf

    5. Install PHP Modules
    6. sudo port install \ php80-curl \ php80-gd \ php80-gettext \ php80-iconv \ php80-imap \ php80-intl \ php80-mbstring \ php80-mcrypt \ php80-mysql \ php80-opcache \ php80-openssl \ php80-sockets \ php80-sqlite \ php80-tidy \ php80-xmlrpc \ php80-xsl \ php80-zip sudo cp /opt/local/etc/php80/php.ini-development /opt/local/etc/php80/php.ini php80-cgi has the following notes: If this is your first install, you need to enable php80-cgi in your web server. php80-mysql has the following notes: To use mysqlnd with a local MySQL server, edit /opt/local/etc/php80/php.ini and set mysql.default_socket, mysqli.default_socket and pdo_mysql.default_socket to the path to your MySQL server's socket file. For mysql80, use /opt/local/var/run/mysql8/mysqld.sock sudo port select --list php Available versions for php: none (active) php80

    7. Activate desired PHP version
    8. sudo port select php php80 Selecting 'php80' for 'php' succeeded. 'php80' is now active. sudo port select --list php Available versions for php: none php80 (active)

    9. Check Which PHP Binary Is Used
    10. which php /opt/local/bin/php

    11. Get PHP Version
    12. php --version PHP 8.0.23 (cli) (built: Sep 12 2022 09:52:43) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.0.23, Copyright (c) Zend Technologies with Zend OPcache v8.0.23, Copyright (c), by Zend Technologies

    13. Edit PHP Config File
    14. sudo vi /opt/local/etc/php80/php.ini

    15. Set Include Path
    16. include_path = ".:/Users/ronludwig/Sites/trivium/phplib"

    17. Edit Apache Config File
    18. sudo vi /opt/local/etc/apache2/httpd.conf

    19. Add Lines To Apache Config File
    20. AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps AddHandler application/x-httpd-php .php

    21. Update Line In Apache Config File
    22. DirectoryIndex index.html index.php

    23. Add Line To Apache Config File
    24. LoadModule php_module lib/apache2/modules/mod_php80.so

    25. Restart Apache
    26. sudo apachectl -t sudo port unload apache2 sudo port load apache2

  5. SSH
    1. Stop SSH
    2. sudo launchctl unload -w /Library/LaunchDaemons/ssh.plist

    3. Configure SSH
    4. Restart SSH
    5. sudo launchctl unload -w /Library/LaunchDaemons/ssh.plist sudo launchctl load -w /Library/LaunchDaemons/ssh.plist

    6. Check if Remote Login is enabled
    7. sudo systemsetup -getremotelogin

    8. Turn off Remote Login
    9. sudo systemsetup -setremotelogin off

    10. Turn on Remote Login
    11. sudo systemsetup -f -setremotelogin on

    12. Fix SSH Error
    13. sudo vi /etc/ssh/ssh_config

    14. Add the following lines to end of file
    15. MACs hmac-md5,hmac-sha1,hmac-sha2-256,umac-64@openssh.com,hmac-ripemd160
      Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc
      HostkeyAlgorithms ssh-dss,ssh-rsa
      KexAlgorithms +diffie-hellman-group1-sha1,diffie-hellman-group14-sha1
      

  6. Domain
    1. Enter in Firefox address bar
    2. about:config

    3. Enter in Firefox address bar
    4. On the bar with the preference name, keep the selection next to Boolean and click the + button to add the preference. browser.fixup.domainwhitelist.gateway browser.fixup.domainwhitelist.hello.local

    5. Click on plus button to make each true
    6. Configure SSH
    7. browser.fixup.domainwhitelist.gateway browser.fixup.domainwhitelist.hello.local

    8. Restart SSH

  7. Troubleshooting
    1. Restart SSH
    2. sudo launchctl unload -w /Library/LaunchDaemons/ssh.plist sudo launchctl load -w /Library/LaunchDaemons/ssh.plist

    3. Check if Remote Login is enabled
    4. sudo systemsetup -getremotelogin

    5. Turn off Remote Login
    6. sudo systemsetup -setremotelogin off

    7. Turn on Remote Login
    8. sudo systemsetup -f -setremotelogin on

    9. Protect your Keys
    10. sudo chmod 600 ~/.ssh/id_rsa sudo chmod 600 ~/.ssh/id_rsa.pub

  8. References