Skip to content

Instantly share code, notes, and snippets.

@1337god
Last active March 8, 2020 16:10
Show Gist options
  • Save 1337god/3cc41adea25da8dde373a32b206e7c9f to your computer and use it in GitHub Desktop.
Save 1337god/3cc41adea25da8dde373a32b206e7c9f to your computer and use it in GitHub Desktop.
Web Server installation Tutorial + NextCloud in a Mini PC

Script for Web Server installation Tutorial + NextCloud in a Mini PC

Commands for the Web Server installation Tutorial + NextCloud in a Mini PC Tutorial in https://medium.com/biddix-report/web-server-installation-tutorial-nextcloud-in-a-mini-pc-5df14142a086

Base steps

sudo locale-gen en_US.UTF-8

# Enable multiverse repository
sudo sed -i "/^# deb.*multiverse/ s/^# //" /etc/apt/sources.list

# Get updates
sudo apt-get update
sudo apt-get upgrade -y
sudo apt dist-upgrade
sudo apt autoremove

# Install build tools and other needed packages
sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline-dev libyaml-dev libcurl4-openssl-dev curl git-core mysql-client libmysqlclient-dev libxslt-dev libxml2-dev software-properties-common fail2ban zip unzip ntp htop

# Setup users
sudo adduser [username]
sudo usermod -aG sudo [username]

# Configure ssh keys
echo "Upload your ssh public key"
echo "scp ~/.ssh/id_rsa.pub [username]@[server]:/home/[username]/"
read
mkdir /home/[username]/.ssh
mv /home/[username]/id_rsa.pub /home/[username]/.ssh/authorized_keys
chown -R [username]:[username] /home/[username]/.ssh
chmod 700 /home/[username]/.ssh
chmod 600 /home/[username]/.ssh/authorized_keys

# Configure SSH
nano /etc/ssh/sshd_config
service ssh restart

To configure SSH follow the How to Harden your Ubuntu 18.04 Server tutorial for the configuration.

Python

sudo apt-get install -y python python-pip python-dev python-virtualenv python-setuptools python3-pip python3-setuptools
sudo pip install virtualenvwrapper

Shell

sudo apt-get install -y zsh
chsh -s $(which zsh)
curl -L http://install.ohmyz.sh | sh
curl -sSL git.io/jovial | sudo bash -s [username]

MySQL

sudo apt install -y phpmyadmin mysql-server mysql-client
sudo mysql_secure_installation
sudo service mysql stop
sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
jobs
mysql -u root
FLUSH PRIVILEGES;
USE mysql;
UPDATE user SET authentication_string=PASSWORD("YOUR_MYSQL_PASSWORD") WHERE User='root';
UPDATE user SET plugin="mysql_native_password" WHERE User='root';
quit
sudo service mysql restart

Web Server

sudo apt install -y apache2 apache2-utils 

#Adds you to the www-data group
sudo usermod -a -G $(whoami) www-data

#Change ownership (recursively) of the web server folder
sudo chown -hR www-data:www-data /var/www/html
sudo chmod g+rwx /var/www/html

PHP

sudo apt install -y php7.2-common libapache2-mod-php php7.2-cli php7.2-opcache php7.2-gd php7.2-mysql php7.2-curl php7.2-intl php7.2-xsl php7.2-mbstring php7.2-zip php7.2-bcmath php-gettext php-apcu php7.2-soap

Tweak PHP

sudo sed -i "s/memory_limit = .*/memory_limit = 1024M/" /etc/php/7.2/apache2/php.ini
sudo sed -i "s/post_max_size = 8M/post_max_size = 16M/g" /etc/php/7.2/apache2/php.ini
sudo sed -i "s/upload_max_filesize = .*/upload_max_filesize = 256M/" /etc/php/7.2/apache2/php.ini
sudo sed -i "s/zlib.output_compression = .*/zlib.output_compression = on/" /etc/php/7.2/apache2/php.ini
sudo sed -i "s/max_execution_time = .*/max_execution_time = 18000/" /etc/php/7.2/apache2/php.ini
sudo sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/7.2/apache2/php.ini
sudo sed -i "s/;opcache.save_comments.*/opcache.save_comments = 1/" /etc/php/7.2/apache2/php.ini
sudo sed -i "s/;opcache.enable=0/opcache.enable=1/g" /etc/php/7.2/apache2/php.ini
sudo sed -i "s/;opcache.enable_cli=0/opcache.enable_cli=1/g" /etc/php/7.2/apache2/php.ini
sudo sed -i "s/;opcache.interned_strings_buffer=4/opcache.interned_strings_buffer=8/g" /etc/php/7.2/apache2/php.ini
sudo sed -i "s/;opcache.max_accelerated_files=2000/opcache.max_accelerated_files=10000/g" /etc/php/7.2/apache2/php.ini
sudo sed -i "s/;opcache.memory_consumption=64/opcache.memory_consumption=128/g" /etc/php/7.2/apache2/php.ini
sudo sed -i "s/;opcache.revalidate_freq=2/opcache.revalidate_freq=1/g" /etc/php/7.2/apache2/php.ini

Databases

mysql -u root -p -e CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'RANDOM_PASSWORD';"
mysql -u root -p -e CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'RANDOM_PASSWORD';"
mysql -u root -p -e "CREATE DATABASE nextcloud;"
mysql -u root -p -e "CREATE DATABASE wordpress;"
mysql -u root -p -e "GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost';"
mysql -u root -p -e "GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost';"
mysql -u root -p -e "FLUSH PRIVILEGES;"

Web Files (Wordpress + eZServerMonitor) + NextCloud

wget https://download.nextcloud.com/server/releases/latest.zip -O nextcloud.zip
wget https://wordpress.org/latest.zip -O wordpress.zip
wget https://www.ezservermonitor.com/esm-web/downloads/version/2.5 -O servermonitor.zip
unzip nextcloud.zip
unzip wordpress.zip
unzip servermonitor.zip
rm *.zip
sudo mv nextcloud /var/www/html
sudo mv eZServerMonitor-2.5 /var/www/html/servermonitor
cd $(pwd)/wordpress
sudo mv * /var/www/html
cd ..
rm -rf wordpress
sudo chown -hR www-data:www-data /var/www/html
sudo rm -rf /var/www/html/index.html
sudo sed -i "s|'filelocking.enabled' => true,|'filelocking.enabled' => true,\n  'memcache.local' => '\OC\Memcache\APCu',|g" /var/www/html/nextcloud/config/config.sample.php

Extras

GeoIP

sudo apt-get install geoip-bin
cd /usr/share/GeoIP/
sudo wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
sudo wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
sudo gunzip *.dat.gz

GUI

# Unity (The Default Desktop)
sudo apt-get install ubuntu-desktop

# Gnome
sudo apt-get install gnome-desktop-environment

# KDE
sudo add-apt-repository ppa:kubuntu-ppa/backports
sudo apt-get install kubuntu-desktop

# LXDE (Lubuntu)
sudo apt-get install lubuntu-desktop

# MATE
sudo apt-get install mate-desktop

# XFCE (Xubuntu)
sudo apt-get install xubuntu-desktop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment