Skip to content

Instantly share code, notes, and snippets.

@pmcfernandes
Last active June 16, 2017 16:54
Show Gist options
  • Save pmcfernandes/5ed6c3441f05c16fd99c to your computer and use it in GitHub Desktop.
Save pmcfernandes/5ed6c3441f05c16fd99c to your computer and use it in GitHub Desktop.
Configure Lamp and webmin in Ubuntu Linux
#!/bin/bash
su -i
# Create Swap space
fallocate -l 4G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap sw 0 0' >> /etc/fstab
# Update repository
apt-get update
# Install nano
apt-get install nano ufw fail2ban zip
# Install LAMP server
apt-get install lamp-server^
apt-get install php7.0 libapache2-mod-php7.0 phpmyadmin apache2-utils
# Install PHP 7 plugins
apt-get install php7.0-mcrypt
apt-get install php-mbstring php7.0-mbstring php-gettext
apt-get install php-xcache
apt-get install php-curl
# Configure mysql system tables and secure connection
# mysql_install_db # Obsolete?
/usr/bin/mysql_secure_installation
# Enable mods in Apache2
a2enmod auth_mysql
a2enmod ssl
a2enmod rewrite
a2enmod deflate
a2enmod cache
a2enmod expires
a2enmod headers
# Enable PHP modules
phpenmod mcrypt
# Change permissions for apache
chown -R www-data:www-data /var/www
# Install sendmail
apt-get install sendmail
wget https://gist.githubusercontent.com/pmcfernandes/607a6686dea712429faf/raw/a7a431af3a76365560dcd708ee6a549bdc83f558/sendmail.cf
cp sendmail.cf /etc/mail/sendmail.cf
# Install Webmin
echo "deb http://download.webmin.com/download/repository sarge contrib"$'\n' >> /etc/apt/sources.list
wget -q http://www.webmin.com/jcameron-key.asc -O- | sudo apt-key add -
apt-get update
apt-get install webmin
# Install and enable firewall
ufw enable
ufw allow 20 # FTP
ufw allow 21 # FTP
ufw allow 22 # SSH
ufw allow 25 # SMTP
ufw allow 80 # HTTP
ufw allow 443 # HTTPS
ufw allow 10000 # Webmin
# Install tool for create screenshots inside UNIX
apt-get install wkhtmltopdf
apt-get install xvfb
echo 'xvfb-run --server-args="-screen 0, 1024x768x24" /usr/bin/wkhtmltopdf $*' > /usr/bin/wkhtmltopdf.sh
chmod a+x /usr/bin/wkhtmltopdf.sh
ln -s /usr/bin/wkhtmltopdf.sh /usr/local/bin/wkhtmltopdf
# Install an anti-virus
apt-get install clamav clamav-daemon
dpkg-reconfigure clamav-base
freshclam
# If freshclam not work because process in use
# ps aux | grep -i clamav
# kill -9 <processnumber>
/etc/init.d/clamav-daemon start
# Install Let's Encrypt
cd /usr/local/sbin
wget https://dl.eff.org/certbot-auto
chmod a+x /usr/local/sbin/certbot-auto
# certbot-auto --apache -d example.com -d www.example.com
# certbot-auto renew
# To finsih process must be add follow lines to crontab
# crontab -e
# 30 2 * * 1 /usr/local/sbin/certbot-auto renew >> /var/log/le-renew.log
# Update server
apt-get update
apt-get upgrade
apt-get autoclean
@pmcfernandes
Copy link
Author

Updated to Ubuntu 16.04 +

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment