Setting up server on Ubuntu 14

Sometimes Ubuntu 14 is still in use when company need to use an old software or scripts. And still a lot of hosting providers are giving possibilities to buy a VPS with Ubuntu 14. For to use a server as a LAMP – for hosting websites and scripts – it’s enough for a small or medium project. In this post I will tell how to setup a server on Ubuntu 14 fast and secure.

First of all, let’s update APT database and upgrade installed by default packages:

# apt-get update
# apt-get upgrade

And then let’s install file manager and text editor:

# apt-get install mc nano

Next step is to install LAMP-server:

# apt-get install apache2 php5 mysql-server phpmyadmin curl libcurl3 libcurl3-dev php5-curl php5-mcrypt

Then turn on some modules:

# a2enmod rewrite
# php5enmod mcrypt

# a2enmod ssl

And then let’s install sendmail and module of it for PHP:

# apt-get install php-mail
# apt-get install sendmail

To send emails from PHP-scripts we need to setup this function in PHP config:

# nano /etc/php5/apache2/php.ini

Find line and add the value:

sendmail_path =  /usr/sbin/sendmail -t -i

To secure server from hacking PHPMyAdmin, let’s hide it’s sub directory:

# nano /etc/phpmyadmin/apache.conf

In the line “Alias /phpmyadmin /usr/share/phpmyadmin” change “/phpmyadmin” to something else. Then reboot Apache:

# /etc/init.d/apache2 restart

To add vistual hosts, let’s make bash-script:

# touch /
# nano /

And paste there this code:

user=www-data group=www-data
dm=`ls /etc/apache2/sites-available/$domain.conf`
if [[ "$dm" = "/etc/apache2/sites-available/$domain.conf" ]]
then echo "Host already exist"
else echo " $domain" >> /etc/hosts
echo "Adding host $domain"
mkdir -p /var/www/$domain
mkdir -p /var/www/$domain/www
chown -R $user:$group /var/www/$domain
echo "<VirtualHost *:80>
ServerName $domain
ServerAlias www.$domain
DocumentRoot /var/www/$domain/www
<Directory /var/www/$domain/www>
Allow from All
Options -Indexes
AllowOverride All
</VirtualHost>" >> /etc/apache2/sites-available/$domain.conf
echo "Add host to Apache"
a2ensite $domain
echo "Restart Apache"
/etc/init.d/apache2 reload
chmod -R 777 /var/www/$domain
echo "Done!"
exit 0

To make it executable:

# chmod +x /

For the server’s security, let’s install and setup some packages:

# apt-get install fail2ban
# apt-get install libapache2-mod-evasive
# nano /etc/apache2/mods-available/mod-evasive.conf

And paste this:

<IfModule mod_evasive20.c>
DOSHashTableSize 4096
DOSPageCount 5
DOSSiteCount 50
DOSPageInterval 1
DOSSiteInterval 1
DOSBlockingPeriod 10

That’s it! More settings and versions of servers I will add to other articles.

(Visited 4 times, 1 visits today)