LNMP Server Environment Installation
- Version: 1.2.0
- Environment: Ubuntu 18.04 LTS
Nginx Web Server Installation
apt-get install nginx
Configuration:
/etc/nginx/nginx.conf > client_max_body_size 128M; > worker_processes 2; (if instance core is 2)
PHP-FPM
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 8.2 (Using PPA for PHP)
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php8.2 php8.2-fpm
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
MySQL Installation (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 Ubuntu 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
或者使用Sshguard:
apt-get install sshguard
(GCP預裝)
ADDITION SETTING
Set Time Zone for the server
$ dpkg-reconfigure tzdata
or
$ sudo timedatectl set-timezone Asia/Taipei
Add sudo user
adduser nick
# Option 1: Add visudo
$ visudo
> nick_tsai ALL=(ALL) NOPASSWD:ALL
# Option 2: Add to sudo group in
$ vim /etc/group
> sudo:x:26:nick_tsai
# Change deault editor if needed
update-alternatives --config editor
# SSH password login: vi /etc/ssh/sshd_config
> PasswordAuthentication yes
service ssh restart
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