Saving you some time

Submitted by admindm on Mon, 11/04/2013 - 21:01

Lest get scripting

As most of you won't have administered a Ubuntu web server before then its likely your going to screw things up at some point, and before you go live with an importent site I encourage you to experiment and screw things up as much as possible. When you screw things up you will find yourself going back to the start of this guide and following it again. While its good to repeat things when we need to learn there comes a point where its getting irritating to run through the same crap again and again. 

To solve this issue I have written all of the previous commands into a script. Once you get connected to your server you can upload the script and it will do most of the work for you. There are a few things I have left out and I will list them here but at the bottom of the page you will find the script. If you have read ahead or you don't really understand everything you have done so far then I suggest you go back to the start and follow the guide. There is no point getting your web server setup if you can't fix problems later on. To prevent lazy people just copying the script and never even reading the guid I have included a small bug that will be easy to spot for anyone who has followed the guide or already knows how to do all this.

Left out of the script is

  1. User creation
  2. Creating you site in apache

And here is the script

 

#!/bin/bash
 
# Sets up a webserver following thew instructions at http://foreverythingit.co.uk
# Feel free to use this, modify it and repost it but please always credit the source
 
##### Constants
 
##### Script
 
##Start by running an update
sudo aptitude update
sudo aptitude upgrade -y
sudo aptitude autoclean
 
##Next change the screen resolution to 1024x768
sudo sed s/#GRUB_GFXMODE=640x480/GRUB_GFXMODE=1024x768/ -i /etc/default/grub
sudo update-grub
 
##next disable ctrl-alt-delete
sudo sed 's/exec shutdown -r now "Control-Alt-Delete pressed"/#exec shutdown -r now "Control-Alt-Delete pressed"/' -i /etc/init/control-alt-delete.conf
 
##Setup firewall ports and enable ufw
sudo ufw enable
sudo ufw allow 20
sudo ufw allow 21
sudo ufw allow 22
sudo ufw allow 23
sudo ufw allow 80
sudo ufw allow 443
 
##Set up CA/SSL certificates
#openssl genrsa -des3 -out server.key 2048
#openssl rsa -in server.key -out server.key.insecure
#mv server.key server.key.secure
#mv server.key.insecure server.key
#openssl req -new -key server.key -out server.csr
#openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
#sudo cp server.crt /etc/ssl/certs
#sudo cp server.key /etc/ssl/private
 
#install phpmyadmin
sudo apt-get -y install phpmyadmin
 
#add a group for webusers
sudo addgroup webuser
 
#Setup the SSH jail
sudo sed s,Subsystem sftp /usr/lib/openssh/sftp-server,Subsystem sftp internal-sftp, -i /etc/ssh/sshd_config
sudo sh -c "echo -e \"\n\" >> /etc/ssh/sshd_config"
sudo sh -c "echo -e \"\n\" >> /etc/ssh/sshd_config"
sudo sh -c "echo -e \"\n\" >> /etc/ssh/sshd_config"
sudo sh -c "echo -e \"Match Group webuser\" >> /etc/ssh/sshd_config"
sudo sh -c "echo -e \"     ChrootDirectory %h\" >> /etc/ssh/sshd_config"
sudo sh -c "echo -e \"     ForceCommand internal-sftp\" >> /etc/ssh/sshd_config"
sudo sh -c "echo -e \"\n\" >> /etc/ssh/sshd_config"
sudo service ssh restart
 
# install fail 2 ban
sudo apt-get -y install fail2ban
 
#instal PECL/PEAR
sudo apt-get -y install php-pear php5-dev build-essential
sudo pecl install uploadprogress
sudo sh -c "echo -e \"\; activate and configurate for php uploadprogress module\" >> /etc/php5/apache2/conf.d/uploadprogress.ini"
sudo sh -c "echo -e \"extension=uploadprogress.so\" >> /etc/ssh/sshd_config"
 
#installing lib2ssh
sudo apt-get -y install libssh2-php
 
#Upping the php max upload filesize
sudo sed s/upload_max_filesize = 2M/upload_max_filesize = 16M/ -i /etc/php5/apache2/php.ini
sudo service apache2 restart
 
#Set the server name
sudo sh -c "echo -e \"ServerName localhost\" >> /etc/apache2/httpd.conf"
 
##Run another update just incase we accidentally installed an old version
sudo aptitude update
sudo aptitude upgrade -y
sudo aptitude autoclean
 
##sudo reboot