-
-
Save jonathanbossenger/618dab103e21f2774aef0a94a234e87d to your computer and use it in GitHub Desktop.
# cloud-config | |
# See https://jonathanbossenger.com/2022/05/25/configuring-ubuntu-in-multipass-for-local-web-development-on-a-macbook/ | |
packages: | |
- software-properties-common | |
- unzip | |
- zip | |
runcmd: | |
# Setting the hostname | |
- echo "Setting the hostname" | |
- echo "wp-local-env" > /etc/hostname | |
- hostname -F /etc/hostname | |
# Adding required repositories | |
- echo "Adding repositories" | |
- add-apt-repository --no-update universe | |
- add-apt-repository --no-update -y ppa:ondrej/php -y | |
- add-apt-repository --no-update -y ppa:ondrej/apache2 -y | |
- apt update | |
- apt upgrade -y | |
# Set up Apache | |
- echo "Installing Apache" | |
- apt install apache2 -y | |
# Set up PHP | |
- echo "Installing PHP" | |
- apt install php libapache2-mod-php php-mysql php-common php-xml php-xmlrpc php-curl php-gd php-imagick php-cli php-dev php-imap php-mbstring php-soap php-zip -y | |
# Set up MySQL | |
- echo "Installing MySQL" | |
- sudo apt install mysql-server -y | |
- service mysql stop | |
- echo "" >> /etc/mysql/mysql.conf.d/mysqld.cnf | |
- echo "default_authentication_plugin=mysql_native_password" >> /etc/mysql/mysql.conf.d/mysqld.cnf | |
- service mysql start | |
- mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';" | |
- mysql -uroot -ppassword -e "FLUSH PRIVILEGES;" | |
# Configure Apache | |
- echo "Configuring Apache" | |
- sed -i s/"export APACHE_RUN_USER=www-data"/"export APACHE_RUN_USER=ubuntu"/g /etc/apache2/envvars | |
- sed -i s/"export APACHE_RUN_GROUP=www-data"/"export APACHE_RUN_GROUP=ubuntu"/g /etc/apache2/envvars | |
- sed -i s/"index.html"/"index.php index.html"/g /etc/apache2/mods-enabled/dir.conf | |
# Configure PHP.ini | |
- echo "Configuring PHP.ini" | |
- touch /etc/php/8.1/apache2/conf.d/user.ini | |
- echo "display_errors=On" >> /etc/php/8.1/apache2/conf.d/user.ini | |
- echo "memory_limit=128M" >> /etc/php/8.1/apache2/conf.d/user.ini | |
- echo "upload_max_filesize=128M" >> /etc/php/8.1/apache2/conf.d/user.ini | |
- echo "post_max_size=1024M" >> /etc/php/8.1/apache2/conf.d/user.ini | |
- echo "max_execution_time=360" >> /etc/php/8.1/apache2/conf.d/user.ini | |
- echo "max_input_time=360" >> /etc/php/8.1/apache2/conf.d/user.ini | |
- echo "extension=soap" >> /etc/php/8.1/apache2/conf.d/user.ini | |
- chown ubuntu:ubuntu /etc/php/8.1/apache2/conf.d/user.ini | |
# Enable Apache modules | |
- echo "Enabling Apache modules" | |
- a2enmod ssl | |
- a2enmod rewrite | |
- service apache2 restart | |
# Create directory to save phpmyadmin and MailHog data | |
- mkdir /run/phpmyadmin | |
# PHPMyAdmin | |
- echo "Installing PHPMyAdmin" | |
- export DEBIAN_FRONTEND=noninteractive | |
- echo "phpmyadmin phpmyadmin/dbconfig-install boolean true" | debconf-set-selections | |
- echo "phpmyadmin phpmyadmin/app-password-confirm password password" | debconf-set-selections | |
- echo "phpmyadmin phpmyadmin/mysql/admin-pass password password" | debconf-set-selections | |
- echo "phpmyadmin phpmyadmin/mysql/app-pass password password" | debconf-set-selections | |
- echo "phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2" | debconf-set-selections | |
- apt-get install -y phpmyadmin | |
- wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.zip -O /run/phpmyadmin/phpmyadmin.zip | |
- unzip /run/phpmyadmin/phpmyadmin.zip -d /run/phpmyadmin/ | |
- mv /usr/share/phpmyadmin/ /usr/share/_phpmyadmin/ | |
- mv /run/phpmyadmin/phpMyAdmin-*-all-languages/ /usr/share/phpmyadmin/ | |
# MailHog | |
- echo "Installing MailHog" | |
- apt-get install golang-go -y | |
- mkdir /run/gocode | |
- echo "export GOPATH=/run/gocode" >> /root/.profile | |
- source /root/.profile | |
- go get github.com/mailhog/MailHog | |
- go get github.com/mailhog/mhsendmail | |
- cp /run/gocode/bin/MailHog /usr/local/bin/mailhog | |
- cp /run/gocode/bin/mhsendmail /usr/local/bin/mhsendmail | |
# Configure Sendmail for PHP | |
- echo "sendmail_path=/usr/local/bin/mhsendmail" >> /etc/php/8.1/apache2/conf.d/user.ini | |
- service apache2 restart | |
# Configure MailHog to start as a system service | |
- IP="$(hostname -I | cut -f1 -d' ')" | |
- touch /etc/systemd/system/mailhog.service | |
- echo "[Unit]" >> /etc/systemd/system/mailhog.service | |
- echo "Description=MailHog service" >> /etc/systemd/system/mailhog.service | |
- echo "[Service]" >> /etc/systemd/system/mailhog.service | |
- echo "ExecStart=/usr/local/bin/mailhog -api-bind-addr $IP:8025 -ui-bind-addr $IP:8025 -smtp-bind-addr 127.0.0.1:1025" >> /etc/systemd/system/mailhog.service | |
- echo "[Install]" >> /etc/systemd/system/mailhog.service | |
- echo "WantedBy=multi-user.target" >> /etc/systemd/system/mailhog.service | |
- service mailhog start | |
- systemctl enable mailhog |
Configure Apache
sed -i s/"export APACHE_RUN_USER=www-data"/"export APACHE_RUN_USER=ubuntu"/g /etc/apache2/envvars
sed -i s/"export APACHE_RUN_GROUP=www-data"/"export APACHE_RUN_GROUP=ubuntu"/g /etc/apache2/envvars
sed -i s/"index.html"/"index.php index.html"/g /etc/apache2/mods-enabled/dir.conf
PHP ini
touch /etc/php/8.1/apache2/conf.d/user.ini
echo "display_errors=On" >> /etc/php/8.1/apache2/conf.d/user.ini
echo "memory_limit=128M" >> /etc/php/8.1/apache2/conf.d/user.ini
echo "upload_max_filesize=128M" >> /etc/php/8.1/apache2/conf.d/user.ini
echo "post_max_size=1024M" >> /etc/php/8.1/apache2/conf.d/user.ini
echo "max_execution_time=360" >> /etc/php/8.1/apache2/conf.d/user.ini
echo "max_input_time=360" >> /etc/php/8.1/apache2/conf.d/user.ini
echo "extension=soap" >> /etc/php/8.1/apache2/conf.d/user.ini
a2enmod ssl
a2enmod rewrite
service apache2 restart
PHPMyAdmin
echo "phpmyadmin phpmyadmin/dbconfig-install boolean true" | debconf-set-selections
echo "phpmyadmin phpmyadmin/app-password-confirm password password" | debconf-set-selections
echo "phpmyadmin phpmyadmin/mysql/admin-pass password password" | debconf-set-selections
echo "phpmyadmin phpmyadmin/mysql/app-pass password password" | debconf-set-selections
echo "phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2" | debconf-set-selections
apt-get install -y phpmyadmin
wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.zip
unzip phpMyAdmin-latest-all-languages.zip
mv /usr/share/phpmyadmin/ /usr/share/_phpmyadmin/
mv ~/phpMyAdmin-*-all-languages/ /usr/share/phpmyadmin/
MailHog
apt-get install golang-go -y
mkdir gocode
echo "export GOPATH=$HOME/gocode" >> ~/.profile
source ~/.profile
go get github.com/mailhog/MailHog
go get github.com/mailhog/mhsendmail
cp /root/gocode/bin/MailHog /usr/local/bin/mailhog
cp /root/gocode/bin/mhsendmail /usr/local/bin/mhsendmail
echo "sendmail_path=/usr/local/bin/mhsendmail" >> /etc/php/8.1/apache2/conf.d/user.ini
service apache2 restart
IP="$(hostname -I | cut -f1 -d' ')"
touch /etc/systemd/system/mailhog.service
echo "[Unit]" >> /etc/systemd/system/mailhog.service
echo "Description=MailHog service" >> /etc/systemd/system/mailhog.service
echo "[Service]" >> /etc/systemd/system/mailhog.service
echo "ExecStart=/usr/local/bin/mailhog -api-bind-addr 192.168.64.2:8025 -ui-bind-addr 192.168.64.2:8025 -smtp-bind-addr 127.0.0.1:1025" >> /etc/systemd/system/mailhog.service
echo "[Install]" >> /etc/systemd/system/mailhog.service
echo "WantedBy=multi-user.target" >> /etc/systemd/system/mailhog.service
service mailhog start
Installation process
- Installable script
- Downloads required GitHub repository into specific location
- Installs mkcert and wpcli
- Runs multipass launch command
- Mounts shared directory for development
- Installs local and multipass sitesetup and sitedrop scripts
Configure MailHog to start as a system service
- IP="$(hostname -I | cut -f1 -d' ')"
- touch /etc/systemd/system/mailhog.service
- echo "[Unit]" >> /etc/systemd/system/mailhog.service
- echo "Description=MailHog service" >> /etc/systemd/system/mailhog.service
- echo "[Service]" >> /etc/systemd/system/mailhog.service
- echo "ExecStart=/usr/local/bin/mailhog -api-bind-addr $IP:8025 -ui-bind-addr $IP:8025 -smtp-bind-addr 127.0.0.1:1025" >> /etc/systemd/system/mailhog.service
- echo "[Install]" >> /etc/systemd/system/mailhog.service
- echo "WantedBy=multi-user.target" >> /etc/systemd/system/mailhog.service
- service mailhog start
- systemctl enable mailhog
Installation requirements
macOS
- Homebrew
- certutil
- Homebrew
Windows
- Powershell
- Chocolatey
Installation
- Install Multipass through brew/choco
Parse Json (get the IP address from the multipass instance)
Windows Install
Base install
Invoke-WebRequest -URI "https://raw.githubusercontent.com/jonathanbossenger/wp-local-env/trunk/windows/install.ps1" -OutFile "wp_local_env_install.ps1"
.\wp_local_env_install.ps1
Install setup scripts
Move-Item -Path "$HOME\sitesetup.ps1" -Destination "C:\Windows\System32\sitesetup.ps1"
Move-Item -Path "$HOME\sitedrop.ps1" -Destination "C:\Windows\System32\sitedrop.ps1"
Move-Item -Path "$HOME\sitehosts.ps1" -Destination "C:\Windows\System32\sitehosts.ps1"
Todo:
Complete server setup
Configure provisioning scripts
Enable OS support