Skip to content

Latest commit

 

History

History
344 lines (244 loc) · 7.76 KB

LAMP-Server-Installation-Documentation.md

File metadata and controls

344 lines (244 loc) · 7.76 KB

GNU/Linux LAMP Server Installation Documentation

Summary

This document describes a basic LAMP (GNU/Linux, Apache2, MySQL, PHP) + GIT server installation, based on a Ubuntu 14.04 GNU/Linux distro. MySQL Databases are backuped locally, the whole server is backup via daily snapshots, as configured by the Client himself while he bought the server.

Severe warning

THIS DOCUMENT IS FOR A LAN DEV ENVIRONMENT ONLY. PRODUCTION/DMZ ENVS CONF ALWAYS UP TO PROFESSIONAL SYSADMINS.

THIS DOCUMENT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SERVER OR THE USE OR OTHER DEALINGS IN THE SERVER.

  • This server configuration do not include any monitoring.
  • One you started to fill logins / passwords, this document become f*cking confidential

Meta

Remote access summary

Server hardware configuration memo

This is not a valid reliable production-ready recommandation, consider it only as an example:

  • OVH VPS Cloud 4 or GANDI custom VPS Server or WhateverCloudProvider VPS
  • vCores: 2
  • RAM: 2 Go
  • HD: 10 Go
  • OS : GNU/Linux
  • Distribution : Ubuntu
  • Version : 14.04
  • Locale : fr_FR.UTF-8

Interface

  • bandwidth: 100 Mb
  • Reverse DNS : myServer.myProvider.com/ IP.ADDRESS

SSH remote connection

root can connect remotely :

[Les Polypodes] ALWAYS use a different Linux (sudoer) user:

Adding French locales

locale-gen fr_FR.UTF-8

Creating a dedicated Linux user lespolypodes, then adding it to sudoers

adduser lespolypodes
adduser lespolypodes sudo

Password for lespolypodes : ThePassword

Server softwares installation

(we use newlines in snippets here because of the f*cking PDF generation of this original markdown document, via LightPaper)

Be up-to-date

ntpdate cdns.ovh.net > /dev/null

Update apt sources:

apt-get update
apt-get upgrade
apt-get dist-upgrade

Basic Shell enhancements

apt-get install vim zsh curl ngrep tree htop sysstat di
apt-get install discus pydf hardinfo lynx ack-grep pandoc
apt-get install most exuberant-ctags
apt-get install linux-headers-generic build-essential
apt-get install manpages-fr manpages-fr-extra
apt-get install manpages-dev silversearcher-ag

LAMP - the bases

apt-get install apache2 apache2-mpm-prefork
apt-get install libapache2-mod-php5 apache2-utils php5
apt-get install mysql-server imagemagick
apt-get install php5-dev phpmyadmin

MySQLroot password: ThePassword

"(...) configuring PhpMyAdmin with dbconfig-common?": yes then apache2

LAMP - extensions

apt-get install php-apc php5-mysql php5-sqlite php5-cli
apt-get install php5-curl php5-gd php5-imagick
apt-get install php5-imap php5-xsl php5-common
apt-get install php5-mcrypt php5-memcache
apt-get install php5-ps php5-intl php5-mcrypt

Then for some unclear reasons, PhpMyAdmin asked later to install /activate mcrypt. Extension is already installed, but just have to run this command:

sudo php5enmod mcrypt

NodeJs

Setup with Ubuntu:

curl -sL https://deb.nodesource.com/setup | sudo bash -

Then install with Ubuntu:

sudo apt-get install -y nodejs

Setup with Debian (as root):

apt-get install curl
curl -sL https://deb.nodesource.com/setup | bash -

Then install with Debian (as root):

apt-get install -y nodejs

Other CLI-related tools

apt-get install tidy markdown git git-core git-doc
apt-get install git-svn git-email tig

Current lespolypodes Linux user becomes an Apacher

adduser lespolypodes www-data

Adding TheClient as ServerName to Apache2 in /etc/apache2/apache2.conf

vim /etc/apache2/apache2.conf

Enabling Apache2 mods

a2enmod rewrite
a2enmod headers
a2enmod deflate
a2enmod expires
a2enmod setenvif
service apache2 restart

PHP

Configuring php.ini (php-cli & apache2):

vim /etc/php5/apache2/php.ini /etc/php5/cli/php.ini -p
[Date]
date.timezone = Europe/Paris

.phar PHP archives need special options:

[Phar]
; http://php.net/phar.readonly
phar.readonly = Off

; http://php.net/phar.require-hash
phar.require_hash = Off

detect_unicode = Off
suhosin.executor.include.whitelist = phar

ZSH

curl -L http://install.ohmyz.sh | sh
chsh 
  • Login shell to indicates : /bin/zsh

Composer (dependency manager for PHP) :

cd /usr/local/bin
sudo su
curl -s http://getcomposer.org/installer | php
mv composer.phar composer
chmod a+x composer

Fail2ban

Configuration:

sudo cp  /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo vim /etc/fail2ban/jail.local
  • Add a /etc/fail2ban/filter.d/apache-w00tw00t.conf
  • [DEFAULT] > ignoreip : add Les Polypodes IP address

PhpMyAdmin

Configuring PhpMyAdmin: Modify ServerAlias phpmyadmin into $$$VeryVerySecretPhpMyAdminURL==! in /etc/apache2/conf-enabled/phpmyadmin.conf

vim /etc/apache2/conf-enabled/phpmyadmin.conf
service apache2 reload

Creating a dedicated Client SQL User + production database: TheClient_prod / TheClient_prod / ThePassword)

Creating & configuring a simple local MySQL backup

Backups archives are generated in /var/backups/mysql every night at 01:00 via root crontab. Backup script uses the /root/.my.cnf configuration file to connect into mysql.

Create a /root/.my.cnf file:

[client]
user=root
pass=ThePassWord

Give it appropriate permissions

chmod 700 /root/.my.cnf
chown root:root /root/.my.cnf

Fetch a copy of the backup script onto the server:

sudo mkdir /var/backups/mysql
sudo chown lespolypodes:root /var/backups/mysql -R
cd /usr/local/bin
sudo curl https://gist.githubusercontent.com/ronanguilloux/1595563/raw/mysqlBackup.sh > automysqlbackup.sh
vim automysqlbackup.sh

Configure backup engine, automysqlbackup.sh with these options:

Nightly backups configuration:

(as root):

su
mv automysqlbackup.sh automysqlbackup
chmod a+x automysqlbackup
crontab -e

Crontab configuration:

# m h  dom mon dow   command
0 1 * * * automysqlbackup

Backup manual test (as root):

cd
automysqlbackup
tree /var/backups/mysql

Appendix

Bash function to generate passwords

# usage: 
# $~:  genpassword 12
genpasswd() {
    local l=$1
    [ "$l" == "" ] && l=16
    tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs
}