Skip to content

Instantly share code, notes, and snippets.

@fabienlege
Last active May 26, 2020 12:26
Show Gist options
  • Save fabienlege/5dee0d89df4cdbce6d6a42ca43b9b535 to your computer and use it in GitHub Desktop.
Save fabienlege/5dee0d89df4cdbce6d6a42ca43b9b535 to your computer and use it in GitHub Desktop.
Install webserver (on ubuntu).
#!/bin/sh
#
# Pour lancer ce script, lancer la commande ci-dessous :
# curl -o- https://gist.githubusercontent.com/fabienlege/5dee0d89df4cdbce6d6a42ca43b9b535/raw/webserver_install.sh | bash
#
echo "
_ _____
| | | ___|
__ _ __ _ ___ _ __ ___ ___ | |__ ___ |___ \\
/ _\` |/ _\` |/ _ \\ '_ \\ / __/ _ \\ | '_ \\ / _ \\ \\ \\
| (_| | (_| | __/ | | | (_| __/ | | | | (_) /\__/ /
\\__,_|\\__, |\\___|_| |_|\\___\\___| |_| |_|\\___/\\____/
__/ |
|___/
>> https://agenceho5.com
"
#On demande de choisir le mot de passe admin
echo "Entrez un mot de passe pour l'utilisateur mysqladmin (administrateur MySQL) :"
read mysqlpwd
#Based on this tuto : https://doc.ubuntu-fr.org/lamp
echo "
1. Installation des logiciels nécessaires
=========================================
"
apt install -y apache2 php libapache2-mod-php mysql-server php-mysql php-curl php-gd php-json php-xml git software-properties-common nodejs npm zip unzip
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
#Certbot for free ssl certs
echo "
2. Ajout du dépôt et installation de certbot
============================================
"
add-apt-repository universe
apt update
apt install -y certbot python3-certbot-apache
apt upgrade -y
#Set database root password. replace cSHZ9hkPSXLmn79 by your password
echo "
3. Configuration du serveur MySQL
=================================
"
mysqladmin -u root password $mysqlpwd
mysql -u root -p$mysqlpwd -e "CREATE USER 'mysqladmin'@'%' IDENTIFIED BY '$mysqlpwd';"
mysql -u root -p$mysqlpwd -e "UPDATE mysql.user SET Super_Priv='Y' WHERE user='mysqladmin' AND host='%';"
mysql -u root -p$mysqlpwd -e "GRANT SUPER ON *.* TO mysqladmin@'%';"
mysql -u root -p$mysqlpwd -e "FLUSH PRIVILEGES;"
echo "bind-address = 127.0.0.1" >> /etc/mysql/conf.d/mysql.cnf
service mysql restart
#Installation de composer
echo "
4. Installation de composer
===========================
"
EXPECTED_CHECKSUM="$(wget -q -O - https://composer.github.io/installer.sig)"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]
then
>&2 echo 'ERROR: Invalid installer checksum'
rm composer-setup.php
exit 1
fi
php composer-setup.php --quiet --install-dir=/usr/bin --filename=composer
RESULT=$?
rm composer-setup.php
#Création d'un fichier apache de base
echo "
5. Paramétrage de appache
=========================
"
echo "
<VirtualHost *:80 *:443>
ServerName [REPLACE_THIS].nsi-dev.com
#ServerName www.[REPLACE_THIS].fr
#ServerAlias [REPLACE_THIS].fr
#ServerAlias [REPLACE_THIS].com
#ServerAlias www.[REPLACE_THIS].com
DocumentRoot /var/www/html/[REPLACE_THIS]/web
ErrorLog \${APACHE_LOG_DIR}/[REPLACE_THIS]-error.log
CustomLog \${APACHE_LOG_DIR}/[REPLACE_THIS]-access.log combined
#LETSENCRIPT
#SSLEngine on
#SSLCertificateFile /etc/letsencrypt/live/[REPLACE_THIS].nsi-dev.com/fullchain.pem
#SSLCertificateKeyFile /etc/letsencrypt/live/[REPLACE_THIS].nsi-dev.com/privkey.pem
#CLOUDFLARE
#SSLEngine on
#SSLCertificateFile /etc/cloudflare/[REPLACE_THIS]/cert.pub
#SSLCertificateKeyFile /etc/cloudflare/[REPLACE_THIS]/cert.priv
<Directory /var/www/html/[REPLACE_THIS]/web>
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
</Directory>
# For PHP-FPM only
#<IfModule mod_fastcgi.c>
# AddHandler php7-[REPLACE_THIS]-fcgi .php
# Action php7-[REPLACE_THIS]-fcgi /php7-[REPLACE_THIS]-fcgi virtual
# Alias /php7-[REPLACE_THIS]-fcgi /usr/lib/cgi-bin/php7-[REPLACE_THIS]-fcgi
# FastCgiExternalServer /usr/lib/cgi-bin/php7-[REPLACE_THIS]-fcgi -socket /var/run/php/php7-[REPLACE_THIS]-fpm.sock -pass-header Authorization
#</IfModule>
#
#<IfModule mod_fastcgi.c>
# <FilesMatch \".+\\.ph(p[345]?|t|tml)$\">
# SetHandler php7-[REPLACE_THIS]-fcgi
# </FilesMatch>
#</IfModule>
</VirtualHost>
" >> /etc/apache2/sites-available/bedrock.conf
a2enmod rewrite ssl
a2ensite bedrock.conf
service apache2 restart
echo "
=========================================================
OPPÉRATION TERMINÉE
=========================================================
Pensez à réaliser manuellement les opérations suivantes :
1. vi /etc/apache2/sites-available/bedrock.conf
2. service apache2 relaod
3. certbot certonly --webroot -d [DOMAINE] -w /var/www/html/[SITE]/web
4. vi /etc/apache2/sites-available/bedrock.conf
5. service apache2 relaod
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment