[Linux] Web Service環境安裝建置 by LNMP – Ubuntu 16.04

LNMP Server Environment Installation

  • Version: 1.2.0
  • Environment: Ubuntu 16.04 LTS

Installer on Github


Set server time zone data

dpkg-reconfigure tzdata

Update dateSet (Add to crontab is recommended)

ntpdate time.stdtime.gov.tw

Add user

adduser nick
visudo 
    > nick_tsai ALL=(ALL) NOPASSWD:ALL

# Change deault editor if needed
update-alternatives --config editor  

# SSH password login: vi /etc/ssh/sshd_config
    > PasswordAuthentication yes
service ssh restart

Install webserver using nginx

apt-get install nginx

Configuration:

/etc/nginx/nginx.conf
  > client_max_body_size 128M;    
  > worker_processes 2; (if instance core is 2)

Install php-fpm (php7.0-fpm) with extensions

apt-get install php-fpm php-mysql php-cli php-mcrypt php-curl php-mbstring php-imagick php-gd php-xml php-zip
apt-get install php-memcached memcached 
phpenmod mcrypt

Install php-fpm 5.6 (Using PPA for PHP)

apt-get install software-properties-common
apt-get install python-software-properties
apt-add-repository ppa:ondrej/php
apt-get update
apt-get install php5.6-fpm php5.6-mysql php5.6-cli php5.6-mcrypt php5.6-curl php5.6-mbstring php5.6-imagick php5.6-gd php5.6-xml php5.6-zip

Configuration

   /etc/php/7.0/fpm/php.ini 
      > cgi.fix_pathinfo = 0
      > mbstring.internal_encoding = UTF-8 (uncomment)
      > max_input_vars = 5000
      > post_max_size=64M
      > upload_max_filesize=64M

   /etc/php/7.0/fpm/pool.d/www.conf
       > pm.max_children = 100
       > pm.start_servers = 10
       > pm.min_spare_servers = 5
       > pm.max_spare_servers = 15

Install MySQL (As DB server)

擇一選型:

MySQL

apt-get install mysql-server

MariaDB

apt-get install mariadb-server

Configuration

    > set datadir = /home/mysql/data
    > set default-time-zone = ‘+8:00’

MySQL change data-dir for 16.04

vim /etc/mysql/mysql.conf.d/mysql.cnf
> set datadir = /home/mysql

vim /etc/apparmor.d/tunables/alias
> alias /var/lib/mysql/ -> /data/newlocation/,
/etc/init.d/apparmor reload

ADDITION INSTALLATION

Install graph handler imagemagic libaray

apt-get install imagemagick

convert for anyone and it’s orginal path is /etc/alternatives/convert


Install Fail2ban

apt-get install fail2ban

或者使用Sshguardapt-get install sshguard (GCP預裝)


ADDITION SETTING

DF Mount

如要使用fstab分別掛載目錄,另如/home獨立掛載硬碟。

mkfs -t ext4 /dev/sdb
mount /dev/sdb /home

注意,如果home目錄下原本資料備份,在掛載後還原時須注意User資料夾權限,例如使用sudo cp -rp,否則重開機只靠SSH無法登入就報銷了。

一般Prod可以掛載/srv即可:Web App Server(網頁伺服器)OS系統建置架構指南


關閉IPv6

例如遇到apt-get來源無法使用IPv6即會卡住。

/etc/sysctl.conf最後加入設定:

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

再生效設定:

sudo sysctl -p

Enable root bash_completion

# In /root/.bashrc: Recomment above lines:
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi

Leave a Reply

Your email address will not be published. Required fields are marked *