[Up]常用資訊

[重點文章] 重點文章 [重點文章] 重點文章

2020年6月28日 星期日

[FreeBSD] 如何安裝 Nginx, MariaDB and PHP (FEMP stack) on FreeBSD 12.1

[FreeBSD] 如何安裝 Nginx, MariaDB and PHP (FEMP stack) on FreeBSD 12.1

 
#Step 01 – 簡介和 安裝 MariaDB Database



作業系統 : FreeBSD
網站系統 : Nginx
資料庫系統 : MariaDB
網站語言 : PHP

ls -al /usr/ports/databases/ | grep mariadb

pkg search mariadb

顯示如下

mariadb-connector-c-3.1.9      MariaDB database connector for C
mariadb-connector-odbc-3.1.7_1 MariaDB database connector for odbc
mariadb101-client-10.1.45      Multithreaded SQL database (client)
mariadb101-server-10.1.45      Multithreaded SQL database (server)
mariadb102-client-10.2.32      Multithreaded SQL database (client)
mariadb102-server-10.2.32      Multithreaded SQL database (server)
mariadb103-client-10.3.23      Multithreaded SQL database (client)
mariadb103-server-10.3.23      Multithreaded SQL database (server)
mariadb104-client-10.4.13_2    Multithreaded SQL database (client)
mariadb104-server-10.4.13_2    Multithreaded SQL database (server)
rubygem-azure_mgmt_mariadb-0.17.3 Microsoft Azure Microsoft Azure MariaDB Library for Ruby Client Library for Ruby


使用最後版本安裝

[ root@FreeBSD12-1-Default-01 ] 16:46 [~] # pkg install mariadb104-server mariadb104-client

設定資料庫啟動 與 執行

[ root@FreeBSD12-1-Default-01 ] 16:46 [~] # sysrc mysql_enable="YES"
[ root@FreeBSD12-1-Default-01 ] 16:46 [~] # service mysql-server start

設定資料庫安全

[ root@FreeBSD12-1-Default-01 ] 16:46 [~] # /usr/local/bin/mysql_secure_installation

測試登入

mysql -u root -p

sockstat -4 -6

sysrc mysql_args="--bind-address=127.0.0.1"

service mysql-server restart
sockstat -4 -6|grep mysql


 
#Step 02 – 安裝 Nginx Web Server


確認版本
ls /usr/ports/www/ | grep nginx

pkg search -o nginx

安裝
pkg install nginx

設定啟動與執行

sysrc nginx_enable="yes"
service nginx start

確認服務是否正常

sockstat -4 -6 | grep nginx


編輯設定檔

vi /usr/local/etc/nginx/nginx.conf

確認目錄檔案

root /usr/local/www/new_html_directory;



 
#Step 03 – 安裝 PHP


ls /usr/ports/lang/ | grep php
pkg search -o php

安裝 PHP 主程式
pkg install php73

安裝 延伸套件
pkg install mod_php73 php73-mbstring php73-curl php73-zlib php73-gd php73-json

安裝 資料庫連接
pkg install php73-mysqli

cp /usr/local/etc/php-fpm.d/www.conf{,.backup}


sysrc php_fpm_enable="yes"
service php-fpm start

sockstat -4 -6| grep php-fpm

讓 nginx 可以執行 php
vi /usr/local/etc/nginx/nginx.conf

===================================================================================
	location ~ .php$ {
	root           	/usr/local/www/nginx;
	fastcgi_pass   127.0.0.1:9000;
	fastcgi_index  index.php;
	fastcgi_param SCRIPT_FILENAME $request_filename;	
	include        fastcgi_params;
    	}

===================================================================================

設定 php.ini檔案
ln -s /usr/local/etc/php.ini-production /usr/local/etc/php.ini


service php-fpm restart

確認設定檔

nginx -t
重啟 nginx
service nginx restart

確認 php 是否正常
echo "" | tee /usr/local/www/nginx/phpinfo.php


 
#Step 04 –


 
#Step 05 –


 
#Step 06 –


 
#Step 07 –


check connection with pool
show ltm pool | grep -e Ltm::Pool -e "Current Connections"

check connection with node
show ltm node | grep -e Ltm::Node -e "Current Connections"

Check irules of Virtual Servers with TMSH
list ltm virtual | grep -E -A 1 "virtual|rules"

 
#Step 08 –


設定 ssh 登入
vi /etc/ssh/sshd_config
===========================
PermitRootLogin yes  ## 開啟root用戶遠端登入
PasswordAuthentication yes ## 開啟ssh密碼登錄
UseDNS no
GSSAPIAuthentication no ## 提升ssh登錄速度
重新載入 sshd
/etc/rc.d/sshd restart

修改 /etc/pkg/FreeBSD.conf

將 quarterly --> latest

安裝更新

# freebsd-update fetch
# freebsd-update install


安裝與配置sudo
pkg install -y sudo

echo '%wheel ALL=(ALL) ALL' >/usr/local/etc/sudoers.d/allow-wheel-user-login

vim /usr/local/etc/sudoer

oscarwu          ALL=(ALL) ALL
%wheel ALL=(ALL) ALL

安裝相關軟體

pkg install vim
pkg install -y htop
pkg install -y bind-tools
pkg install unzip
####################################################################

vi /etc/rc.conf


#設定固定IP
#ifconfig_em0="inet 192.168.13.4 netmask 255.255.255.0"
#defaultrouter="192.168.13.1"
#

安裝更新

# freebsd-update fetch
# freebsd-update install

# pkg install -y python37
# ln -s /usr/local/bin/python3.7 /usr/local/bin/python
# pkg install -y vim
# pkg install -y vim-console
# pkg install -y htop
# pkg install -y bind-tools
# pkg install -y unzip
# pkg install -y rsync
# pkg install -y bash
# pkg install -y most
# pkg install -y bash-completion
# pkg install -y vnstat
# pkg install -y wget
# pkg install -y curl
# pkg install -y git
# pkg install -y node-14.4.0
# pkg install -y yarn
# pkg install -y neovim
# pkg install -y py37-pip
# pip --version 

# pkg install py37-pip

# ln -s /usr/local/bin/pip-3.7 /usr/local/bin/pip
# pip --version 

curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
	
" curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
" https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
Reload .vimrc and 
:PlugInstall
to install plugins.

#### 如果需要才設定 ####################
首先建立~/.vim/colors這個資料夾(如果不存在慢慢建立)
mkdir ~/.vim
mkdir ~/.vim/colors
建立後切換目錄到~/.vim/colors
cd ~/.vim/colors
使用以下指令下載vim顏色設定檔
curl -O https://raw.githubusercontent.com/zeis/vim-kolor/master/colors/kolor.vim
首先建立~/.vim/colors這個資料夾(如果不存在慢慢建立)

#############################

# FreeBSD 對 VMwareTools 安裝:

# pkg install open-vm-tools-nox11

# vim /etc/rc.conf

加入以下文字:

vmware_guest_vmblock_enable="YES"
vmware_guest_vmhgfs_enable="YES"
vmware_guest_vmmemctl_enable="YES"
vmware_guest_vmxnet_enable="YES"
vmware_guestd_enable="YES"

重新開機:

# reboot

timeticks / 100 = seconds

timeticks / 6000 = minutes

timeticks / 360000 = hours

timeticks / 8640000 = days


qle really meant to say divide by 6000 to convert to minutes.

timeticks / 100 = seconds

timeticks / 6000 = minutes

timeticks / 360000 = hours

timeticks / 8640000 = days

 
#Step 09 –

[ root@FreeBSD12-1-Default-01 ] 1:21 [~] # cat .cshrc
alias h         history 1000
alias j         jobs -l
alias la        ls -A
alias lf        ls -FA
alias ll        ls -lA
alias lh        ll -h
alias ls        ls -FGI
alias .         ls
alias ..        cd ../
alias man       env LC_ALL=C man
alias s         screen
alias r         screen -r

set     autolist

setenv  LSCOLORS "ExFxcxdxbxegedabagacad"

setenv  TERMCAP 'xterm|xterm-color:Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm:tc=xterm-xfree86:'

setenv  LANG zh_TW.UTF-8
setenv  LC_CTYPE zh_TW.UTF-8
setenv  LC_COLLATE zh_TW.UTF-8
setenv  LC_TIME zh_TW.UTF-8
setenv  LC_NUMERIC zh_TW.UTF-8
setenv  LC_MONETARY zh_TW.UTF-8
setenv  LC_MESSAGES zh_TW.UTF-8
setenv  LC_ALL zh_TW.UTF-8

umask   22

set path = (/sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin /usr/local/bin /usr/X11R6/bin $HOME/bin)

if (-x /usr/local/bin/vim) then
        setenv  EDITOR  vim
        alias vi        vim
else
        setenv  EDITOR  vi
endif
setenv  PAGER   less
setenv  BLOCKSIZE       K

if ($?prompt) then
        if ($USER == root) then
                set prompt = "[ %U%{^[[36;1m%}%n%{^[[m%}%B@%{^[[33m%}%m%{^[[m%} ] %{^[[35;1m%}%T%{^[[m%} [%{^[[32;1m%}%~%{^[[m%}] %# "
                        #set prompt = "%Broot@%m[%~]%w%D %T%#"
        else
            set prompt = "%B[%{\033[36m%}%n%{\033[37m%}@%m %~]%# "
        endif
        set filec
        set history = 5000
        set savehist = 5000
        set mail = (/var/mail/$USER)
        if ( $?tcsh ) then
                bindkey "^W" backward-delete-word
                bindkey -k up history-search-backward
                bindkey -k down history-search-forward
        endif
endif


 
#Step 10 –

20200620 backup

set nocompatible
" Use Vim settings, rather than Vi settings
set softtabstop=2
" Indent by 2 spaces when hitting tab
set shiftwidth=4
" Indent by 4 spaces when auto-indenting
set tabstop=4
" Show existing tab with 4 spaces width
execute pathogen#infect()
syntax on
highlight Comment ctermfg=darkcyan
highlight Search term=reverse ctermbg=4 ctermfg=7
" Enable syntax highlighting
filetype indent plugin on
" Enable indenting for files
set autoindent
" Enable auto indenting
set number
" Enable line numbers
" colorscheme desert
" Set nice looking colorscheme
set nobackup
" Disable backup files
set laststatus=2
set cursorline
set cursorcolumn
hi CursorLine cterm=none ctermbg=DarkMagenta ctermfg=White
hi CursorColumn cterm=none ctermbg=DarkMagenta ctermfg=White
set ruler
set ignorecase
set smartcase
set hlsearch
hi Search cterm=reverse ctermbg=none ctermfg=none
set incsearch
"show status line
"set statusline=%F%m%r%h%w%=(%{&ff}/%Y)\ (line\ %l\/%L,\ col\ %c)
"set statusline=
"set statusline+=%1*\[%n]                                  "buffernr
"set statusline+=%2*\ %<%F\                                "File+path
"set statusline+=%3*\ %=\ %{''.(&fenc!=''?&fenc:&enc).''}\ "Encoding
"set statusline+=%4*\ %{(&bomb?\",BOM\":\"\")}\            "Encoding2
"set statusline+=%5*\ %{&ff}\                              "FileFormat (dos/unix..)
"set statusline+=%6*\ row:%l/%L\ col:%03c\ (%03p%%)\             "Rownumber/total (%)
"set statusline+=%0*\ \ %m%r%w\ %P\ \                      "Modified? Readonly? Top/bot.
"hi User2 ctermfg=3  ctermbg=0
"hi User6 ctermfg=3  ctermbg=4
"set laststatus=2
" ==================
set statusline=%y\ %t\%r%h%w\ %m%=\ %{&fileencoding}\ [%{&ff}]\ [AscII=\%03.3b]\ [Hex=\%02.2B]\ [LINE=%L]\ [Pos=%l,%v,%p%%]
"set laststatus=2
"set statusline=%4*%<\ %1*[%F]
"set statusline+=%4*\ %5*[%{&encoding}, " encoding
"set statusline+=%{&fileformat}%{\"\".((exists(\"+bomb\")\ &&\ &bomb)?\",BOM\":\"\").\"\"}]%m
"set statusline+=%4*%=\ %6*%y%4*\ %3*%l%4*,\ %3*%c%4*\ \<\ %2*%P%4*\ \>
"highlight User1 ctermfg=red
"highlight User1 term=underline cterm=underline ctermfg=red
"highlight User2 term=underline cterm=underline ctermfg=green
"highlight User3 term=underline cterm=underline ctermfg=yellow
"highlight User4 term=underline cterm=underline ctermfg=white
"highlight User5 ctermfg=cyan
"highlight User6 ctermfg=white
"=========================
set wildmenu
" Display command line's tab complete options as a menu.
call plug#begin('~/.vim/plugged')
Plug 'pearofducks/ansible-vim'
" install and use neomake linting
Plug 'neomake/neomake'
" install jedi auto for python
Plug 'davidhalter/jedi-vim'
" Install  PEP8 support
Plug 'Vimjas/vim-python-pep8-indent'
"
Plug 'preservim/nerdtree'
Plug 'vim-airline/vim-airline'
"
" Colorscheme
Plug 'morhetz/gruvbox'
Plug 'lifepillar/vim-mucomplete'
Plug 'Rip-Rip/clang_complete'
call plug#end()
colorscheme desert
" Get help
nnoremap  H :execute "!pydoc3 " . expand("")
" Run code
autocmd FileType python nnoremap   :exec '!clear; python3' shellescape(@%, 1)
" Edit vimr configuration file
nnoremap ve :e $MYVIMRC
" " Reload vimr configuration file
nnoremap vw :source $MYVIMRC
map  :NERDTree
"#vim Vundle Start
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'

" add all your plugins here (note older versions of Vundle
" used Bundle instead of Plugin)
Plugin 'vim-scripts/indentpython.vim'
Plugin 'jnurmine/Zenburn'
Plugin 'altercation/vim-colors-solarized'
" ...

" All of your Plugins must be added before the following line
call vundle#end()            " required
"#vim Vundle end


沒有留言:

張貼留言