cangir / macos-web-development

Installation script for MacOS web development AMP stack (Apache, MySQL and PHP).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

macos-web-development

Installs MacOS web development AMP stack (Apache, MySQL and PHP).

Why macos-web-development?

Because you want to

./macos-web-development.sh --no-dry-run

... and then instantly create a cool PHP based website at http://cool.test

mkdir -p ~/WebServer/sites/cool/public && echo "<h1>Cool</h1>" >> ~/WebServer/sites/cool/public/index.php

... without reading tutorials and performing installation steps manually. 🀩

You will also be able to create http://cool.com.test or http://cool.co.uk.test or whatever.

Also

Because you want to manage your own stack of independent software, which you are free to mess around with in any way you want. Macos-web-development simply installs packages, mostly with Homebrew (which is also automatically installed), and edits configuration files.

Features

  • Browse http://{any}.test to visit ~/{user}/WebServer/sites/{any}/public (fully customizable path).
  • Switch between PHP versions 5.6 to 7.4 using command sphp {version}, for example sphp 7.2.
  • Distribute Apache vhosts configuraton and PHP ini from template files in repository. Simply adjust them to your needs before installation... or not. πŸ™ƒ
  • Opt out of software you don't want. For example --no-mysql.
  • Dry run – check which software is already installed etc. This is the default behaviour, use --no-dry-run to actually install stuff.
  • Uninstall – not sure when you would use this, but hey, it's a freeeeee world. πŸ˜€

Apache configuration

After installation the Apache vhosts configuration is found at /usr/local/etc/httpd/extra/httpd-vhosts.conf. Change it whenever you want and restart Apache using sudo apachectl -k restart.

PHP ini

The custom PHP ini file is installed as a symlink in each PHP version, pointing to /usr/local/php/php.ini. One file for all PHP versions = enjoy. πŸ₯³

Usage

Full installation (dry run with info)

./macos-web-development.sh

Full installation

./macos-web-development.sh --no-dry-run

Installation with selected versions of PHP and no MySQL

./macos-web-development.sh --no-php-5-6 --no-php-7-0 --no-php-7-4 --no-mysql --no-dry-run

Installation with preset

Common

Installs mandatory stuff and Apache, MySQL, PHP 7.1, 7.2, 7.3 and Dnsmasq.

./macos-web-development.sh --p-common --no-dry-run
Minimal

Installs mandatory stuff and Apache, PHP 7.2 and Dnsmasq. No MySQL.

./macos-web-development.sh --p-minimal --no-dry-run

Uninstallation

Maybe you're poking around with your computer and want to uninstall... install... uninstall... install... 😎

./macos-web-development.sh --uninstall --no-dry-run

See the help for all details

./macos-web-development.sh --help

Installed software

The following software is included in a full installation.

  • xcode-select Xcode command line developer tools. You probably already have this... feel free to pass --no-xcode-select.
  • Homebrew
  • Openldap
  • Libiconv
  • MySQL
  • Dnsmasq to be able to browse http://{any}.test
  • Apache some say it's better with Homebrew than the MacOS default. πŸ€·β€β™‚οΈ Script based Apache PHP configuration (and PHP switching with sphp) only works with a Homebrew:ed Apache.
  • PHP versions 5.6 to 7.4
  • sphp a PHP switching script

All of the above will only be installed if not already on the machine. However, Apache and versions of PHP will only be skipped by default if they were already installed with Homebrew. If not, they will be installed with Homebrew and replace existing ones, which will remain untouched on the system. Should you choose to uninstall with macos-web-development, the existing software should be brought back to life, as if nothing ever happened.

Uninstallation

  • Will not uninstall xcode-select, Homebrew and Openldap.
  • Will not remove the server root folder at ~/WebServer/sites (or the folder you specified), or any websites in there.
  • Will uninstall the MySQL server, but will not remove any databases.
  • Takes no other options than --no-dry-run and will always uninstall all supported versions of PHP etc.

Complementary installation

Should you decide that you need PHP 7.4 after installation without it, just execute a new installation. Installed software will be left alone, and only the missing packages will be installed. This should also work with future releases of PHP, once they're implemented in this script.

Options

Option                                    Description
-h or --help  Display help.
--no-apache Skip Apache.
--no-dnsmasq Skip Dnsmasq. You just won't be able to browse http://{any}.test to automatically visit ~/WebServer/sites/{any}/public. Virtual hosts can still be managed manually.
--no-dry-run Disable dry run and actually install stuff.
--no-mysql Skip MySQL.
--no-php Skip PHP.
--no-php-5-6 Skip PHP 5.6
--no-php-7-0 Skip PHP 7.0
--no-php-7-1 Skip PHP 7.1
--no-php-7-2 Skip PHP 7.2
--no-php-7-3 Skip PHP 7.3
--no-php-7-4 Skip PHP 7.4
--no-php-enable Don't automatically enable the latest version of PHP in currently executing installation.
--no-xcode-select Skip Xcode command line developer tools.
--only-apache Only install Apache.
--only-dnsmasq Only install Dnsmasq.
--only-mysql Only install MySQL.
--only-php Only install PHP.
--only-xcode-select Only install Xcode command line tools.
--p-common Common preset. Sets options --no-php-5-6 --no-php-7-0 --no--php-7-4 --no-xcode-select
--p-minimal Minimal preset. Sets options --no-mysql --no-php-5-6 --no-php-7-0 --no-php-7-1 --no-php-7-3 --no--php-7-4 --no-xcode-select
--uninstall Uninstall. Takes no other options than --no-dry-run and will uninstall all versions of PHP etc.

Credit

Setup is based on these resources

sphp

Script by Andy Miller: Easy Brew PHP version switching

Requirements

MacOS

Successfully tested with a fresh installation of macOS Catalina (10.15.3)

Tested without success on macOS Sierra (10.12.6).

About

Installation script for MacOS web development AMP stack (Apache, MySQL and PHP).

License:MIT License


Languages

Language:Shell 100.0%