Skip to content

Instantly share code, notes, and snippets.

@smaknsk
Last active January 1, 2016 15:39
Show Gist options
  • Save smaknsk/8165875 to your computer and use it in GitHub Desktop.
Save smaknsk/8165875 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Provision for Vagrant box ArchLinux
#
# Insert to Vagrantfile:
# config.vm.provision "shell", path: "https://gist.github.com/smaknsk/8165875/raw"
#
#
# Run nginx, httpd, php-fpm as user:
#
user="vagrant"
group="vagrant"
host_ip="192.168.33.1"
#
# Base packeges
#
pacman -Syu --noconfirm
pacman -S --noconfirm --needed wget mc git tig mlocate
#
# Development server packages
#
pacman -S --noconfirm --needed mariadb nginx php-fpm memcached
pacman -S --noconfirm --needed php-gd php-intl php-mcrypt php-memcache xdebug phpmyadmin php-composer php-xsl
pacman -S --noconfirm --needed nodejs
pacman -S --noconfirm --needed imagemagick
#
# Install NPM packeges
#
echo "Installing bower..."
npm install -g bower &>/dev/null
#
# Function Install from AUR
#
function aurinstall() {
# Check is root
if [ $EUID -ne 0 ]; then
echo "You must run as root user" 2>&1
return 1
fi
local PKGNAME
for PKGNAME in $@; do
echo "Installing ${PKGNAME}..."
local PKGDEST=/tmp/makepkg_${PKGNAME}
/usr/bin/mkdir ${PKGDEST}
cd ${PKGDEST}
/usr/bin/curl -s https://aur.archlinux.org/packages/${PKGNAME:0:2}/${PKGNAME}/${PKGNAME}.tar.gz | /usr/bin/tar -zx
cd ${PKGNAME}
/usr/bin/chown nobody:nobody -R ${PKGDEST}
/usr/bin/sudo -u nobody /usr/bin/makepkg -s --noconfirm PKGDEST=${PKGDEST} &>/dev/null
/usr/bin/pacman -U --needed --noconfirm `/usr/bin/find ${PKGDEST}/*pkg.tar.xz`
rm -r ${PKGDEST}
done
}
#
# Additional packages
#
aurinstall aurget php-imagick
#
# Configure PHP-FPM
#
sed -i "s/user = http/user = $user/" /etc/php/php-fpm.conf
sed -i "s/group = http/group = $group/" /etc/php/php-fpm.conf
sed -i "s/listen.owner = http/listen.owner = $user/" /etc/php/php-fpm.conf
sed -i "s/listen.group = http/listen.group = $group/" /etc/php/php-fpm.conf
#
# Configure nginx
#
usermod -G log -a $user
#
# Configure php
#
sed -i "s/short_open_tag = Off/short_open_tag = On/" /etc/php/php.ini
sed -i "s/display_errors = Off/display_errors = On/" /etc/php/php.ini
sed -i "s/error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT/error_reporting = E_ALL/" /etc/php/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 100M/" /etc/php/php.ini
sed -i "s/post_max_size = 8M/post_max_size = 108M/" /etc/php/php.ini
sed -i "s/expose_php = On/expose_php = Off/" /etc/php/php.ini
sed -i "s/;extension=calendar.so/extension=calendar.so/" /etc/php/php.ini
sed -i "s/;extension=exif.so/extension=exif.so/" /etc/php/php.ini
sed -i "s/;extension=gd.so/extension=gd.so/" /etc/php/php.ini
sed -i "s/;extension=iconv.so/extension=iconv.so/" /etc/php/php.ini
sed -i "s/;extension=intl.so/extension=intl.so/" /etc/php/php.ini
sed -i "s/;extension=mcrypt.so/extension=mcrypt.so/" /etc/php/php.ini
sed -i "s/;extension=mysqli.so/extension=mysqli.so/" /etc/php/php.ini
sed -i "s/;extension=mysql.so/extension=mysql.so/" /etc/php/php.ini
sed -i "s/;extension=openssl.so/extension=openssl.so/" /etc/php/php.ini
sed -i "s/;extension=pdo_mysql.so/extension=pdo_mysql.so/" /etc/php/php.ini
sed -i "s/;extension=phar.so/extension=phar.so/" /etc/php/php.ini
sed -i "s/;extension=posix.so/extension=posix.so/" /etc/php/php.ini
sed -i "s/;extension=shmop.so/extension=shmop.so/" /etc/php/php.ini
sed -i "s/;extension=soap.so/extension=soap.so/" /etc/php/php.ini
sed -i "s/;extension=sysvmsg.so/extension=sysvmsg.so/" /etc/php/php.ini
sed -i "s/;extension=sysvsem.so/extension=sysvsem.so/" /etc/php/php.ini
sed -i "s/;extension=sysvshm.so/extension=sysvshm.so/" /etc/php/php.ini
sed -i "s/;extension=xsl.so/extension=xsl.so/" /etc/php/php.ini
sed -i "s/;extension=zip.so/extension=zip.so/" /etc/php/php.ini
sed -i "s/open_basedir = \/srv\/http\/:\/home\/:\/tmp\/:\/usr\/share\/pear\/:\/usr\/share\/webapps\//open_basedir = \/srv\/http\/:\/home\/:\/tmp\/:\/usr\/share\/pear\/:\/usr\/share\/webapps\/:\/etc\/webapps\/:\/vagrant\/:\/usr\/local\/bin\//" /etc/php/php.ini
sed -i "s/;sendmail_path =/sendmail_path = \"\/usr\/bin\/php \/vagrant\/www\/smak.dev\/www\/mail\/fake_mail.php\"/" /etc/php/php.ini
sed -i "s/;date.timezone =/date.timezone = Asia\/Novosibirsk/" /etc/php/php.ini
sed -i "s/;//" /etc/php/conf.d/{memcache.ini,xdebug.ini,imagick.ini}
sed -i "s/xdebug.remote_host=127.0.0.1/xdebug.remote_host=$host_ip/" /etc/php/conf.d/xdebug.ini
#
# Configure PhpMyAdmin
#
sed -i "s/\$cfg['Servers'][\$i]['auth_type'] = 'cookie';/\$cfg['Servers'][\$i]['auth_type'] = 'config';/" /etc/webapps/phpmyadmin/config.inc.php
if ! grep -q "\$cfg['Servers'][\$i]['user'] = 'root';" /etc/webapps/phpmyadmin/config.inc.php;
then
cat >> /etc/webapps/phpmyadmin/config.inc.php << EOL
<?php
\$cfg['Servers'][\$i]['user'] = 'root';
\$cfg['Servers'][\$i]['password'] = 'root';
?>
EOL
fi
#
# Init mariadb
#
mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
#
# Services start and enable
#
systemctl enable mysqld nginx php-fpm memcached
systemctl start mysqld nginx php-fpm memcached
#
# Configure MySQL
#
mysqladmin password 'root'
cat > /home/$user/.my.cnf << EOL
[client]
user=root
password=root
EOL
cat > /root/.my.cnf << EOL
[client]
user=root
password=root
EOL
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION"
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'root' WITH GRANT OPTION"
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY 'root' WITH GRANT OPTION"
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'::1' IDENTIFIED BY 'root' WITH GRANT OPTION"
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'vagrant-arch.vagrantup.com' IDENTIFIED BY 'root' WITH GRANT OPTION"
mysql -e "GRANT ALL PRIVILEGES ON *.* TO ''@'localhost' IDENTIFIED BY 'root'"
mysql -e "GRANT ALL PRIVILEGES ON *.* TO ''@'vagrant-arch.vagrantup.com' IDENTIFIED BY 'root'"
mysql -e "DROP USER 'root'@'localhost'"
mysql -e "DROP USER 'root'@'127.0.0.1'"
mysql -e "DROP USER 'root'@'::1'"
mysql -e "DROP USER 'root'@'vagrant-arch.vagrantup.com'"
mysql -e "DROP USER ''@'localhost'"
mysql -e "DROP USER ''@'vagrant-arch.vagrantup.com'"
mysql -e "FLUSH PRIVILEGES"
mysql -e "DROP DATABASE IF EXISTS test"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment