envdev/lamp-xenial64-fpm/bootstrap.sh

185 lines
7.6 KiB
Bash
Raw Normal View History

2016-05-16 12:00:25 +02:00
#!/usr/bin/env bash
2016-12-05 14:43:40 +01:00
echo 'ubuntu:scores' | sudo chpasswd
2016-05-16 12:00:25 +02:00
VARGANTDEV=1
DIR=/vagrant
DIRDATA=$DIR/data
MYSQL_PASS=scores
2016-06-24 15:13:51 +02:00
MARIADB_VERSION="10.1"
2017-02-08 15:28:26 +01:00
PHPMYADMIN_VERSION="4.6.6"
2016-05-16 12:00:25 +02:00
# --- Add a file action.upgrade to perfom a system upgrade
2016-12-02 10:38:11 +01:00
if [ -f $DIR/action.upgrade ]; then
2016-05-16 12:00:25 +02:00
sudo apt-get update
sudo apt-get -y upgrade
sudo rm -rf $DIR/action.upgrade
fi
# --- Installation Wkhtmltopdf
2016-12-02 10:38:11 +01:00
if [ ! -f /usr/local/bin/wkhtmltopdf ]; then
2017-01-17 13:56:29 +01:00
sudo apt-get install libxrender1 libfontconfig1
2017-02-20 11:27:47 +01:00
wget -q http://download.gna.org/wkhtmltopdf/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
tar xJf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
cp -R wkhtmltox/* /usr/local/
rm -rf wkhtmltox*
2016-05-16 12:00:25 +02:00
fi
# --- Database
2016-12-02 10:38:11 +01:00
if [ $VARGANTDEV -eq 1 ]; then
2016-05-16 12:00:25 +02:00
# --- Installation MariaDB
2016-12-02 10:38:11 +01:00
if [ ! -f /etc/mysql/vagrant ]; then
2016-05-16 12:00:25 +02:00
sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo add-apt-repository 'deb [arch=amd64,i386] http://ftp.igh.cnrs.fr/pub/mariadb/repo/10.1/ubuntu xenial main'
2016-05-16 12:00:25 +02:00
sudo apt-get update
sudo debconf-set-selections <<< "mariadb-server-$MARIADB_VERSION mysql-server/root_password password $MYSQL_PASS"
sudo debconf-set-selections <<< "mariadb-server-$MARIADB_VERSION mysql-server/root_password_again password $MYSQL_PASS"
sudo apt-get -y install mariadb-server mariadb-client
sudo sed -i -e 's/bind-address[ \t]*= 127.0.0.1/bind-address = 0.0.0.0/g' /etc/mysql/my.cnf
sudo sed -i -e 's/max_connections[ \t]*= 100/max_connections = 20/g' /etc/mysql/my.cnf
sudo service mysql restart
# Création utilisateur universel
2016-12-02 13:49:54 +01:00
mysql -uroot -p$MYSQL_PASS -e "CREATE USER 'root'@'%' IDENTIFIED BY '$MYSQL_PASS'"
mysql -uroot -p$MYSQL_PASS -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION"
2016-05-16 12:00:25 +02:00
sudo touch /etc/mysql/vagrant
fi
else
# --- Installation MySQL Server
2016-12-02 10:38:11 +01:00
if [ ! -f /etc/mysql/vagrant ]; then
2016-05-16 12:00:25 +02:00
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password $MYSQL_PASS"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $MYSQL_PASS"
sudo apt-get -y install mysql-server mysql-client
sudo sed -i -e 's/bind-address[ \t]*= 127.0.0.1/bind-address = 0.0.0.0/g' /etc/mysql/my.cnf
sudo sed -i -e 's/max_connections[ \t]*= 100/max_connections = 20/g' /etc/mysql/my.cnf
sudo service mysql restart
sudo touch /etc/mysql/vagrant
fi
fi
# --- PHP
2016-12-02 11:47:24 +01:00
if [ ! -f /usr/bin/php ]; then
# Install
2016-05-16 12:12:01 +02:00
sudo apt-get update
2017-01-04 16:35:58 +01:00
sudo apt-get -y install htop unzip apache2 php7.0-fpm php7.0-cli php7.0-bcmath php7.0-bz2 \
php7.0-curl php7.0-gd php7.0-intl php7.0-json php7.0-mcrypt php7.0-mysql php7.0-soap \
php7.0-xmlrpc php7.0-xsl php-apcu php-mbstring php-zip
2016-12-02 10:38:11 +01:00
if [ $VARGANTDEV -eq 1 ]; then
2016-06-24 15:13:51 +02:00
sudo apt-get -y install php-xdebug
2016-12-02 11:47:24 +01:00
fi
sudo a2enmod autoindex deflate expires headers rewrite actions proxy proxy_fcgi
sudo cp -f $DIRDATA/Apache/phpfcgi.conf /etc/apache2/conf-available/phpfcgi.conf
sudo a2enconf phpfcgi
2016-05-16 12:00:25 +02:00
# --- Configuration PHP / CLI
2016-12-02 10:38:11 +01:00
if [ -f /etc/php/7.0/cli/php.ini ]; then
2016-12-02 11:47:24 +01:00
sudo sed -i -e 's/short_open_tag = Off/short_open_tag = On/g' /etc/php/7.0/cli/php.ini
sudo sed -i -e 's/;mbstring.internal_encoding = UTF-8/mbstring.internal_encoding = UTF-8/g' /etc/php/7.0/cli/php.ini
sudo sed -i -e 's/;date.timezone =/date.timezone = Europe\/Paris/g' /etc/php/7.0/cli/php.ini
2016-05-16 12:00:25 +02:00
fi
# --- Configuration PHP FPM
2016-12-02 10:38:11 +01:00
if [ -f /etc/php/7.0/fpm/php.ini ]; then
2016-10-06 10:35:52 +02:00
sudo sed -i -e 's/max_execution_time = 30/max_execution_time = 300/g' /etc/php/7.0/fpm/php.ini
2016-12-02 11:47:24 +01:00
sudo sed -i -e 's/short_open_tag = Off/short_open_tag = On/g' /etc/php/7.0/fpm/php.ini
2016-10-10 11:55:30 +02:00
sudo sed -i -e 's/;mbstring.internal_encoding = UTF-8/mbstring.internal_encoding = UTF-8/g' /etc/php/7.0/fpm/php.ini
sudo sed -i -e 's/;date.timezone =/date.timezone = Europe\/Paris/g' /etc/php/7.0/fpm/php.ini
sudo sed -i -e 's/post_max_size = 8M/post_max_size = 50M/g' /etc/php/7.0/fpm/php.ini
sudo sed -i -e 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /etc/php/7.0/fpm/php.ini
2016-10-06 10:35:52 +02:00
sudo sed -i -e 's/session.gc_maxlifetime = 1440/session.gc_maxlifetime = 86400/g' /etc/php/7.0/fpm/php.ini
2016-12-02 11:47:24 +01:00
sudo sed -i -e 's/;opcache.enable=0/opcache.enable=1/g' /etc/php/7.0/fpm/php.ini
sudo cp -f $DIRDATA/PHP/xdebug.ini /etc/php/7.0/mods-available/xdebug.ini
2016-12-05 14:52:27 +01:00
# Pool user
2016-12-05 14:43:40 +01:00
sudo sed -i -e 's/user = www-data/user = ubuntu/g' /etc/php/7.0/fpm/pool.d/www.conf
2016-12-05 14:52:27 +01:00
sudo sed -i -e 's/group = www-data/group = ubuntu/g' /etc/php/7.0/fpm/pool.d/www.conf
2017-01-25 16:12:36 +01:00
sudo sed -i -e 's/listen.group = ubuntu/listen.group = www-data/g' /etc/php/7.0/fpm/pool.d/www.conf
2017-01-17 13:56:29 +01:00
2016-05-16 12:00:25 +02:00
# --- Browscap
2016-10-06 10:35:52 +02:00
sudo cp -f $DIRDATA/PHP/php_browscap.ini /etc/php/7.0/fpm/
2016-12-02 11:47:24 +01:00
sudo sed -i -e 's/;browscap = extra\/browscap.ini/browscap = \/etc\/php\/7.0\/fpm\/php_browscap.ini/g' /etc/php/7.0/fpm/php.ini
2016-05-16 12:00:25 +02:00
fi
# --- ChartDirector
2016-12-02 11:47:24 +01:00
#if [ ! -f /usr/lib/php5/20121212/chartdir.lic ]; then
2016-07-29 10:12:44 +02:00
#sudo cp -R $DIRDATA/ChartDirector/lib/fonts /usr/lib/php5/20121212/
#sudo chown -R 777 /usr/lib/php5/20121212/fonts
#sudo cp $DIRDATA/ChartDirector/lib/libchartdir.so /usr/lib/php5/20121212/
#sudo cp $DIRDATA/ChartDirector/lib/phpchartdir550.dll /usr/lib/php5/20121212/
#sudo cp $DIRDATA/ChartDirector/chartdir.lic /usr/lib/php5/20121212/
#sudo cp $DIRDATA/ChartDirector/chartdir.ini /etc/php5/mods-available/
#sudo php5enmod chartdir
2016-12-02 11:47:24 +01:00
#fi
sudo service php7.0-fpm restart
2016-05-16 12:00:25 +02:00
fi
# --- Composer
2016-12-02 10:38:11 +01:00
if [ ! -f /usr/local/bin/composer ]; then
2016-05-16 12:00:25 +02:00
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
fi
# --- Installation phpMyAdmin
PHPMYADMIN_DIR="phpMyAdmin-$PHPMYADMIN_VERSION-all-languages"
PHPMYADMIN_URL="https://files.phpmyadmin.net/phpMyAdmin"
2016-12-02 10:38:11 +01:00
if [ ! -d "/home/vhosts/$PHPMYADMIN_DIR" ]; then
2016-05-16 12:00:25 +02:00
wget -q "$PHPMYADMIN_URL/$PHPMYADMIN_VERSION/$PHPMYADMIN_DIR.tar.xz" -O "/home/vagrant/$PHPMYADMIN_DIR.tar.xz"
2016-12-02 10:38:11 +01:00
if [ -f "/home/vagrant/$PHPMYADMIN_DIR.tar.xz" ]; then
2016-05-16 12:00:25 +02:00
tar xJvf "/home/vagrant/$PHPMYADMIN_DIR.tar.xz" --directory /home/vhosts/
mysql -uroot -p$MYSQL_PASS < /home/vhosts/$PHPMYADMIN_DIR/sql/create_tables.sql
mysql -uroot -p$MYSQL_PASS < $DIRDATA/Apps/phpmyadmin.sql
2016-05-16 12:00:25 +02:00
sudo service mysql restart
cp $DIRDATA/Apps/config.inc.php /home/vhosts/$PHPMYADMIN_DIR/
chmod 0644 /home/vhosts/$PHPMYADMIN_DIR/config.inc.php
2016-05-16 12:00:25 +02:00
fi
fi
# --- Configuration Apache
2016-12-02 10:38:11 +01:00
if [ ! -f /etc/apache2/conf-available/httpd.conf ]; then
2016-05-16 12:00:25 +02:00
sudo echo "ServerName 127.0.0.1" > /etc/apache2/conf-available/httpd.conf
sudo a2enconf httpd
fi
# --- Disable all website
cd /etc/apache2/sites-available/
for f in *.conf; do
if [ $f = "000-default.conf" ]; then
continue
fi
if [ $f = "default-ssl.conf" ]; then
continue
fi
sudo a2dissite $f;
sudo rm -vf /etc/apache2/sites-available/$f;
done;
# --- phpmyadmin.sd.dev
2016-06-24 15:13:51 +02:00
cp -f $DIRDATA/Apache/phpmyadmin.conf $DIR/vhosts/phpmyadmin.conf
sed -i -e "s/VERSION/$PHPMYADMIN_VERSION/" $DIR/vhosts/phpmyadmin.conf
2016-05-16 12:00:25 +02:00
# --- test.sd.dev
cp -f $DIRDATA/Apache/test.conf $DIR/vhosts/test.conf
2016-12-02 10:38:11 +01:00
if [ ! -d /home/vhosts/test ]; then
2016-05-16 12:00:25 +02:00
sudo mkdir /home/vhosts/test
fi
# --- Copy Vhosts files
VHOSTS='000-default.conf'
cd $DIR/vhosts/
for f in *.conf; do
if [ $f = "000-default.conf" ]; then
continue
fi
if [ $f = "default-ssl.conf" ]; then
continue
fi
2016-12-02 10:38:11 +01:00
if [ -f $f ]; then
2016-12-02 11:47:24 +01:00
sudo cp -vf $f /etc/apache2/sites-available/
2016-05-16 12:00:25 +02:00
VHOSTS+=" $f"
fi
done;
sudo a2ensite $VHOSTS
# --- Restart apache
sudo service apache2 restart
2016-06-29 11:32:16 +02:00