Skip to content

Instantly share code, notes, and snippets.

@eusonlito
Last active March 6, 2024 12:21
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eusonlito/1f3dc8d667f30709b457 to your computer and use it in GitHub Desktop.
Save eusonlito/1f3dc8d667f30709b457 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ "`whoami`" != 'root' ]; then
echo ""
echo "This script only can be executed by root"
echo ""
exit 1
fi
cat <<EOF > /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8
EOF
echo 'export LC_ALL="en_US.UTF-8"' >> /root/.bashrc
update-locale LANG=en_US.UTF-8
dpkg-reconfigure locales
cd /etc/apt/
sed -i -e 's/^deb-src/# deb-src/' \
-e 's/#\s*deb /deb /' \
-e 's/^deb cdrom.*//' \
sources.list
cd /usr/local/bin/
cat <<EOF > update
apt-get clean
apt-get autoclean
apt-get update && apt-get dist-upgrade --assume-yes --allow-unauthenticated
apt-get autoremove --assume-yes
EOF
chmod 700 update
update
mysqlpassword=`cat /dev/urandom | tr -dc 'a-zA-Z0-9-_!@#$%^&*()_+{}|:<>?=' | fold -w 18 | head -n 1`
debconf-set-selections <<< "mysql-server mysql-server/root_password password $mysqlpassword"
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $mysqlpassword"
cat <<EOF > $HOME/.my.cnf
[mysql]
user=root
password=$mysqlpassword
EOF
export DEBIAN_FRONTEND=noninteractive
add-apt-repository ppa:ondrej/apache2
add-apt-repository ppa:ondrej/php
wget https://dev.mysql.com/get/mysql-apt-config_0.8.29-1_all.deb -O /tmp/mysql-apt.deb
dpkg -i /tmp/mysql-apt.deb
apt-get install -y debconf-utils apache2 curl mcrypt vim-scripts vim-tiny ntpdate \
language-pack-en htop lynx screen tree rsync mysql-server \
php8.3 php8.3-bcmath php8.3-bz2 php8.3-cli php8.3-common php8.3-curl \
php8.3-gd php8.3-fpm php8.3-imagick php8.3-intl php8.3-memcached php8.3-mbstring \
php8.3-mysql php8.3-opcache php8.3-pgsql php8.3-readline php8.3-redis php8.3-tidy \
php8.3-xml php8.3-soap php8.3-xsl php8.3-zip php-apcu php-imagick \
php-memcached php-redis memcached redis-server
if [ ! -d /etc/apache2 ] \
|| [ ! -d /etc/php/8.3 ] \
|| [ ! -d /etc/mysql ]; then
echo ""
echo "Installation failed. Please check previous errors before continue."
echo ""
exit 1
fi
cd /etc/apache2/
if [ -f conf.d/security ]; then
security=conf.d/security
elif [ -f conf-enabled/security.conf ]; then
security=conf-enabled/security.conf
else
security=''
fi
if [ "$security" != "" ]; then
sed -i -e 's/^ServerTokens.*$/ServerTokens Prod/' \
-e 's/^ServerSignature.*$/ServerSignature Off/' \
-e 's/^TraceEnable.*$/TraceEnable Off/' \
$security
fi
a2enmod deflate expires filter headers include proxy_fcgi rewrite setenvif socache_shmcb ssl
cd /etc/php/8.3/fpm/
timezone=`cat /etc/timezone | sed -e 's#/#\\\/#'`
sed -i -e 's/^expose_php =.*$/expose_php = Off/' \
-e 's/^max_execution_time =.*$/max_execution_time = 180/' \
-e 's/^max_input_time =.*$/max_input_time = 240/' \
-e 's/^memory_limit =.*$/memory_limit = 512M/' \
-e 's/^upload_max_filesize =.*$/upload_max_filesize = 200M/' \
-e 's/^post_max_size =.*$/post_max_size = 2G/' \
-e 's/^.*date\.timezone =.*$/date.timezone = "'$timezone'"/' \
-e 's/^.*max_input_vars =.*$/max_input_vars = 10000/' \
php.ini
cp php.ini /etc/php/8.3/cli/
service apache2 restart
echo ""
echo "Finished"
echo ""
echo "MySQL password was stored in $HOME/.my.cnf"
echo ""
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment