Skip to content

Instantly share code, notes, and snippets.

@ukadev
Last active November 6, 2022 16:25
Show Gist options
  • Save ukadev/7446d35ab2eb490b37ba5b759e1566e8 to your computer and use it in GitHub Desktop.
Save ukadev/7446d35ab2eb490b37ba5b759e1566e8 to your computer and use it in GitHub Desktop.
Minimal vagrant provision for lamp on Ubuntu with PHP8.1 with xdebug3 and also composer, phpmyadmin and laravel installer (and virtualhost).
#!/bin/bash
# Set the same ip as in your VagrantFile in order to configure xdebug
VAGRANT_IP= 192.168.33.10
# Here you can set the root mySQL password
MYSQL_PASSWORD="toor"
# For each of the following list, you can enable or disable its installation, setting it to false
# NOTE: You have to enable Apache and MySQL installations to be able to install phpMyAdmin, otherwise it'll be skipped.
INSTALL_APACHE=true
INSTALL_PHP=true
INSTALL_XDEBUG=true
INSTALL_MYSQL=true
INSTALL_NODEJS=true
INSTALL_COMPOSER=true
INSTALL_PHPMYADMIN=true
INSTALL_LARAVEL_INSTALLER=true
INSTALL_LARAVEL_VIRTUALHOST=true
apt-get update
if [ "$INSTALL_APACHE" = true ]
then
apt-get install -y apache2 acl pkg-config libssl-dev git zip
a2enmod rewrite
service apache2 restart
fi
if [ "$INSTALL_MYSQL" = true ]
then
echo "mysql-server mysql-server/root_password password $MYSQL_PASSWORD" | debconf-set-selections
echo "mysql-server mysql-server/root_password_again password $MYSQL_PASSWORD" | debconf-set-selections
apt-get install -y mysql-server
mysql -u USER -p$MYSQL_PASSWORD -e "alter user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '$MYSQL_PASSWORD';"
fi
if [ "$INSTALL_PHP" = true ]
then
add-apt-repository ppa:ondrej/php
apt-get install -y php8.1 php8.1-dev libapache2-mod-php8.1 libmcrypt-dev php8.1-mysql php8.1-curl php8.1-gd php8.1-cli php-pear php8.1-intl php8.1-apcu php8.1-mbstring php8.1-zip php8.1-dom php8.1-xml zip
phpenmod mcrypt
if [ "$INSTALL_XDEBUG" = true ]
then
apt-get install php8.1-xdebug
rm /etc/php/8.1/mods-available/xdebug.ini
cat >> /etc/php/8.1/mods-available/xdebug.ini << EOF
zend_extension=xdebug.so
xdebug.idekey=PHPSTORM
xdebug.client_host=$VAGRANT_IP
xdebug.mode=debug
xdebug.var_display_max_depth = 10
EOF
fi
fi
if [ "$INSTALL_NODEJS" = true ]
then
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
apt-get install -y nodejs
fi
if [ "$INSTALL_COMPOSER" = true ]
then
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
fi
if [ "$INSTALL_PHPMYADMIN" = true ]
then
if [ "$INSTALL_APACHE" = true ] && [ "$INSTALL_MYSQL" = true ]
then
add-apt-repository ppa:phpmyadmin/ppa
apt-get update
echo "phpmyadmin phpmyadmin/dbconfig-install boolean true" | debconf-set-selections
echo "phpmyadmin phpmyadmin/database-type select mysql" | debconf-set-selections
echo "phpmyadmin phpmyadmin/app-password-confirm password $MYSQL_PASSWORD" | debconf-set-selections
echo "phpmyadmin phpmyadmin/mysql/admin-pass password $MYSQL_PASSWORD" | debconf-set-selections
echo "phpmyadmin phpmyadmin/mysql/app-pass password $MYSQL_PASSWORD" | debconf-set-selections
echo "phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2" | debconf-set-selections
echo "phpmyadmin phpmyadmin/mysql/method select Unix socket" | debconf-set-selections
echo "phpmyadmin phpmyadmin/db/dbname string phpmyadmin" | debconf-set-selections
echo "phpmyadmin phpmyadmin/remote/host select localhost" | debconf-set-selections
apt-get install -y phpmyadmin
fi
fi
if [ "$INSTALL_LARAVEL_INSTALLER" = true ]
then
composer global require laravel/installer
export PATH="~/.config/composer/vendor/bin:$PATH"
fi
if [ "$INSTALL_LARAVEL_VIRTUALHOST" = true ]
then
rm /etc/apache2/sites-available/000-default.conf
cat >> /etc/apache2/sites-available/000-default.conf << EOF
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/public
<Directory /var/www/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
EOF
service apache2 restart
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment