hostvn 117 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594
  1. #!/bin/bash
  2. ######################################################################
  3. # Auto Install & Optimize LEMP Stack on CentOS 7, 8 #
  4. # #
  5. # Author: Sanvv - HOSTVN Technical #
  6. # Website: https://hostvn.vn #
  7. # #
  8. # Please do not remove copyright. Thank! #
  9. # Please do not copy under any circumstance for commercial reason! #
  10. ######################################################################
  11. # shellcheck disable=SC2207
  12. # Set Color
  13. RED='\033[0;31m'
  14. NC='\033[0m'
  15. SCRIPTS_VERSION="1.0.5.5"
  16. # Set variables
  17. OS_VER=$(rpm -E %centos)
  18. OS_ARCH=$(uname -m)
  19. IPADDRESS=$(curl -s http://myip.directadmin.com)
  20. DIR=$(pwd)
  21. BASH_DIR="/var/hostvn"
  22. PHP_MODULES_DIR="/usr/lib64/php/modules"
  23. GITHUB_RAW_LINK="https://raw.githubusercontent.com"
  24. EXT_LINK="https://scripts.hostvn.net"
  25. UPDATE_LINK="https://scripts.hostvn.net/update"
  26. GITHUB_URL="https://github.com"
  27. PECL_PHP_LINK="https://pecl.php.net/get"
  28. PMA_LINK="https://files.phpmyadmin.net/phpMyAdmin"
  29. FILE_INFO="${BASH_DIR}/hostvn.conf"
  30. HOSTNAME=$(hostname)
  31. PHP2_RELEASE="no"
  32. ADMIN_TOOL_PWD=$(< /dev/urandom tr -dc A-Za-z0-9 | head -c8)
  33. # Copyright
  34. AUTHOR="HOSTVN.VN"
  35. AUTHOR_CONTACT="https://www.facebook.com/groups/hostvn.vn"
  36. # Service Version
  37. PHPMYADMIN_VERSION=$(curl -s ${UPDATE_LINK}/version | grep "phpmyadmin_version=" | cut -f2 -d'=')
  38. PHP_SYS_INFO_VERSION=$(curl -s ${UPDATE_LINK}/version | grep "phpsysinfo_version=" | cut -f2 -d'=')
  39. IGBINARY_VERSION=$(curl -s ${UPDATE_LINK}/version | grep "igbinary_version=" | cut -f2 -d'=')
  40. PHP_MEMCACHED_VERSION=$(curl -s ${UPDATE_LINK}/version | grep "php_memcached_version=" | cut -f2 -d'=')
  41. PHP_REDIS_VERSION=$(curl -s ${UPDATE_LINK}/version | grep "php_redis_version=" | cut -f2 -d'=')
  42. MARIADB_VERSION=$(curl -s ${UPDATE_LINK}/version | grep "mariadb_version=" | cut -f2 -d'=')
  43. #PHP_VERSION_1=$(curl -s ${UPDATE_LINK}/version | grep "php_version=" | cut -f2 -d'=')
  44. #PHP_VERSION_2=$(curl -s ${UPDATE_LINK}/version | grep "php2_version=" | cut -f2 -d'=')
  45. PHP_LIST=( $(curl -s "${UPDATE_LINK}"/version | grep "php_list=" | cut -f2 -d'=') )
  46. if [[ "${OS_VER}" -eq 8 ]]; then
  47. index=0
  48. for keyword in "${PHP_LIST[@]}"; do
  49. if [[ "$keyword" = "php7.1" || "$keyword" = "php7.0" || "$keyword" = "php5.6" ]]; then
  50. unset "PHP_LIST[$index]"
  51. fi
  52. (( index++ ))
  53. done
  54. fi
  55. # Set Lang
  56. OPTION_CHANGE_SSH="Ban co muon thay doi port SSH khong ? "
  57. OPTION_INST_PUREFTP="Ban co muon cai dat PURE-FTPD (Quan ly FTP) khong ? "
  58. OPTION_INST_AV="Ban co muon cai dat Clamav (Scan Malware) khong ? "
  59. OPTION_INST_MEMCACHED="Ban co muon cai dat Memcached khong ? "
  60. OPTION_INST_REDIS="Ban co muon cai dat Redis khong ? "
  61. ENTER_OPTION="Nhap vao lua chon cua ban: "
  62. SELECT_PHP="Hay lua chon phien ban PHP muon cai dat:"
  63. WRONG_PHP_OPTION="Lua chon cua ban khong chinh xac, vui long chon lai."
  64. SELECT_INST_PHP_2="Ban co muon cai dat phien ban PHP thu hai khong - Multiple PHP ?"
  65. ENTER_OPTION_PHP_2="Nhap vao lua chon cua ban [1-2]: "
  66. WRONG_PHP_SELECT_2="Ban nhap sai. Vui long nhap lai."
  67. INVALID_PHP2_OPTION="${RED}Lua chon cua ban khong chinh xac. Vui long chon lai.${NC}"
  68. SELECT_PHP_2="Lua chon phien ban PHP thu hai ban muon su dung:"
  69. INST_MARIADB_ERR="Cai dat MariaDB that bai, vui long truy cap ${AUTHOR_CONTACT} de duoc ho tro."
  70. INST_NGINX_ERR="Cai dat Nginx that bai, vui long truy cap ${AUTHOR_CONTACT} de duoc ho tro."
  71. INST_PHP_ERR="Cai dat PHP that bai, vui long truy cap ${AUTHOR_CONTACT} de duoc ho tro."
  72. INST_PHP_ERR_2="Cai dat PHP 2 that bai, vui long truy cap ${AUTHOR_CONTACT} de duoc ho tro"
  73. INST_IGBINARY_ERR="Cai dat Igbinary that bai. Vui long cai dat lai: Igbinary, Php memcached ext, Phpredis."
  74. INST_MEMEXT_ERR="Cai dat Php memcached extension khong thanh cong. Vui long cai dat lai."
  75. INST_PHPREDIS_ERR="Cai dat Phpredis khong thanh cong. Vui long cai dat lai."
  76. INST_IGBINARY_ERR_2="Cai dat Igbinary cho PHP 2 khong thanh cong. Vui long cai dat lai: Igbinary, Php memcached ext, Phpredis."
  77. INST_MEMEXT_ERR_2="Cai dat Php memcached extension cho PHP 2 khong thanh cong. Vui long cai dat lai."
  78. INST_PHPREDIS_ERR_2="Cai dat Phpredis cho PHP 2 khong thanh cong. Vui long cai dat lai."
  79. NGINX_NOT_WORKING="Nginx khong hoat dong."
  80. MARIADB_NOT_WORKING="MariaDB khong hoat dong."
  81. PUREFTP_NOT_WORKING="Pure-ftp khong hoat dong."
  82. PHP_NOT_WORKING="PHP-FPM khong hoat dong."
  83. LFD_NOT_WORKING="CSF khong hoat dong."
  84. LFD_NOT_WORKING="LFD khong hoat dong."
  85. LOGIN_NOTI1="Cam on ban da su dung dich vu cua ${AUTHOR}."
  86. LOGIN_NOTI2="Neu can ho tro vui long truy cap ${AUTHOR_CONTACT}"
  87. LOGIN_NOTI3="De mo menu ban go lenh sau: hostvn"
  88. # Random Port
  89. RANDOM_ADMIN_PORT=$(shuf -i 49152-57343 -n 1)
  90. CSF_UI_PORT=$(shuf -i 57344-65000 -n 1)
  91. # Dir
  92. DEFAULT_DIR_WEB="/usr/share/nginx/html"
  93. DEFAULT_DIR_TOOL="/usr/share/nginx/private"
  94. USR_DIR="/usr/share"
  95. # Get info VPS
  96. CPU_CORES=$(grep -c "processor" /proc/cpuinfo)
  97. RAM_TOTAL=$(awk '/MemTotal/ {print $2}' /proc/meminfo)
  98. SWAP_TOTAL=$(awk '/SwapFree/ {print $2}' /proc/meminfo)
  99. PHP_MEM=${RAM_TOTAL}+${SWAP_TOTAL}
  100. NGINX_PROCESSES=$(grep -c ^processor /proc/cpuinfo)
  101. MAX_CLIENT=$((NGINX_PROCESSES * 1024))
  102. rm -rf "${DIR}"/hostvn
  103. rm -rf "${DIR}"/install
  104. ############################################
  105. # Function
  106. ############################################
  107. cd_dir(){
  108. cd "$1" || return
  109. }
  110. generate_random_pwd(){
  111. < /dev/urandom tr -dc A-Za-z0-9 | head -c16
  112. }
  113. valid_ip() {
  114. # shellcheck disable=SC2166
  115. if [ -n "$1" -a -z "${*##*\.*}" ]; then
  116. ipcalc "$1" | \
  117. awk 'BEGIN{FS=":";is_invalid=0} /^INVALID/ {is_invalid=1; print $1} END{exit is_invalid}'
  118. else
  119. return 1
  120. fi
  121. }
  122. ############################################
  123. # Prepare install
  124. ############################################
  125. create_bash_dir(){
  126. mkdir -p /home/backup
  127. chmod 710 /home/backup
  128. chmod 711 /home
  129. mkdir -p "${BASH_DIR}"
  130. }
  131. # Config Selinux
  132. config_selinux(){
  133. if [[ "${OS_VER}" -eq 8 ]]; then
  134. dnf -y install policycoreutils-python-utils
  135. fi
  136. se_status=$(getenforce)
  137. # if [ "${se_status}" == "Disabled" ]; then
  138. # setenforce 0
  139. # sed -i 's/SELINUX=disabled/SELINUX=permissive/g' /etc/selinux/config
  140. # fi
  141. # if [ "${se_status}" == "Enforcing" ]; then
  142. # setenforce 0
  143. # sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config
  144. # fi
  145. if [ "${se_status}" == "Permissive" ]; then
  146. setenforce 0
  147. sed -i 's/SELINUX=permissive/SELINUX=disabled/g' /etc/selinux/config
  148. fi
  149. if [ "${se_status}" == "Enforcing" ]; then
  150. setenforce 0
  151. sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
  152. fi
  153. }
  154. #Set timezone
  155. set_timezone(){
  156. if [[ -f "/etc/localtime" && -f "/usr/share/zoneinfo/Asia/Ho_Chi_Minh" ]]; then
  157. rm -f /etc/localtime
  158. ln -sf /usr/share/zoneinfo/Asia/Ho_Chi_Minh /etc/localtime
  159. else
  160. timedatectl set-timezone Asia/Ho_Chi_Minh
  161. fi
  162. }
  163. #Set OS Archive
  164. set_os_arch(){
  165. if [[ "${OS_ARCH}" == "x86_64" ]]; then
  166. OS_ARCH1="amd64"
  167. elif [[ "${OS_ARCH}" == "i686" ]]; then
  168. OS_ARCH1="x86"
  169. fi
  170. }
  171. # Admin Email
  172. set_email(){
  173. clear
  174. while true
  175. do
  176. read -r -p "Nhap vao email cua ban: " ADMIN_EMAIL
  177. echo
  178. if [[ "${ADMIN_EMAIL}" =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$ ]];
  179. then
  180. echo "Email cua ban la: ${ADMIN_EMAIL}."
  181. break
  182. else
  183. echo "Email ban nhap khong chinh xac vui long nhap lai."
  184. fi
  185. done
  186. }
  187. # Create log file
  188. create_log(){
  189. LOG="/var/log/install.log"
  190. touch "${LOG}"
  191. }
  192. ssh_login_noti(){
  193. string=$(grep -rnw "/root/.bash_profile" -e "${AUTHOR}")
  194. if [ -z "${string}" ]; then
  195. {
  196. echo "echo \"${LOGIN_NOTI1}\""
  197. echo "echo \"${LOGIN_NOTI2}\""
  198. echo "echo \"${LOGIN_NOTI3}\""
  199. } >> ~/.bash_profile
  200. fi
  201. }
  202. ############################################
  203. # Option Install
  204. ############################################
  205. input_ip(){
  206. echo "Nhap vao dia chi IP cua VPS. Bam Enter de script tu detect IP Public."
  207. read -r -p "Nhap vao dia chi IP cua VPS: " IPADDRESS_NEW
  208. if [ -n "${IPADDRESS_NEW}" ] && valid_ip "${IPADDRESS_NEW}" ; then
  209. IPADDRESS=${IPADDRESS_NEW}
  210. else
  211. printf "IP ban nhap khong chinh xac. Script se tu dong detect IP Public cua VPS."
  212. fi
  213. }
  214. select_php_ver(){
  215. clear
  216. while true
  217. do
  218. printf "%s\n" "${SELECT_PHP}"
  219. PS3="${ENTER_OPTION}"
  220. select opt in "${PHP_LIST[@]}"
  221. do
  222. case $opt in
  223. "$opt") PHP_VERSION="${opt/.}"; break;;
  224. esac
  225. done
  226. echo
  227. if [[ " ${PHP_LIST[*]} " == *" $(echo "${PHP_VERSION}" | fold -w4 | paste -sd'.') "* ]]; then
  228. break
  229. else
  230. clear
  231. printf "${RED}%s${NC}\n" "${WRONG_PHP_OPTION}"
  232. fi
  233. done
  234. sleep 1
  235. }
  236. select_php_multi(){
  237. clear
  238. printf "%s\n" "${SELECT_INST_PHP_2}"
  239. PS3="${ENTER_OPTION_PHP_2}"
  240. options=("Yes" "No")
  241. select opt in "${options[@]}"
  242. do
  243. case $opt in
  244. "Yes") MULTI_PHP="y"; break;;
  245. "No") MULTI_PHP="n"; break;;
  246. *) printf "${RED}%s${NC}\n" "${WRONG_PHP_SELECT_2} $REPLY";;
  247. esac
  248. done
  249. sleep 1
  250. }
  251. select_php_ver_2(){
  252. clear
  253. while true
  254. do
  255. printf "%s\n" "${SELECT_PHP_2}"
  256. PS3="${ENTER_OPTION}"
  257. select opt in "${PHP_LIST[@]}"
  258. do
  259. case $opt in
  260. "$opt") PHP_VERSION_2="${opt/.}"; break;;
  261. esac
  262. done
  263. echo
  264. if [[ " ${PHP_LIST[*]} " == *" $(echo "${PHP_VERSION_2}" | fold -w4 | paste -sd'.') "* ]]; then
  265. break
  266. else
  267. clear
  268. printf "${RED}%s\n${NC}" "${INVALID_PHP2_OPTION}"
  269. fi
  270. done
  271. sleep 1
  272. }
  273. option_clamav(){
  274. if [[ ${RAM_TOTAL} -gt 1049576 ]]; then
  275. clear
  276. printf "%s\n" "${OPTION_INST_AV}"
  277. PS3="${ENTER_OPTION}"
  278. options=("Yes" "No")
  279. select opt in "${options[@]}"
  280. do
  281. case $opt in
  282. "Yes") prompt_inst_av="y"; break;;
  283. "No") prompt_inst_av="n"; break;;
  284. *) printf "${RED}%s${NC}\n" "${WRONG_PHP_SELECT_2} $REPLY";;
  285. esac
  286. done
  287. sleep 1
  288. fi
  289. }
  290. option_memcached(){
  291. clear
  292. printf "%s\n" "${OPTION_INST_MEMCACHED}"
  293. PS3="${ENTER_OPTION}"
  294. options=("Yes" "No")
  295. select opt in "${options[@]}"
  296. do
  297. case $opt in
  298. "Yes") prompt_memcached="y"; break;;
  299. "No") prompt_memcached="n"; break;;
  300. *) printf "${RED}%s${NC}\n" "${WRONG_PHP_SELECT_2} $REPLY";;
  301. esac
  302. done
  303. sleep 1
  304. }
  305. option_redis(){
  306. clear
  307. printf "%s\n" "${OPTION_INST_REDIS}"
  308. PS3="${ENTER_OPTION}"
  309. options=("Yes" "No")
  310. select opt in "${options[@]}"
  311. do
  312. case $opt in
  313. "Yes") prompt_redis="y"; break;;
  314. "No") prompt_redis="n"; break;;
  315. *) printf "${RED}%s${NC}\n" "${WRONG_PHP_SELECT_2} $REPLY";;
  316. esac
  317. done
  318. sleep 1
  319. }
  320. option_pureftp(){
  321. clear
  322. printf "%s\n" "${OPTION_INST_PUREFTP}"
  323. PS3="${ENTER_OPTION}"
  324. options=("Yes" "No")
  325. select opt in "${options[@]}"
  326. do
  327. case $opt in
  328. "Yes") prompt_pureftpd="y"; break;;
  329. "No") prompt_pureftpd="n"; break;;
  330. *) printf "${RED}%s${NC}\n" "${WRONG_PHP_SELECT_2} $REPLY";;
  331. esac
  332. done
  333. sleep 1
  334. }
  335. option_change_ssh_port(){
  336. clear
  337. printf "%s\n" "${OPTION_CHANGE_SSH}"
  338. PS3="${ENTER_OPTION}"
  339. options=("Yes" "No")
  340. select opt in "${options[@]}"
  341. do
  342. case $opt in
  343. "Yes")
  344. prompt_ssh="y";
  345. SSH_PORT="8282";
  346. sleep 1
  347. printf "${RED}%s${NC}\n" "Port SSH moi là: 8282";
  348. printf "${RED}%s${NC}\n" "Luu y: Voi Google Cloud cac ban can mo port 8282 trong tab VPC network";
  349. sleep 1
  350. break;;
  351. "No") prompt_ssh="n"; SSH_PORT="22" ; break;;
  352. *) printf "${RED}%s${NC}\n" "${WRONG_PHP_SELECT_2} $REPLY";;
  353. esac
  354. done
  355. sleep 1
  356. }
  357. ############################################
  358. # Install LEMP Stack
  359. ############################################
  360. # Install Nginx
  361. install_nginx(){
  362. if [[ -d /etc/nginx ]]; then
  363. rm -rf /etc/nginx
  364. fi
  365. cat >> "/etc/yum.repos.d/nginx.repo" << EONGINXREPO
  366. [nginx-stable]
  367. name=nginx stable repo
  368. baseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/
  369. gpgcheck=1
  370. enabled=1
  371. gpgkey=https://nginx.org/keys/nginx_signing.key
  372. module_hotfixes=true
  373. EONGINXREPO
  374. yum -y install yum-utils
  375. yum -y install nginx
  376. mkdir -p "${DEFAULT_DIR_TOOL}"
  377. chown -R nginx:nginx "${DEFAULT_DIR_TOOL}"
  378. semanage permissive -a httpd_t
  379. systemctl start nginx
  380. }
  381. nginx_brotli(){
  382. NGINXV=$(nginx -v 2>&1 | grep -o '[0-9.]*$'; echo)
  383. MODULES_PATH="/etc/nginx/modules"
  384. wget -q "${EXT_LINK}"/ngx_brotli/"${NGINXV}"/ngx_http_brotli_filter_module.so -O "${MODULES_PATH}"/ngx_http_brotli_filter_module.so
  385. wget -q "${EXT_LINK}"/ngx_brotli/"${NGINXV}"/ngx_http_brotli_static_module.so -O "${MODULES_PATH}"/ngx_http_brotli_static_module.so
  386. if [[ -f "${MODULES_PATH}/ngx_http_brotli_filter_module.so" && -f "${MODULES_PATH}/ngx_http_brotli_static_module.so" ]]; then
  387. LOAD_BROTLI_FILTER="load_module modules/ngx_http_brotli_filter_module.so;"
  388. LOAD_BROTLI_STATIC="load_module modules/ngx_http_brotli_static_module.so;"
  389. INCLUDE_BROTLI="include /etc/nginx/extra/brotli.conf;"
  390. BROTLI_STATIC_OFF="brotli_static off;"
  391. fi
  392. }
  393. # Config naxsi
  394. nginx_naxsi(){
  395. mkdir -p /etc/nginx/naxsi
  396. wget -q "${EXT_LINK}"/naxsi/"${NGINXV}"/ngx_http_naxsi_module.so -O "${MODULES_PATH}"/ngx_http_naxsi_module.so
  397. wget -q "${EXT_LINK}"/naxsi/rule/naxsi_core.rules -O /etc/nginx/naxsi/naxsi_core.rules
  398. wget -q "${EXT_LINK}"/naxsi/rule/wordpress.rules -O /etc/nginx/naxsi/wordpress.rules
  399. wget -q "${EXT_LINK}"/naxsi/rule/drupal.rules -O /etc/nginx/naxsi/drupal.rules
  400. wget -q "${EXT_LINK}"/naxsi/rule/naxsi_relax.rules -O /etc/nginx/naxsi/naxsi_relax.rules
  401. if [[ -f "${MODULES_PATH}/ngx_http_naxsi_module.so" ]]; then
  402. LOAD_NAXSI="load_module modules/ngx_http_naxsi_module.so;"
  403. fi
  404. }
  405. create_naxsi_config(){
  406. cat >> "/etc/nginx/naxsi/disable_admin.conf" <<EOnaxsi_config
  407. location /RequestDenied { internal; return 404; }
  408. location /wp-admin {
  409. try_files \$uri \$uri/ /index.php?\$args;
  410. SecRulesDisabled;
  411. }
  412. location /admin {
  413. try_files \$uri \$uri/ /index.php?\$args;
  414. SecRulesDisabled;
  415. }
  416. location /admincp {
  417. try_files \$uri \$uri/ /index.php?\$args;
  418. SecRulesDisabled;
  419. }
  420. location /administrator {
  421. try_files \$uri \$uri/ /index.php?\$args;
  422. SecRulesDisabled;
  423. }
  424. EOnaxsi_config
  425. cat >> "/etc/nginx/naxsi/enable_naxsi.conf" <<EOenable_naxsi
  426. ## Naxsi rules
  427. #LearningMode;
  428. #SecRulesEnabled;
  429. SecRulesDisabled;
  430. DeniedUrl /RequestDenied;
  431. ## check rules
  432. CheckRule "\$SQL >= 8" BLOCK;
  433. CheckRule "\$RFI >= 8" BLOCK;
  434. CheckRule "\$TRAVERSAL >= 4" BLOCK;
  435. CheckRule "\$EVADE >= 4" BLOCK;
  436. CheckRule "\$XSS >= 8" BLOCK;
  437. # nginx-naxsi relaxation rules
  438. include /etc/nginx/naxsi_config/naxsi_relax.rules;
  439. include /etc/nginx/naxsi_config/wordpress.rules;
  440. include /etc/nginx/naxsi_config/drupal.rules;
  441. EOenable_naxsi
  442. }
  443. install_naxsi(){
  444. nginx_naxsi
  445. create_naxsi_config
  446. }
  447. #Install Mariadb
  448. install_mariadb(){
  449. if [ -f "/etc/yum.repos.d/mariadb.repo" ]; then
  450. rm -rf /etc/yum.repos.d/mariadb.repo
  451. fi
  452. cat >> "/etc/yum.repos.d/mariadb.repo" << EOMARIADBREPO
  453. [mariadb]
  454. name = MariaDB
  455. baseurl = http://yum.mariadb.org/${MARIADB_VERSION}/centos${OS_VER}-${OS_ARCH1}
  456. gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
  457. gpgcheck=1
  458. EOMARIADBREPO
  459. if [[ "${OS_VER}" -eq 8 ]]; then
  460. dnf makecache
  461. dnf -y install galera-4
  462. #dnf install -y MariaDB-server MariaDB-client --disablerepo=AppStream
  463. dnf install -y mariadb-server
  464. else
  465. #yum -y install MariaDB-server MariaDB-client
  466. yum -y install mariadb-server
  467. fi
  468. /bin/systemctl start mariadb.service
  469. }
  470. # Install php-fpm
  471. install_php(){
  472. if [ "${OS_VER}" -eq 8 ]; then
  473. PHP1_VERSION=${PHP_VERSION//php}
  474. PHP1_VERSION=$(echo "${PHP1_VERSION}" | fold -w1 | paste -sd'.')
  475. dnf module reset php -y
  476. dnf makecache
  477. dnf module enable php:remi-"${PHP1_VERSION}" -y
  478. yum install -y dnf-plugins-core
  479. dnf config-manager --set-enabled powertools
  480. else
  481. yum-config-manager --enable remi-"${PHP_VERSION}"
  482. fi
  483. yum -y install php php-fpm php-ldap php-zip php-embedded php-cli php-mysql php-common php-gd php-xml php-mbstring \
  484. php-mcrypt php-pdo php-soap php-json php-simplexml php-process php-curl php-bcmath php-snmp php-pspell php-gmp \
  485. php-intl php-imap php-enchant php-pear php-zlib php-xmlrpc php-devel \
  486. php-tidy php-opcache php-cli php-pecl-zip php-dom php-ssh2 php-xmlreader php-date php-exif php-filter php-ftp \
  487. php-hash php-iconv php-libxml php-pecl-imagick php-openssl php-pcre php-posix php-sockets php-spl \
  488. php-tokenizer php-bz2 php-pgsql php-sqlite3 php-fileinfo
  489. }
  490. install_php_2(){
  491. if [[ "${MULTI_PHP}" =~ ^(Y|y)$ ]]; then
  492. yum -y install "${PHP_VERSION_2}" "${PHP_VERSION_2}"-php-fpm "${PHP_VERSION_2}"-php-ldap "${PHP_VERSION_2}"-php-zip "${PHP_VERSION_2}"-php-embedded "${PHP_VERSION_2}"-php-cli "${PHP_VERSION_2}"-php-mysql "${PHP_VERSION_2}"-php-common "${PHP_VERSION_2}"-php-gd "${PHP_VERSION_2}"-php-xml "${PHP_VERSION_2}"-php-mbstring \
  493. "${PHP_VERSION_2}"-php-mcrypt "${PHP_VERSION_2}"-php-pdo "${PHP_VERSION_2}"-php-soap "${PHP_VERSION_2}"-php-json "${PHP_VERSION_2}"-php-simplexml "${PHP_VERSION_2}"-php-process "${PHP_VERSION_2}"-php-curl "${PHP_VERSION_2}"-php-bcmath "${PHP_VERSION_2}"-php-snmp "${PHP_VERSION_2}"-php-pspell "${PHP_VERSION_2}"-php-gmp \
  494. "${PHP_VERSION_2}"-php-intl "${PHP_VERSION_2}"-php-imap "${PHP_VERSION_2}"-php-enchant "${PHP_VERSION_2}"-php-pear "${PHP_VERSION_2}"-php-zlib "${PHP_VERSION_2}"-php-xmlrpc "${PHP_VERSION_2}"-php-devel \
  495. "${PHP_VERSION_2}"-php-tidy "${PHP_VERSION_2}"-php-opcache "${PHP_VERSION_2}"-php-cli "${PHP_VERSION_2}"-php-pecl-zip "${PHP_VERSION_2}"-php-dom "${PHP_VERSION_2}"-php-ssh2 "${PHP_VERSION_2}"-php-xmlreader "${PHP_VERSION_2}"-php-date "${PHP_VERSION_2}"-php-exif "${PHP_VERSION_2}"-php-filter "${PHP_VERSION_2}"-php-ftp \
  496. "${PHP_VERSION_2}"-php-hash "${PHP_VERSION_2}"-php-iconv "${PHP_VERSION_2}"-php-libxml "${PHP_VERSION_2}"-php-pecl-imagick "${PHP_VERSION_2}"-php-openssl "${PHP_VERSION_2}"-php-pcre "${PHP_VERSION_2}"-php-posix "${PHP_VERSION_2}"-php-sockets "${PHP_VERSION_2}"-php-spl \
  497. "${PHP_VERSION_2}"-php-tokenizer "${PHP_VERSION_2}"-php-bz2 "${PHP_VERSION_2}"-php-pgsql "${PHP_VERSION_2}"-php-sqlite3 "${PHP_VERSION_2}"-php-fileinfo
  498. PHP2_RELEASE="yes"
  499. PHP2_INI_PATH="/etc/opt/remi/${PHP_VERSION_2}/php.d"
  500. PHP_MODULES_DIR_2="/opt/remi/${PHP_VERSION_2}/root/usr/lib64/php/modules"
  501. if [[ ${PHP_VERSION_2} == "php56" ]]; then
  502. PHP2_INI_PATH="/opt/remi/${PHP_VERSION_2}/root/etc/php.d"
  503. fi
  504. fi
  505. }
  506. check_duplicate_php(){
  507. if [[ "${PHP_VERSION_2}" == "${PHP_VERSION}" ]]; then
  508. MULTI_PHP="n"
  509. echo "Phien ban PHP thứ 2 trung voi phien ban mac dinh. He thong se cai dat mot phien ban PHP."
  510. fi
  511. }
  512. ############################################
  513. # Install Composer
  514. ############################################
  515. install_composer(){
  516. curl -sS https://getcomposer.org/installer | php
  517. mv composer.phar /usr/local/bin/composer
  518. }
  519. ############################################
  520. # Install WP-CLI
  521. ############################################
  522. install_wpcli(){
  523. curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
  524. chmod +x wp-cli.phar
  525. mv wp-cli.phar /usr/local/bin/wp
  526. }
  527. ############################################
  528. # Dynamic calculation
  529. ############################################
  530. memory_calculation(){
  531. if [[ "${PHP_MEM}" -le '262144' ]]; then
  532. OPCACHE_MEM='128'
  533. MAX_MEMORY='128'
  534. PHP_REAL_PATH_LIMIT='512k'
  535. PHP_REAL_PATH_TTL='14400'
  536. MAX_INPUT_VARS="6000"
  537. elif [[ "${PHP_MEM}" -gt '262144' && "${PHP_MEM}" -le '393216' ]]; then
  538. OPCACHE_MEM='128'
  539. MAX_MEMORY='128'
  540. PHP_REAL_PATH_LIMIT='640k'
  541. PHP_REAL_PATH_TTL='21600'
  542. MAX_INPUT_VARS="6000"
  543. elif [[ "${PHP_MEM}" -gt '393216' && "${PHP_MEM}" -le '524288' ]]; then
  544. OPCACHE_MEM='128'
  545. MAX_MEMORY='128'
  546. PHP_REAL_PATH_LIMIT='768k'
  547. PHP_REAL_PATH_TTL='21600'
  548. MAX_INPUT_VARS="6000"
  549. elif [[ "${PHP_MEM}" -gt '524288' && "${PHP_MEM}" -le '1049576' ]]; then
  550. OPCACHE_MEM='144'
  551. MAX_MEMORY='160'
  552. PHP_REAL_PATH_LIMIT='768k'
  553. PHP_REAL_PATH_TTL='28800'
  554. MAX_INPUT_VARS="6000"
  555. elif [[ "${PHP_MEM}" -gt '1049576' && "${PHP_MEM}" -le '2097152' ]]; then
  556. OPCACHE_MEM='160'
  557. MAX_MEMORY='320'
  558. PHP_REAL_PATH_LIMIT='1536k'
  559. PHP_REAL_PATH_TTL='28800'
  560. MAX_INPUT_VARS="6000"
  561. elif [[ "${PHP_MEM}" -gt '2097152' && "${PHP_MEM}" -le '3145728' ]]; then
  562. OPCACHE_MEM='192'
  563. MAX_MEMORY='384'
  564. PHP_REAL_PATH_LIMIT='2048k'
  565. PHP_REAL_PATH_TTL='43200'
  566. MAX_INPUT_VARS="6000"
  567. elif [[ "${PHP_MEM}" -gt '3145728' && "${PHP_MEM}" -le '4194304' ]]; then
  568. OPCACHE_MEM='224'
  569. MAX_MEMORY='512'
  570. PHP_REAL_PATH_LIMIT='3072k'
  571. PHP_REAL_PATH_TTL='43200'
  572. MAX_INPUT_VARS="6000"
  573. elif [[ "${PHP_MEM}" -gt '4194304' && "${PHP_MEM}" -le '8180000' ]]; then
  574. OPCACHE_MEM='288'
  575. MAX_MEMORY='640'
  576. PHP_REAL_PATH_LIMIT='4096k'
  577. PHP_REAL_PATH_TTL='43200'
  578. MAX_INPUT_VARS="10000"
  579. elif [[ "${PHP_MEM}" -gt '8180000' && "${PHP_MEM}" -le '16360000' ]]; then
  580. OPCACHE_MEM='320'
  581. MAX_MEMORY='800'
  582. PHP_REAL_PATH_LIMIT='4096k'
  583. PHP_REAL_PATH_TTL='43200'
  584. MAX_INPUT_VARS="10000"
  585. elif [[ "${PHP_MEM}" -gt '16360000' && "${PHP_MEM}" -le '32400000' ]]; then
  586. OPCACHE_MEM='480'
  587. MAX_MEMORY='1024'
  588. PHP_REAL_PATH_LIMIT='4096k'
  589. PHP_REAL_PATH_TTL='43200'
  590. MAX_INPUT_VARS="10000"
  591. elif [[ "${PHP_MEM}" -gt '32400000' && "${PHP_MEM}" -le '64800000' ]]; then
  592. OPCACHE_MEM='600'
  593. MAX_MEMORY='1280'
  594. PHP_REAL_PATH_LIMIT='4096k'
  595. PHP_REAL_PATH_TTL='43200'
  596. MAX_INPUT_VARS="10000"
  597. elif [[ "${PHP_MEM}" -gt '64800000' ]]; then
  598. OPCACHE_MEM='800'
  599. MAX_MEMORY='2048'
  600. PHP_REAL_PATH_LIMIT='8192k'
  601. PHP_REAL_PATH_TTL='86400'
  602. MAX_INPUT_VARS="10000"
  603. fi
  604. }
  605. ############################################
  606. # Install Cache
  607. ############################################
  608. # Install Memcached
  609. install_memcached(){
  610. if [[ "${OS_VER}" -eq 8 ]]; then
  611. dnf -y install memcached
  612. else
  613. yum -y install memcached
  614. fi
  615. if [[ -f "/etc/sysconfig/memcached" ]]; then
  616. mv /etc/sysconfig/memcached /etc/sysconfig/memcached.bak
  617. cat >> "/etc/sysconfig/memcached" << EOMEMCACHED
  618. PORT="11211"
  619. USER="memcached"
  620. MAXCONN="${MAX_CLIENT}"
  621. CACHESIZE="${MAX_MEMORY}mb"
  622. OPTIONS="-l 127.0.0.1 -U 0"
  623. EOMEMCACHED
  624. fi
  625. semanage permissive -a memcached_t
  626. }
  627. # Install Redis
  628. install_redis(){
  629. yum --enablerepo=remi install redis -y
  630. mv /etc/redis.conf /etc/redis.conf.bak
  631. cat >> "/etc/redis.conf" << EOFREDIS
  632. maxmemory ${MAX_MEMORY}mb
  633. maxmemory-policy allkeys-lru
  634. save ""
  635. EOFREDIS
  636. semanage permissive -a redis_t
  637. }
  638. # Install igbinary
  639. install_igbinary(){
  640. if [[ "${PHP_VERSION}" == "php56" ]]; then
  641. IGBINARY_VERSION="2.0.8"
  642. fi
  643. cd "${DIR}" && wget "${PECL_PHP_LINK}"/igbinary-"${IGBINARY_VERSION}".tgz
  644. tar -xvf igbinary-"${IGBINARY_VERSION}".tgz
  645. cd_dir "${DIR}/igbinary-${IGBINARY_VERSION}"
  646. /usr/bin/phpize && ./configure --with-php-config=/usr/bin/php-config
  647. make && make install
  648. cd "${DIR}" && rm -rf igbinary-"${IGBINARY_VERSION}" igbinary-"${IGBINARY_VERSION}".tgz
  649. if [[ -f "${PHP_MODULES_DIR}/igbinary.so" ]]; then
  650. cat >> "/etc/php.d/40-igbinary.ini" << EOF
  651. extension=igbinary.so
  652. EOF
  653. else
  654. echo "${INST_IGBINARY_ERR}" >> ${LOG}
  655. fi
  656. }
  657. install_igbinary_2(){
  658. if [[ "${PHP_VERSION_2}" == "php56" ]]; then
  659. IGBINARY_VERSION="2.0.8"
  660. fi
  661. cd "${DIR}" && wget "${PECL_PHP_LINK}"/igbinary-"${IGBINARY_VERSION}".tgz
  662. tar -xvf igbinary-"${IGBINARY_VERSION}".tgz
  663. cd_dir "${DIR}/igbinary-${IGBINARY_VERSION}"
  664. /opt/remi/"${PHP_VERSION_2}"/root/usr/bin/phpize && ./configure --with-php-config=/opt/remi/"${PHP_VERSION_2}"/root/usr/bin/php-config
  665. make && make install
  666. cd "${DIR}" && rm -rf igbinary-"${IGBINARY_VERSION}" igbinary-"${IGBINARY_VERSION}".tgz
  667. if [[ -f "${PHP_MODULES_DIR_2}/igbinary.so" ]]; then
  668. cat >> "${PHP2_INI_PATH}/40-igbinary.ini" << EOF
  669. extension=igbinary.so
  670. EOF
  671. else
  672. echo "${INST_IGBINARY_ERR_2}" >> ${LOG}
  673. fi
  674. }
  675. # Install Php memcached extension
  676. install_php_memcached(){
  677. if [[ "${PHP_VERSION}" == "php56" ]]; then
  678. PHP_MEMCACHED_VERSION="2.2.0"
  679. fi
  680. cd "${DIR}" && wget "${PECL_PHP_LINK}"/memcached-"${PHP_MEMCACHED_VERSION}".tgz
  681. tar -xvf memcached-"${PHP_MEMCACHED_VERSION}".tgz
  682. cd_dir "${DIR}/memcached-${PHP_MEMCACHED_VERSION}"
  683. /usr/bin/phpize && ./configure --enable-memcached-igbinary --with-php-config=/usr/bin/php-config
  684. make && make install
  685. cd "${DIR}" && rm -rf memcached-"${PHP_MEMCACHED_VERSION}".tgz memcached-"${PHP_MEMCACHED_VERSION}"
  686. if [[ -f "${PHP_MODULES_DIR}/memcached.so" ]]; then
  687. cat >> "/etc/php.d/50-memcached.ini" << EOF
  688. extension=memcached.so
  689. EOF
  690. else
  691. echo "${INST_MEMEXT_ERR}" >> ${LOG}
  692. fi
  693. }
  694. install_php_memcached_2(){
  695. if [[ "${PHP_VERSION_2}" == "php56" ]]; then
  696. PHP_MEMCACHED_VERSION="2.2.0"
  697. fi
  698. cd "${DIR}" && wget "${PECL_PHP_LINK}"/memcached-"${PHP_MEMCACHED_VERSION}".tgz
  699. tar -xvf memcached-"${PHP_MEMCACHED_VERSION}".tgz
  700. cd_dir "${DIR}/memcached-${PHP_MEMCACHED_VERSION}"
  701. /opt/remi/"${PHP_VERSION_2}"/root/usr/bin/phpize && ./configure --enable-memcached-igbinary --with-php-config=/opt/remi/"${PHP_VERSION_2}"/root/usr/bin/php-config
  702. make && make install
  703. cd "${DIR}" && rm -rf memcached-"${PHP_MEMCACHED_VERSION}".tgz memcached-"${PHP_MEMCACHED_VERSION}"
  704. if [[ -f "${PHP_MODULES_DIR_2}/memcached.so" ]]; then
  705. cat >> "${PHP2_INI_PATH}/50-memcached.ini" << EOF
  706. extension=memcached.so
  707. EOF
  708. else
  709. echo "${INST_MEMEXT_ERR_2}" >> ${LOG}
  710. fi
  711. }
  712. # Install Phpredis
  713. install_php_redis(){
  714. if [[ "${PHP_VERSION}" == "php56" ]]; then
  715. PHP_REDIS_VERSION="4.3.0"
  716. fi
  717. cd "${DIR}" && wget "${PECL_PHP_LINK}"/redis-"${PHP_REDIS_VERSION}".tgz
  718. tar -xvf redis-"${PHP_REDIS_VERSION}".tgz
  719. cd_dir "${DIR}/redis-${PHP_REDIS_VERSION}"
  720. /usr/bin/phpize && ./configure --enable-redis-igbinary --with-php-config=/usr/bin/php-config
  721. make && make install
  722. cd "${DIR}" && rm -rf redis-"${PHP_REDIS_VERSION}".tgz redis-"${PHP_REDIS_VERSION}"
  723. if [[ -f "${PHP_MODULES_DIR}/redis.so" ]]; then
  724. cat >> "/etc/php.d/50-redis.ini" << EOF
  725. extension=redis.so
  726. EOF
  727. else
  728. echo "${INST_PHPREDIS_ERR}" >> ${LOG}
  729. fi
  730. }
  731. install_php_redis_2(){
  732. if [[ "${PHP_VERSION_2}" == "php56" ]]; then
  733. PHP_REDIS_VERSION="4.3.0"
  734. fi
  735. cd "${DIR}" && wget "${PECL_PHP_LINK}"/redis-"${PHP_REDIS_VERSION}".tgz
  736. tar -xvf redis-"${PHP_REDIS_VERSION}".tgz
  737. cd_dir "${DIR}/redis-${PHP_REDIS_VERSION}"
  738. /opt/remi/"${PHP_VERSION_2}"/root/usr/bin/phpize && ./configure --enable-redis-igbinary --with-php-config=/opt/remi/"${PHP_VERSION_2}"/root/usr/bin/php-config
  739. make && make install
  740. cd "${DIR}" && rm -rf redis-"${PHP_REDIS_VERSION}".tgz redis-"${PHP_REDIS_VERSION}"
  741. if [[ -f "${PHP_MODULES_DIR_2}/redis.so" ]]; then
  742. cat >> "${PHP2_INI_PATH}/50-redis.ini" << EOF
  743. extension=redis.so
  744. EOF
  745. else
  746. echo "${INST_PHPREDIS_ERR_2}" >> "${LOG}"
  747. fi
  748. }
  749. ############################################
  750. # Config Nginx
  751. ############################################
  752. # dynamic SSL cache size calculation
  753. cal_ssl_cache_size(){
  754. if [[ ${RAM_TOTAL} -gt 500000 && ${RAM_TOTAL} -le 800000 ]]; then
  755. SSL_CACHE_SIZE=20
  756. elif [[ ${RAM_TOTAL} -gt 800000 && ${RAM_TOTAL} -le 1000000 ]]; then
  757. SSL_CACHE_SIZE=40
  758. elif [[ ${RAM_TOTAL} -gt 1000000 && ${RAM_TOTAL} -le 1880000 ]]; then
  759. SSL_CACHE_SIZE=60
  760. elif [[ ${RAM_TOTAL} -gt 1880000 && ${RAM_TOTAL} -le 2890000 ]]; then
  761. SSL_CACHE_SIZE=80
  762. elif [[ ${RAM_TOTAL} -gt 2890000 && ${RAM_TOTAL} -le 3890000 ]]; then
  763. SSL_CACHE_SIZE=150
  764. elif [[ ${RAM_TOTAL} -gt 3890000 && ${RAM_TOTAL} -le 7800000 ]]; then
  765. SSL_CACHE_SIZE=300
  766. elif [[ ${RAM_TOTAL} -gt 7800000 && ${RAM_TOTAL} -le 15600000 ]]; then
  767. SSL_CACHE_SIZE=500
  768. elif [[ ${RAM_TOTAL} -gt 15600000 && ${RAM_TOTAL} -le 23600000 ]]; then
  769. SSL_CACHE_SIZE=1000
  770. elif [[ ${RAM_TOTAL} -gt 23600000 ]]; then
  771. SSL_CACHE_SIZE=2000
  772. else
  773. SSL_CACHE_SIZE=10
  774. fi
  775. }
  776. self_signed_ssl(){
  777. #Create dhparams
  778. challenge_password=$(generate_random_pwd)
  779. self_signed_dir="/etc/nginx/ssl/server"
  780. mkdir -p "${self_signed_dir}"
  781. openssl dhparam -out /etc/nginx/ssl/dhparams.pem 2048
  782. openssl genrsa -out "${self_signed_dir}/server.key" 4096
  783. openssl req -new -days 3650 -key "${self_signed_dir}/server.key" -out "${self_signed_dir}/server.csr" <<EOF
  784. VN
  785. Cau Giay
  786. Ha Noi
  787. ${AUTHOR}
  788. IT
  789. ${IPADDRESS}
  790. ${ADMIN_EMAIL}
  791. ${challenge_password}
  792. ${AUTHOR}
  793. EOF
  794. openssl x509 -in "${self_signed_dir}/server.csr" -out "${self_signed_dir}/server.crt" -req -signkey "${self_signed_dir}/server.key" -days 3650
  795. }
  796. create_nginx_conf(){
  797. mkdir -p /etc/nginx/backup_vhost
  798. mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.orig
  799. cat >> "/etc/nginx/nginx.conf" << EONGINXCONF
  800. user nginx;
  801. worker_processes ${NGINX_PROCESSES};
  802. worker_rlimit_nofile 260000;
  803. error_log /var/log/nginx/error.log warn;
  804. pid /var/run/nginx.pid;
  805. ${LOAD_BROTLI_FILTER}
  806. ${LOAD_BROTLI_STATIC}
  807. ${LOAD_NAXSI}
  808. events {
  809. worker_connections ${MAX_CLIENT};
  810. accept_mutex off;
  811. accept_mutex_delay 200ms;
  812. use epoll;
  813. #multi_accept on;
  814. }
  815. http {
  816. index index.html index.htm index.php;
  817. include /etc/nginx/mime.types;
  818. default_type application/octet-stream;
  819. charset utf-8;
  820. log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" '
  821. '\$status \$body_bytes_sent "\$http_referer" '
  822. '"\$http_user_agent" "\$http_x_forwarded_for"';
  823. access_log off;
  824. server_tokens off;
  825. sendfile on;
  826. tcp_nopush on;
  827. tcp_nodelay off;
  828. types_hash_max_size 2048;
  829. server_names_hash_bucket_size 128;
  830. server_names_hash_max_size 10240;
  831. client_max_body_size 1024m;
  832. client_body_buffer_size 128k;
  833. client_body_in_file_only off;
  834. client_body_timeout 60s;
  835. client_header_buffer_size 256k;
  836. client_header_timeout 20s;
  837. large_client_header_buffers 8 256k;
  838. keepalive_timeout 15;
  839. keepalive_disable msie6;
  840. reset_timedout_connection on;
  841. send_timeout 60s;
  842. disable_symlinks if_not_owner from=\$document_root;
  843. server_name_in_redirect off;
  844. open_file_cache max=2000 inactive=20s;
  845. open_file_cache_valid 120s;
  846. open_file_cache_min_uses 2;
  847. open_file_cache_errors off;
  848. # Limit Request
  849. limit_req_status 403;
  850. limit_conn_zone \$binary_remote_addr zone=one:10m;
  851. limit_req_zone \$binary_remote_addr zone=two:10m rate=1r/s;
  852. # Custom Response Headers
  853. add_header X-Powered-By ${AUTHOR};
  854. add_header X-Content-Type-Options "nosniff" always;
  855. add_header X-XSS-Protection "1; mode=block" always;
  856. add_header Referrer-Policy "no-referrer-when-downgrade" always;
  857. add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
  858. # Custom Variables
  859. map \$scheme \$https_suffix { default ''; https '-https'; }
  860. include /etc/nginx/extra/gzip.conf;
  861. ${INCLUDE_BROTLI}
  862. include /etc/nginx/extra/ssl.conf;
  863. include /etc/nginx/extra/cloudflare.conf;
  864. include /etc/nginx/web_apps.conf;
  865. include /etc/nginx/conf.d/*.conf;
  866. }
  867. EONGINXCONF
  868. }
  869. create_wp_cache_conf(){
  870. mkdir -p /etc/nginx/wordpress
  871. cat >> "/etc/nginx/wordpress/disable_xmlrpc.conf" << EOxmlrpc
  872. # Disable XML-RPC
  873. location = xmlrpc.php { deny all; access_log off; log_not_found off; }
  874. EOxmlrpc
  875. cat >> "/etc/nginx/wordpress/disable_user_api.conf" << EOuser_api
  876. #Block API User
  877. location ~* /wp-json/wp/v2/users {
  878. allow 127.0.0.1;
  879. deny all;
  880. access_log off;
  881. log_not_found off;
  882. }
  883. EOuser_api
  884. cat >> "/etc/nginx/wordpress/wordpress_secure.conf" << EOwpsecure
  885. include /etc/nginx/wordpress/disable_user_api.conf;
  886. rewrite /wp-admin$ \$scheme://\$host\$uri/ permanent;
  887. location /wp-includes/{
  888. location ~ \.(gz|tar|bzip2|7z|php|php5|php7|log|error|py|pl|kid|love|cgi)\$ {
  889. deny all;
  890. }
  891. }
  892. location /wp-content/uploads {
  893. location ~ \.(gz|tar|bzip2|7z|php|php5|php7|log|error|py|pl|kid|love|cgi)\$ {
  894. deny all;
  895. }
  896. }
  897. location /wp-content/updraft {
  898. deny all;
  899. }
  900. location /wp-content/uploads/sucuri {
  901. deny all;
  902. }
  903. location /wp-content/uploads/nginx-helper {
  904. deny all;
  905. }
  906. location = /wp-config.php {
  907. deny all;
  908. }
  909. location = /wp-links-opml.php {
  910. deny all;
  911. }
  912. location = /wp-config-sample.php {
  913. deny all;
  914. }
  915. location = /wp-comments-post.php {
  916. deny all;
  917. }
  918. location = /readme.html {
  919. deny all;
  920. }
  921. location = /license.txt {
  922. deny all;
  923. }
  924. # enable gzip on static assets - php files are forbidden
  925. location /wp-content/cache {
  926. # Cache css & js files
  927. location ~* \.(?:css(\.map)?|js(\.map)?|.html)\$ {
  928. add_header Access-Control-Allow-Origin *;
  929. access_log off;
  930. log_not_found off;
  931. expires 97d;
  932. }
  933. location ~ \.php\$ {
  934. #Prevent Direct Access Of PHP Files From Web Browsers
  935. deny all;
  936. }
  937. }
  938. EOwpsecure
  939. cat >> "/etc/nginx/wordpress/yoast_seo.conf" <<EOyoast_seo
  940. #Yoast SEO Sitemaps
  941. location ~* ^/wp-content/plugins/wordpress-seo(?:-premium)?/css/main-sitemap\.xsl\$ {}
  942. location ~ ([^/]*)sitemap(.*).x(m|s)l\$ {
  943. ## this rewrites sitemap.xml to /sitemap_index.xml
  944. rewrite ^/sitemap.xml\$ /sitemap_index.xml permanent;
  945. ## this makes the XML sitemaps work
  946. rewrite ^/([a-z]+)?-?sitemap.xsl\$ /index.php?yoast-sitemap-xsl=\$1 last;
  947. rewrite ^/sitemap_index.xml\$ /index.php?sitemap=1 last;
  948. rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml\$ /index.php?sitemap=\$1&sitemap_n=\$2 last;
  949. ## The following lines are optional for the premium extensions
  950. ## News SEO
  951. rewrite ^/news-sitemap.xml\$ /index.php?sitemap=wpseo_news last;
  952. ## Local SEO
  953. rewrite ^/locations.kml\$ /index.php?sitemap=wpseo_local_kml last;
  954. rewrite ^/geo-sitemap.xml\$ /index.php?sitemap=wpseo_local last;
  955. ## Video SEO
  956. rewrite ^/video-sitemap.xsl\$ /index.php?yoast-sitemap-xsl=video last;
  957. }
  958. EOyoast_seo
  959. cat >> "/etc/nginx/wordpress/rank_math_seo.conf" <<EOrank_math_seo
  960. # RANK MATH SEO plugin
  961. rewrite ^/sitemap_index.xml\$ /index.php?sitemap=1 last;
  962. rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml\$ /index.php?sitemap=\$1&sitemap_n=\$2 last;
  963. EOrank_math_seo
  964. cat >> "/etc/nginx/wordpress/w3c.conf" << EOw3c
  965. location ~ /wp-content/cache/minify/.*js_gzip\$ {
  966. gzip off;
  967. types {}
  968. default_type application/x-javascript;
  969. add_header Content-Encoding gzip;
  970. expires 31536000s;
  971. etag on;
  972. if_modified_since exact;
  973. add_header Pragma "public";
  974. add_header Cache-Control "public";
  975. add_header Strict-Transport-Security "max-age=31536000";
  976. add_header X-Frame-Options "SAMEORIGIN";
  977. add_header X-XSS-Protection "1; mode=block";
  978. add_header X-Content-Type-Options "nosniff";
  979. add_header Referrer-Policy "no-referrer-when-downgrade";
  980. add_header Vary "Accept-Encoding";
  981. }
  982. location ~ /wp-content/cache/minify/.*css_gzip\$ {
  983. gzip off;
  984. types {}
  985. default_type text/css;
  986. add_header Content-Encoding gzip;
  987. expires 31536000s;
  988. etag on;
  989. if_modified_since exact;
  990. add_header Pragma "public";
  991. add_header Cache-Control "public";
  992. add_header Strict-Transport-Security "max-age=31536000";
  993. add_header X-Frame-Options "SAMEORIGIN";
  994. add_header X-XSS-Protection "1; mode=block";
  995. add_header X-Content-Type-Options "nosniff";
  996. add_header Referrer-Policy "no-referrer-when-downgrade";
  997. add_header Vary "Accept-Encoding";
  998. }
  999. location ~ /wp-content/cache/page_enhanced.*gzip\$ {
  1000. gzip off;
  1001. types {}
  1002. default_type text/html;
  1003. add_header Content-Encoding gzip;
  1004. expires 3600s;
  1005. etag on;
  1006. if_modified_since exact;
  1007. add_header Pragma "public";
  1008. add_header Cache-Control "public";
  1009. add_header Strict-Transport-Security "max-age=31536000";
  1010. add_header X-Frame-Options "SAMEORIGIN";
  1011. add_header X-XSS-Protection "1; mode=block";
  1012. add_header X-Content-Type-Options "nosniff";
  1013. add_header Referrer-Policy "no-referrer-when-downgrade";
  1014. }
  1015. location ~ \.(css|htc|less|js|js2|js3|js4)\$ {
  1016. expires 31536000s;
  1017. etag on;
  1018. if_modified_since exact;
  1019. add_header Pragma "public";
  1020. add_header Cache-Control "public";
  1021. add_header Strict-Transport-Security "max-age=31536000";
  1022. add_header X-Frame-Options "SAMEORIGIN";
  1023. add_header X-XSS-Protection "1; mode=block";
  1024. add_header X-Content-Type-Options "nosniff";
  1025. add_header Referrer-Policy "no-referrer-when-downgrade";
  1026. try_files \$uri \$uri/ /index.php?\$args;
  1027. }
  1028. location ~ \.(html|htm|rtf|rtx|txt|xsd|xsl|xml)\$ {
  1029. expires 3600s;
  1030. etag on;
  1031. if_modified_since exact;
  1032. add_header Pragma "public";
  1033. add_header Cache-Control "public";
  1034. add_header Strict-Transport-Security "max-age=31536000";
  1035. add_header X-Frame-Options "SAMEORIGIN";
  1036. add_header X-XSS-Protection "1; mode=block";
  1037. add_header X-Content-Type-Options "nosniff";
  1038. add_header Referrer-Policy "no-referrer-when-downgrade";
  1039. try_files \$uri \$uri/ /index.php?\$args;
  1040. }
  1041. location ~ \.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|webp|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|webm|mpp|_otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|_ttf|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)\$ {
  1042. expires 31536000s;
  1043. etag on;
  1044. if_modified_since exact;
  1045. add_header Pragma "public";
  1046. add_header Cache-Control "public";
  1047. add_header Strict-Transport-Security "max-age=31536000";
  1048. add_header X-Frame-Options "SAMEORIGIN";
  1049. add_header X-XSS-Protection "1; mode=block";
  1050. add_header X-Content-Type-Options "nosniff";
  1051. add_header Referrer-Policy "no-referrer-when-downgrade";
  1052. try_files \$uri \$uri/ /index.php?\$args;
  1053. }
  1054. set \$w3tc_enc "";
  1055. if (\$http_accept_encoding ~ gzip) { set \$w3tc_enc _gzip; }
  1056. if (-f \$request_filename\$w3tc_enc) { rewrite (.*) \$1\$w3tc_enc break; }
  1057. rewrite ^/wp-content/cache/minify/ /index.php last;
  1058. set \$w3tc_rewrite 1;
  1059. if (\$request_method = POST) { set \$w3tc_rewrite 0; }
  1060. if (\$query_string != "") { set \$w3tc_rewrite 0; }
  1061. if (\$request_uri !~ \/\$) { set \$w3tc_rewrite 0; }
  1062. if (\$http_cookie ~* "(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle)") {
  1063. set \$w3tc_rewrite 0;
  1064. }
  1065. set \$w3tc_preview "";
  1066. if (\$http_cookie ~* "(w3tc_preview)") { set \$w3tc_preview _preview; }
  1067. set \$w3tc_ssl "";
  1068. if (\$scheme = https) { set \$w3tc_ssl _ssl; }
  1069. if (\$http_x_forwarded_proto = 'https') { set \$w3tc_ssl _ssl; }
  1070. set \$w3tc_enc "";
  1071. if (\$http_accept_encoding ~ gzip) { set \$w3tc_enc _gzip; }
  1072. if (!-f "\$document_root/wp-content/cache/page_enhanced/\$http_host/\$request_uri/_index\$w3tc_ssl\$w3tc_preview.html\$w3tc_enc") {
  1073. set \$w3tc_rewrite 0;
  1074. }
  1075. if (\$w3tc_rewrite = 1) {
  1076. rewrite .* "/wp-content/cache/page_enhanced/\$http_host/\$request_uri/_index\$w3tc_ssl\$w3tc_preview.html\$w3tc_enc" last;
  1077. }
  1078. EOw3c
  1079. cat >> "/etc/nginx/wordpress/wpfc.conf" << EOwpfc
  1080. location / {
  1081. error_page 418 = @cachemiss;
  1082. error_page 419 = @mobileaccess;
  1083. recursive_error_pages on;
  1084. if (\$request_method = POST) { return 418; }
  1085. if (\$arg_s != "") { return 418; }
  1086. if (\$arg_p != "") { return 418; }
  1087. if (\$args ~ "amp") { return 418; }
  1088. if (\$arg_preview = "true") { return 418; }
  1089. if (\$arg_ao_noptimize != "") { return 418; }
  1090. if (\$http_cookie ~* "wordpress_logged_in_") { return 418; }
  1091. if (\$http_cookie ~* "comment_author_") { return 418; }
  1092. if (\$http_cookie ~* "wp_postpass_") { return 418; }
  1093. if (\$http_user_agent = "Amazon CloudFront" ) { return 403; access_log off; }
  1094. if (\$http_x_pull = "KeyCDN") { return 403; access_log off; }
  1095. try_files "/wp-content/cache/all/\${uri}index.html" \$uri \$uri/ /index.php\$is_args\$args;
  1096. add_header "X-Cache" "HIT";
  1097. add_header "Vary" "Cookie";
  1098. }
  1099. location @mobileaccess {
  1100. try_files "/wp-content/cache/wpfc-mobile-cache/\${uri}index.html" \$uri \$uri/ /index.php\$is_args\$args;
  1101. add_header "X-Cache" "HIT";
  1102. add_header "Vary" "User-Agent, Cookie";
  1103. expires 30m;
  1104. add_header "Cache-Control" "must-revalidate";
  1105. }
  1106. location @cachemiss {
  1107. try_files \$uri \$uri/ /index.php\$is_args\$args;
  1108. }
  1109. include /etc/nginx/extra/staticfiles.conf;
  1110. EOwpfc
  1111. cat >> "/etc/nginx/wordpress/wpsc.conf" << EOwpsc
  1112. set \$cache_uri \$request_uri;
  1113. if (\$request_method = POST) { set \$cache_uri 'null cache'; }
  1114. if (\$query_string != "") { set \$cache_uri 'null cache'; }
  1115. if (\$request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
  1116. set \$cache_uri 'null cache';
  1117. }
  1118. if (\$http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {
  1119. set \$cache_uri 'null cache';
  1120. }
  1121. location / {
  1122. try_files /wp-content/cache/supercache/\$http_host/\$cache_uri/index.html \$uri \$uri/ /index.php ;
  1123. }
  1124. include /etc/nginx/extra/staticfiles.conf;
  1125. EOwpsc
  1126. cat >> "/etc/nginx/wordpress/enabler.conf" << EOenabler
  1127. location / {
  1128. error_page 418 = @cachemiss;
  1129. error_page 419 = @mobileaccess;
  1130. recursive_error_pages on;
  1131. if (\$request_method = POST) { return 418; }
  1132. if (\$arg_s != "") { return 418; }
  1133. if (\$arg_p != "") { return 418; }
  1134. if (\$args ~ "amp") { return 418; }
  1135. if (\$arg_preview = "true") { return 418; }
  1136. if (\$arg_ao_noptimize != "") { return 418; }
  1137. if (\$http_cookie ~* "wordpress_logged_in_") { return 418; }
  1138. if (\$http_cookie ~* "comment_author_") { return 418; }
  1139. if (\$http_cookie ~* "wp_postpass_") { return 418; }
  1140. try_files "/wp-content/cache/cache-enabler/\$host\${uri}index.html" \$uri \$uri/ /index.php\$is_args\$args;
  1141. add_header "X-Cache" "HIT";
  1142. expires 30m;
  1143. add_header "Cache-Control" "must-revalidate";
  1144. }
  1145. location @mobileaccess {
  1146. try_files "/wp-content/cache/supercache/\$host\${uri}index\$https_suffix-mobile.html" \$uri \$uri/ /index.php\$is_args\$args;
  1147. add_header "X-Cache" "HIT";
  1148. expires 30m;
  1149. add_header "Cache-Control" "must-revalidate";
  1150. }
  1151. location @cachemiss {
  1152. try_files \$uri \$uri/ /index.php\$is_args\$args;
  1153. }
  1154. include /etc/nginx/extra/staticfiles.conf;
  1155. EOenabler
  1156. cat >> "/etc/nginx/wordpress/swift2.conf" << EOswift2
  1157. set \$swift_cache 1;
  1158. if (\$request_method = POST){ set \$swift_cache 0; }
  1159. if (\$args != ''){ set \$swift_cache 0; }
  1160. if (\$http_cookie ~* "wordpress_logged_in") { set \$swift_cache 0; }
  1161. if (\$request_uri ~ ^/wp-content/cache/swift-performance/([^/]*)/assetproxy) {
  1162. set \$swift_cache 0;
  1163. }
  1164. if (!-f "/wp-content/cache/swift-performance//\$http_host/\$request_uri/desktop/unauthenticated/index.html") {
  1165. set \$swift_cache 0;
  1166. }
  1167. if (\$swift_cache = 1){
  1168. rewrite .* /wp-content/cache/swift-performance//\$http_host/\$request_uri/desktop/unauthenticated/index.html last;
  1169. }
  1170. include /etc/nginx/extra/staticfiles.conf;
  1171. EOswift2
  1172. }
  1173. # Extra config
  1174. create_extra_conf(){
  1175. # Include http block
  1176. if [[ ! -d "/etc/nginx/extra" ]]; then
  1177. mkdir -p /etc/nginx/extra
  1178. fi
  1179. cat >> "/etc/nginx/extra/brotli.conf" << EOFBRCONF
  1180. ##Brotli Compression
  1181. brotli on;
  1182. brotli_static on;
  1183. brotli_buffers 16 8k;
  1184. brotli_comp_level 4;
  1185. brotli_types
  1186. application/atom+xml
  1187. application/geo+json
  1188. application/javascript
  1189. application/json
  1190. application/ld+json
  1191. application/manifest+json
  1192. application/rdf+xml
  1193. application/rss+xml
  1194. application/vnd.ms-fontobject
  1195. application/wasm
  1196. application/x-font-opentype
  1197. application/x-font-truetype
  1198. application/x-font-ttf
  1199. application/x-javascript
  1200. application/x-web-app-manifest+json
  1201. application/xhtml+xml
  1202. application/xml
  1203. application/xml+rss
  1204. font/eot
  1205. font/opentype
  1206. font/otf
  1207. image/bmp
  1208. image/svg+xml
  1209. image/vnd.microsoft.icon
  1210. image/x-icon
  1211. image/x-win-bitmap
  1212. text/cache-manifest
  1213. text/calendar
  1214. text/css
  1215. text/javascript
  1216. text/markdown
  1217. text/plain
  1218. text/vcard
  1219. text/vnd.rim.location.xloc
  1220. text/vtt
  1221. text/x-component
  1222. text/x-cross-domain-policy
  1223. text/xml;
  1224. EOFBRCONF
  1225. cat >> "/etc/nginx/extra/gzip.conf" << EOFGZCONF
  1226. ##Gzip Compression
  1227. gzip on;
  1228. gzip_static on;
  1229. gzip_disable msie6;
  1230. gzip_vary on;
  1231. gzip_proxied any;
  1232. gzip_comp_level 2;
  1233. gzip_buffers 16 8k;
  1234. gzip_http_version 1.1;
  1235. gzip_min_length 256;
  1236. gzip_types
  1237. application/atom+xml
  1238. application/geo+json
  1239. application/javascript
  1240. application/json
  1241. application/ld+json
  1242. application/manifest+json
  1243. application/rdf+xml
  1244. application/rss+xml
  1245. application/vnd.ms-fontobject
  1246. application/wasm
  1247. application/x-font-opentype
  1248. application/x-font-truetype
  1249. application/x-font-ttf
  1250. application/x-javascript
  1251. application/x-web-app-manifest+json
  1252. application/xhtml+xml
  1253. application/xml
  1254. application/xml+rss
  1255. font/eot
  1256. font/opentype
  1257. font/otf
  1258. image/bmp
  1259. image/svg+xml
  1260. image/vnd.microsoft.icon
  1261. image/x-icon
  1262. image/x-win-bitmap
  1263. text/cache-manifest
  1264. text/calendar
  1265. text/css
  1266. text/javascript
  1267. text/markdown
  1268. text/plain
  1269. text/vcard
  1270. text/vnd.rim.location.xloc
  1271. text/vtt
  1272. text/x-component
  1273. text/x-cross-domain-policy
  1274. text/xml;
  1275. EOFGZCONF
  1276. cat >> "/etc/nginx/extra/ssl.conf" << EOFSSLCONF
  1277. # SSL
  1278. ssl_session_timeout 1d;
  1279. ssl_session_cache shared:SSL:${SSL_CACHE_SIZE}m;
  1280. ssl_session_tickets off;
  1281. # Diffie-Hellman parameter for DHE ciphersuites
  1282. ssl_dhparam /etc/nginx/ssl/dhparams.pem;
  1283. # Mozilla Intermediate configuration
  1284. ssl_protocols TLSv1.2 TLSv1.3;
  1285. ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
  1286. # OCSP Stapling
  1287. #ssl_stapling on;
  1288. #ssl_stapling_verify on;
  1289. resolver 1.1.1.1 1.0.0.1 8.8.8.8 8.8.4.4 208.67.222.222 208.67.220.220 valid=10m;
  1290. resolver_timeout 10s;
  1291. EOFSSLCONF
  1292. cat >> "/etc/nginx/extra/cloudflare.conf" << EOCF
  1293. set_real_ip_from 173.245.48.0/20;
  1294. set_real_ip_from 103.21.244.0/22;
  1295. set_real_ip_from 103.22.200.0/22;
  1296. set_real_ip_from 103.31.4.0/22;
  1297. set_real_ip_from 141.101.64.0/18;
  1298. set_real_ip_from 108.162.192.0/18;
  1299. set_real_ip_from 190.93.240.0/20;
  1300. set_real_ip_from 188.114.96.0/20;
  1301. set_real_ip_from 197.234.240.0/22;
  1302. set_real_ip_from 198.41.128.0/17;
  1303. set_real_ip_from 162.158.0.0/15;
  1304. set_real_ip_from 104.16.0.0/12;
  1305. set_real_ip_from 172.64.0.0/13;
  1306. set_real_ip_from 131.0.72.0/22;
  1307. #set_real_ip_from 2400:cb00::/32;
  1308. #set_real_ip_from 2606:4700::/32;
  1309. #set_real_ip_from 2803:f800::/32;
  1310. #set_real_ip_from 2405:b500::/32;
  1311. #set_real_ip_from 2405:8100::/32;
  1312. #set_real_ip_from 2a06:98c0::/29;
  1313. #set_real_ip_from 2c0f:f248::/32;
  1314. real_ip_header X-Forwarded-For;
  1315. EOCF
  1316. cat >> "/etc/nginx/extra/nginx_limits.conf" << EOCF
  1317. fastcgi_connect_timeout 60;
  1318. fastcgi_buffer_size 128k;
  1319. fastcgi_buffers 256 16k;
  1320. fastcgi_busy_buffers_size 256k;
  1321. fastcgi_temp_file_write_size 256k;
  1322. fastcgi_send_timeout 600;
  1323. fastcgi_read_timeout 600;
  1324. fastcgi_intercept_errors on;
  1325. fastcgi_param HTTP_PROXY "";
  1326. EOCF
  1327. # Include Server block
  1328. cat >> "/etc/nginx/extra/staticfiles.conf" << EOSTATICFILES
  1329. location = /favicon.ico { allow all; log_not_found off; access_log off; }
  1330. location = /robots.txt { allow all; log_not_found off; access_log off; }
  1331. location ~* \.(gif|jpg|jpeg|png|ico|webp)\$ {
  1332. gzip_static off;
  1333. ${BROTLI_STATIC_OFF}
  1334. add_header Access-Control-Allow-Origin *;
  1335. add_header Cache-Control "public, must-revalidate, proxy-revalidate, immutable, stale-while-revalidate=86400, stale-if-error=604800";
  1336. access_log off;
  1337. expires 97d;
  1338. break;
  1339. }
  1340. location ~* \.(3gp|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso)\$ {
  1341. gzip_static off;
  1342. ${BROTLI_STATIC_OFF}
  1343. sendfile off;
  1344. sendfile_max_chunk 1m;
  1345. add_header Access-Control-Allow-Origin *;
  1346. add_header Cache-Control "public, must-revalidate, proxy-revalidate, immutable, stale-while-revalidate=86400, stale-if-error=604800";
  1347. access_log off;
  1348. expires 97d;
  1349. break;
  1350. }
  1351. location ~* \.(js)\$ {
  1352. add_header Access-Control-Allow-Origin *;
  1353. add_header Cache-Control "public, must-revalidate, proxy-revalidate, immutable, stale-while-revalidate=86400, stale-if-error=604800";
  1354. access_log off;
  1355. expires 97d;
  1356. break;
  1357. }
  1358. location ~* \.(css)\$ {
  1359. add_header Access-Control-Allow-Origin *;
  1360. add_header Cache-Control "public, must-revalidate, proxy-revalidate, immutable, stale-while-revalidate=86400, stale-if-error=604800";
  1361. access_log off;
  1362. expires 97d;
  1363. break;
  1364. }
  1365. location ~* \.(eot|svg|ttf|woff|woff2)\$ {
  1366. add_header Access-Control-Allow-Origin *;
  1367. add_header Cache-Control "public, must-revalidate, proxy-revalidate";
  1368. access_log off;
  1369. expires 365d;
  1370. break;
  1371. }
  1372. EOSTATICFILES
  1373. cat >> "/etc/nginx/extra/security.conf" << EOsecurity
  1374. location ^~ /GponForm/ { deny all; access_log off; log_not_found off; }
  1375. location ^~ /GponForm/diag_Form { deny all; access_log off; log_not_found off; }
  1376. # Return 403 forbidden for readme.(txt|html) or license.(txt|html) or example.(txt|html) or other common git repository files
  1377. location ~* "/(^\$|readme|license|example|LICENSE|README|LEGALNOTICE|INSTALLATION|CHANGELOG)\.(txt|html|md)" {
  1378. deny all;
  1379. }
  1380. location ~ ^/(\.user.ini|\.htaccess|\.htpasswd|\.user\.ini|\.ht|\.env|\.git|\.svn|\.project) {
  1381. deny all;
  1382. access_log off;
  1383. log_not_found off;
  1384. }
  1385. # Deny backup extensions & log files and return 403 forbidden
  1386. location ~* "\.(love|error|kid|cgi|old|orig|original|php#|php~|php_bak|save|swo|aspx?|tpl|sh|bash|bak?|cfg|cgi|dll|exe|git|hg|ini|jsp|log|mdb|out|sql|svn|swp|tar|rdf|gz|zip|bz2|7z|pem|asc|conf|dump)\$" {
  1387. deny all;
  1388. }
  1389. # block base64_encoded content
  1390. location ~* "(base64_encode)(.*)(\()" { deny all; }
  1391. # block javascript eval()
  1392. location ~* "(eval\()" { deny all; }
  1393. # Additional security settings
  1394. location ~* "(127\.0\.0\.1)" { deny all; }
  1395. location ~* "([a-z0-9]{2000})" { deny all; }
  1396. location ~* "(javascript\:)(.*)(\;)" { deny all; }
  1397. location ~* "(GLOBALS|REQUEST)(=|\[|%)" { deny all; }
  1398. location ~* "(<|%3C).*script.*(>|%3)" { deny all; }
  1399. location ~* "(boot\.ini|etc/passwd|self/environ)" { deny all; }
  1400. location ~* "(thumbs?(_editor|open)?|tim(thumb)?)\.php" { deny all; }
  1401. location ~* "(https?|ftp|php):/" { deny all; }
  1402. EOsecurity
  1403. }
  1404. vhost_custom(){
  1405. REWRITE_CONFIG_PATH="/etc/nginx/rewrite"
  1406. mkdir -p "${REWRITE_CONFIG_PATH}"
  1407. cat >> "${REWRITE_CONFIG_PATH}/default.conf" << EOrewrite_default
  1408. location / {
  1409. try_files \$uri \$uri/ /index.php?\$query_string;
  1410. }
  1411. EOrewrite_default
  1412. cat >> "${REWRITE_CONFIG_PATH}/codeigniter.conf" << EOrewrite_ci
  1413. location / {
  1414. try_files \$uri \$uri/ /index.php?/\$request_uri;
  1415. }
  1416. EOrewrite_ci
  1417. cat >> "${REWRITE_CONFIG_PATH}/discuz.conf" << EOrewrite_discuz
  1418. location / {
  1419. rewrite ^([^\.]*)/topic-(.+)\.html\$ \$1/portal.php?mod=topic&topic=\$2 last;
  1420. rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html\$ \$1/portal.php?mod=view&aid=\$2&page=\$3 last;
  1421. rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html\$ \$1/forum.php?mod=forumdisplay&fid=\$2&page=\$3 last;
  1422. rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html\$ \$1/forum.php?mod=viewthread&tid=\$2&extra=page%3D\$4&page=\$3 last;
  1423. rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html\$ \$1/forum.php?mod=group&fid=\$2&page=\$3 last;
  1424. rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html\$ \$1/home.php?mod=space&\$2=\$3 last;
  1425. rewrite ^([^\.]*)/blog-([0-9]+)-([0-9]+)\.html\$ \$1/home.php?mod=space&uid=\$2&do=blog&id=\$3 last;
  1426. rewrite ^([^\.]*)/(fid|tid)-([0-9]+)\.html\$ \$1/index.php?action=\$2&value=\$3 last;
  1427. rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html\$ \$1/plugin.php?id=\$2:\$3 last;
  1428. }
  1429. EOrewrite_discuz
  1430. cat >> "${REWRITE_CONFIG_PATH}/drupal.conf" << EOrewrite_drupal
  1431. location / {
  1432. try_files \$uri /index.php?\$query_string;
  1433. }
  1434. location ~ \..*/.*\.php\$ { return 403; }
  1435. location ~ ^/sites/.*/private/ { return 403; }
  1436. # Block access to scripts in site files directory
  1437. location ~ ^/sites/[^/]+/files/.*\.php\$ { deny all; }
  1438. location ~ (^|/)\. { return 403; }
  1439. location ~ /vendor/.*\.php\$ { deny all; return 404; }
  1440. location @rewrite {
  1441. rewrite ^/(.*)\$ /index.php?q=\$1;
  1442. }
  1443. location ~* \.(engine|inc|install|make|module|profile|po|sh|.*sql|theme|twig|tpl(\.php)?|xtmpl|yml)(~|\.sw[op]|\.bak|\.orig|\.save)?\$|composer\.(lock|json)\$|web\.config\$|^(\.(?!well-known).*|Entries.*|Repository|Root|Tag|Template)\$|^#.*#\$|\.php(~|\.sw[op]|\.bak|\.orig|\.save)\$ {
  1444. deny all;
  1445. return 404;
  1446. }
  1447. location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)\$ {
  1448. try_files \$uri @rewrite;
  1449. expires max;
  1450. log_not_found off;
  1451. }
  1452. location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7
  1453. try_files \$uri @rewrite;
  1454. }
  1455. location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7
  1456. try_files \$uri /index.php?\$query_string;
  1457. }
  1458. if (\$request_uri ~* "^(.*/)index\.php/(.*)") {
  1459. return 307 \$1\$2;
  1460. }
  1461. EOrewrite_drupal
  1462. cat >> "${REWRITE_CONFIG_PATH}/ecshop.conf" << EOrewrite_ecshop
  1463. if (!-e \$request_filename) {
  1464. rewrite "^/index\.html" /index.php last;
  1465. rewrite "^/category\$" /index.php last;
  1466. rewrite "^/feed-c([0-9]+)\.xml\$" /feed.php?cat=\$1 last;
  1467. rewrite "^/feed-b([0-9]+)\.xml\$" /feed.php?brand=\$1 last;
  1468. rewrite "^/feed\.xml\$" /feed.php last;
  1469. rewrite "^/category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html\$" /category.php?id=\$1&brand=\$2&price_min=\$3&price_max=\$4&filter_attr=\$5&page=\$6&sort=\$7&order=\$8 last;
  1470. rewrite "^/category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)(.*)\.html\$" /category.php?id=\$1&brand=\$2&price_min=\$3&price_max=\$4&filter_attr=\$5 last;
  1471. rewrite "^/category-([0-9]+)-b([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html\$" /category.php?id=\$1&brand=\$2&page=\$3&sort=\$4&order=\$5 last;
  1472. rewrite "^/category-([0-9]+)-b([0-9]+)-([0-9]+)(.*)\.html\$" /category.php?id=\$1&brand=\$2&page=\$3 last;
  1473. rewrite "^/category-([0-9]+)-b([0-9]+)(.*)\.html\$" /category.php?id=\$1&brand=\$2 last;
  1474. rewrite "^/category-([0-9]+)(.*)\.html\$" /category.php?id=\$1 last;
  1475. rewrite "^/goods-([0-9]+)(.*)\.html" /goods.php?id=\$1 last;
  1476. rewrite "^/article_cat-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html\$" /article_cat.php?id=\$1&page=\$2&sort=\$3&order=\$4 last;
  1477. rewrite "^/article_cat-([0-9]+)-([0-9]+)(.*)\.html\$" /article_cat.php?id=\$1&page=\$2 last;
  1478. rewrite "^/article_cat-([0-9]+)(.*)\.html\$" /article_cat.php?id=\$1 last;
  1479. rewrite "^/article-([0-9]+)(.*)\.html\$" /article.php?id=\$1 last;
  1480. rewrite "^/brand-([0-9]+)-c([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)\.html" /brand.php?id=\$1&cat=\$2&page=\$3&sort=\$4&order=\$5 last;
  1481. rewrite "^/brand-([0-9]+)-c([0-9]+)-([0-9]+)(.*)\.html" /brand.php?id=\$1&cat=\$2&page=\$3 last;
  1482. rewrite "^/brand-([0-9]+)-c([0-9]+)(.*)\.html" /brand.php?id=\$1&cat=\$2 last;
  1483. rewrite "^/brand-([0-9]+)(.*)\.html" /brand.php?id=\$1 last;
  1484. rewrite "^/tag-(.*)\.html" /search.php?keywords=\$1 last;
  1485. rewrite "^/snatch-([0-9]+)\.html\$" /snatch.php?id=\$1 last;
  1486. rewrite "^/group_buy-([0-9]+)\.html\$" /group_buy.php?act=view&id=\$1 last;
  1487. rewrite "^/auction-([0-9]+)\.html\$" /auction.php?act=view&id=\$1 last;
  1488. rewrite "^/exchange-id([0-9]+)(.*)\.html\$" /exchange.php?id=\$1&act=view last;
  1489. rewrite "^/exchange-([0-9]+)-min([0-9]+)-max([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html\$" /exchange.php?cat_id=\$1&integral_min=\$2&integral_max=\$3&page=\$4&sort=\$5&order=\$6 last;
  1490. rewrite "^/exchange-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html\$" /exchange.php?cat_id=\$1&page=\$2&sort=\$3&order=\$4 last;
  1491. rewrite "^/exchange-([0-9]+)-([0-9]+)(.*)\.html\$" /exchange.php?cat_id=\$1&page=\$2 last;
  1492. rewrite "^/exchange-([0-9]+)(.*)\.html\$" /exchange.php?cat_id=\$1 last;
  1493. }
  1494. EOrewrite_ecshop
  1495. cat >> "${REWRITE_CONFIG_PATH}/xenforo.conf" << EOrewrite_xenforo
  1496. location / {
  1497. try_files \$uri \$uri/ /index.php?\$uri&\$args;
  1498. }
  1499. location /install/data/ { internal; }
  1500. location /install/templates/ { internal; }
  1501. location /internal_data/ { internal; }
  1502. location /library/ { internal; }
  1503. location /src/ { internal; }
  1504. EOrewrite_xenforo
  1505. cat >> "${REWRITE_CONFIG_PATH}/joomla.conf" << EOjoomla
  1506. location / {
  1507. try_files \$uri \$uri/ /index.php?\$args;
  1508. }
  1509. EOjoomla
  1510. cat >> "${REWRITE_CONFIG_PATH}/laravel.conf" << EOlaravel
  1511. location / {
  1512. try_files \$uri \$uri/ /index.php?\$query_string;
  1513. }
  1514. EOlaravel
  1515. cat >> "${REWRITE_CONFIG_PATH}/whmcs.conf" << EOwhmcs
  1516. location ~ /announcements/?(.*)\$ {
  1517. rewrite ^/(.*)\$ /index.php?rp=/announcements/\$1;
  1518. }
  1519. location ~ /download/?(.*)\$ {
  1520. rewrite ^/(.*)\$ /index.php?rp=/download\$1;
  1521. }
  1522. location ~ /knowledgebase/?(.*)\$ {
  1523. rewrite ^/(.*)\$ /index.php?rp=/knowledgebase/\$1;
  1524. }
  1525. location ~ /store/ssl-certificates/?(.*)\$ {
  1526. rewrite ^/(.*)\$ /index.php?rp=/store/ssl-certificates/\$1;
  1527. }
  1528. location ~ /store/sitelock/?(.*)\$ {
  1529. rewrite ^/(.*)\$ /index.php?rp=/store/sitelock/\$1;
  1530. }
  1531. location ~ /store/website-builder/?(.*)\$ {
  1532. rewrite ^/(.*)\$ /index.php?rp=/store/website-builder/\$1;
  1533. }
  1534. location ~ /store/order/?(.*)\$ {
  1535. rewrite ^/(.*)\$ /index.php?rp=/store/order/\$1;
  1536. }
  1537. location ~ /cart/domain/renew/?(.*)\$ {
  1538. rewrite ^/(.*)\$ /index.php?rp=/cart/domain/renew\$1;
  1539. }
  1540. location ~ /account/paymentmethods/?(.*)\$ {
  1541. rewrite ^/(.*)\$ /index.php?rp=/account/paymentmethods\$1;
  1542. }
  1543. location ~ /admin/(addons|apps|domains|help\/license|services|setup|utilities\/system\/php-compat)(.*) {
  1544. rewrite ^/(.*)\$ /admin/index.php?rp=/admin/\$1\$2 last;
  1545. }
  1546. EOwhmcs
  1547. cat >> "${REWRITE_CONFIG_PATH}/wordpress.conf" << EOwordpress
  1548. location / {
  1549. try_files \$uri \$uri/ /index.php?\$args;
  1550. }
  1551. EOwordpress
  1552. cat >> "${REWRITE_CONFIG_PATH}/prestashop.conf" << EOprestashop
  1553. location / {
  1554. rewrite ^/api/?(.*)\$ /webservice/dispatcher.php?url=\$1 last;
  1555. rewrite ^/([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg\$ /img/p/\$1/\$1\$2.jpg last;
  1556. rewrite ^/([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg\$ /img/p/\$1/\$2/\$1\$2\$3.jpg last;
  1557. rewrite ^/([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg\$ /img/p/\$1/\$2/\$3/\$1\$2\$3\$4.jpg last;
  1558. rewrite ^/([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg\$ /img/p/\$1/\$2/\$3/\$4/\$1\$2\$3\$4\$5.jpg last;
  1559. rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg\$ /img/p/\$1/\$2/\$3/\$4/\$5/\$1\$2\$3\$4\$5\$6.jpg last;
  1560. rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg\$ /img/p/\$1/\$2/\$3/\$4/\$5/\$6/\$1\$2\$3\$4\$5\$6\$7.jpg last;
  1561. rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg\$ /img/p/\$1/\$2/\$3/\$4/\$5/\$6/\$7/\$1\$2\$3\$4\$5\$6\$7\$8.jpg last;
  1562. rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg\$ /img/p/\$1/\$2/\$3/\$4/\$5/\$6/\$7/\$8/\$1\$2\$3\$4\$5\$6\$7\$8\$9.jpg last;
  1563. rewrite ^/c/([0-9]+)(-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg\$ /img/c/\$1\$2.jpg last;
  1564. rewrite ^/c/([a-zA-Z-]+)(-[0-9]+)?/.+\.jpg\$ /img/c/\$1.jpg last;
  1565. rewrite ^/([0-9]+)(-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg\$ /img/c/\$1\$2.jpg last;
  1566. try_files \$uri \$uri/ /index.php?\$args;
  1567. }
  1568. EOprestashop
  1569. cat >> "${REWRITE_CONFIG_PATH}/opencart.conf" << EOopencart
  1570. rewrite /admin\$ \$scheme://\$host\$uri/ permanent;
  1571. rewrite ^/download/(.*) /index.php?route=error/not_found last;
  1572. rewrite ^/image-smp/(.*) /index.php?route=product/smp_image&name=\$1 break;
  1573. location = /sitemap.xml {
  1574. rewrite ^(.*)\$ /index.php?route=feed/google_sitemap break;
  1575. }
  1576. location = /googlebase.xml {
  1577. rewrite ^(.*)\$ /index.php?route=feed/google_base break;
  1578. }
  1579. location / {
  1580. # This try_files directive is used to enable SEO-friendly URLs for OpenCart
  1581. try_files \$uri \$uri/ @opencart;
  1582. }
  1583. location @opencart {
  1584. rewrite ^/(.+)\$ /index.php?_route_=\$1 last;
  1585. }
  1586. location /admin { index index.php; }
  1587. EOopencart
  1588. cat >> "${REWRITE_CONFIG_PATH}/yii.conf" << EOyii
  1589. location / {
  1590. try_files \$uri \$uri/ /index.php\$is_args\$args;
  1591. }
  1592. location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
  1593. try_files \$uri =404;
  1594. }
  1595. EOyii
  1596. }
  1597. # Config default server block
  1598. default_vhost(){
  1599. NGINX_VHOST_PATH="/etc/nginx/conf.d"
  1600. mkdir -p "${USR_DIR}"/nginx/auth
  1601. mkdir -p /etc/nginx/apps
  1602. if [[ -f "${NGINX_VHOST_PATH}/default.conf" ]]; then
  1603. rm -rf "${NGINX_VHOST_PATH}"/default.conf
  1604. fi
  1605. cat >> "/etc/nginx/apps/phpmyadmin.conf" <<EOphpmyadmin_vhost
  1606. location ^~ /phpmyadmin {
  1607. root ${DEFAULT_DIR_TOOL}/;
  1608. index index.php index.html index.htm;
  1609. location ~ ^/phpmyadmin/(.+\.php)\$ {
  1610. try_files \$uri =404;
  1611. fastcgi_split_path_info ^(.+\.php)(/.+)\$;
  1612. fastcgi_index index.php;
  1613. include /etc/nginx/fastcgi_params;
  1614. include /etc/nginx/extra/nginx_limits.conf;
  1615. fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
  1616. if (-f \$request_filename)
  1617. {
  1618. fastcgi_pass php-app;
  1619. }
  1620. }
  1621. location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|webp|xml|txt))\$ {
  1622. root ${DEFAULT_DIR_TOOL}/;
  1623. }
  1624. }
  1625. location ~ ^/pma { rewrite ^/* /phpmyadmin last; }
  1626. location ^~ /phpmyadmin/locale/ { deny all; access_log off; log_not_found off; }
  1627. location ^~ /phpmyadmin/doc/ { deny all; access_log off; log_not_found off; }
  1628. location ^~ /phpmyadmin/log/ { deny all; access_log off; log_not_found off; }
  1629. location ^~ /phpmyadmin/tmp/ { deny all; access_log off; log_not_found off; }
  1630. location ^~ /phpmyadmin/libraries/ { deny all; access_log off; log_not_found off; }
  1631. location ^~ /phpmyadmin/templates/ { deny all; access_log off; log_not_found off; }
  1632. location ^~ /phpmyadmin/sql/ { deny all; access_log off; log_not_found off; }
  1633. location ^~ /phpmyadmin/vendor/ { deny all; access_log off; log_not_found off; }
  1634. location ^~ /phpmyadmin/examples/ { deny all; access_log off; log_not_found off; }
  1635. EOphpmyadmin_vhost
  1636. cat >> "/etc/nginx/apps/opcache.conf" <<EOopcache_vhost
  1637. location ^~ /opcache {
  1638. root ${DEFAULT_DIR_TOOL}/;
  1639. index index.php index.html index.htm;
  1640. location ~ ^/opcache/(.+\.php)\$ {
  1641. try_files \$uri =404;
  1642. fastcgi_split_path_info ^(.+\.php)(/.+)\$;
  1643. fastcgi_index index.php;
  1644. include /etc/nginx/fastcgi_params;
  1645. include /etc/nginx/extra/nginx_limits.conf;
  1646. fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
  1647. if (-f \$request_filename)
  1648. {
  1649. fastcgi_pass php-app;
  1650. }
  1651. }
  1652. location ~* ^/opcache/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|webp|xml|txt))\$ {
  1653. root ${DEFAULT_DIR_TOOL}/;
  1654. }
  1655. }
  1656. EOopcache_vhost
  1657. cat >> "/etc/nginx/apps/serverinfo.conf" <<EOserverinfo_vhost
  1658. location ^~ /serverinfo {
  1659. root ${DEFAULT_DIR_TOOL}/;
  1660. index index.php index.html index.htm;
  1661. location ~ ^/serverinfo/(.+\.php)\$ {
  1662. try_files \$uri =404;
  1663. fastcgi_split_path_info ^(.+\.php)(/.+)\$;
  1664. fastcgi_index index.php;
  1665. include /etc/nginx/fastcgi_params;
  1666. include /etc/nginx/extra/nginx_limits.conf;
  1667. fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
  1668. if (-f \$request_filename)
  1669. {
  1670. fastcgi_pass php-app;
  1671. }
  1672. }
  1673. location ~* ^/serverinfo/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|webp|xml|txt))\$ {
  1674. root ${DEFAULT_DIR_TOOL}/;
  1675. }
  1676. }
  1677. EOserverinfo_vhost
  1678. cat >> "/etc/nginx/apps/memcached.conf" <<EOmemcached_vhost
  1679. location ^~ /memcached {
  1680. root ${DEFAULT_DIR_TOOL}/;
  1681. index index.php index.html index.htm;
  1682. auth_basic "Restricted";
  1683. auth_basic_user_file ${USR_DIR}/nginx/auth/.htpasswd;
  1684. location ~ ^/memcached/(.+\.php)\$ {
  1685. try_files \$uri =404;
  1686. fastcgi_split_path_info ^(.+\.php)(/.+)\$;
  1687. fastcgi_index index.php;
  1688. include /etc/nginx/fastcgi_params;
  1689. include /etc/nginx/extra/nginx_limits.conf;
  1690. fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
  1691. if (-f \$request_filename)
  1692. {
  1693. fastcgi_pass php-app;
  1694. }
  1695. }
  1696. location ~* ^/memcached/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|webp|xml|txt))\$ {
  1697. root ${DEFAULT_DIR_TOOL}/;
  1698. }
  1699. }
  1700. EOmemcached_vhost
  1701. cat >> "/etc/nginx/apps/redis.conf" <<EOredis_vhost
  1702. location ^~ /redis {
  1703. root ${DEFAULT_DIR_TOOL}/;
  1704. index index.php index.html index.htm;
  1705. location ~ ^/redis/(.+\.php)\$ {
  1706. try_files \$uri =404;
  1707. fastcgi_split_path_info ^(.+\.php)(/.+)\$;
  1708. fastcgi_index index.php;
  1709. include /etc/nginx/fastcgi_params;
  1710. include /etc/nginx/extra/nginx_limits.conf;
  1711. fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
  1712. if (-f \$request_filename)
  1713. {
  1714. fastcgi_pass php-app;
  1715. }
  1716. }
  1717. location ~* ^/redis/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|webp|xml|txt))\$ {
  1718. root ${DEFAULT_DIR_TOOL}/;
  1719. }
  1720. }
  1721. EOredis_vhost
  1722. cat >> "/etc/nginx/web_apps.conf" << EOdefault_vhost
  1723. upstream php-app {
  1724. server unix:/var/run/php-fpm.sock;
  1725. }
  1726. server {
  1727. listen 80 default_server;
  1728. root /usr/share/nginx/html/;
  1729. index index.html index.htm;
  1730. error_page 400 401 403 404 500 502 503 504 /50x.html;
  1731. }
  1732. server {
  1733. listen ${RANDOM_ADMIN_PORT};
  1734. server_name ${IPADDRESS};
  1735. access_log off;
  1736. log_not_found off;
  1737. error_log /var/log/nginx_error.log;
  1738. root ${DEFAULT_DIR_TOOL};
  1739. index index.php index.html index.htm;
  1740. auth_basic "Restricted";
  1741. auth_basic_user_file ${USR_DIR}/nginx/auth/.htpasswd;
  1742. include /etc/nginx/apps/phpmyadmin.conf;
  1743. include /etc/nginx/apps/opcache.conf;
  1744. include /etc/nginx/apps/serverinfo.conf;
  1745. include /etc/nginx/apps/memcached.conf;
  1746. include /etc/nginx/apps/redis.conf;
  1747. location /nginx_status {
  1748. stub_status on;
  1749. access_log off;
  1750. allow 127.0.0.1;
  1751. allow ${IPADDRESS};
  1752. deny all;
  1753. }
  1754. location /php_status {
  1755. fastcgi_pass unix:/var/run/php-fpm.sock;
  1756. fastcgi_index index.php;
  1757. fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
  1758. include /etc/nginx/fastcgi_params;
  1759. allow 127.0.0.1;
  1760. allow ${IPADDRESS};
  1761. deny all;
  1762. }
  1763. error_page 400 401 403 404 500 502 503 504 /50x.html;
  1764. include /etc/nginx/extra/security.conf;
  1765. include /etc/nginx/extra/staticfiles.conf;
  1766. }
  1767. EOdefault_vhost
  1768. }
  1769. default_index(){
  1770. if [[ -f "${DEFAULT_DIR_WEB}/index.html" ]]; then
  1771. rm -rf "${DEFAULT_DIR_WEB}"/index.html
  1772. fi
  1773. cat >> "${DEFAULT_DIR_WEB}/index.html" << EOdefault_index
  1774. <!DOCTYPE html>
  1775. <html lang="en">
  1776. <head>
  1777. <title>Site Maintenance</title>
  1778. <style>
  1779. body{text-align:center;padding:150px}
  1780. h1{font-size:50px}
  1781. body{font:20px Helvetica,sans-serif;color:#333}
  1782. article{display:block;text-align:left;max-width:650px;margin:0 auto}
  1783. a{color:#dc8100;text-decoration:none}
  1784. a:hover{color:#333;text-decoration:none}
  1785. </style>
  1786. </head>
  1787. <body>
  1788. <article>
  1789. <h1>We'll be back soon!</h1>
  1790. <div>
  1791. <p>Sorry for the inconvenience but we're performing some maintenance at the moment. If you need to you can always
  1792. <a href="mailto:${ADMIN_EMAIL}">contact us</a>, otherwise we'll be back online shortly!</p>
  1793. </div>
  1794. </article>
  1795. </body>
  1796. </html>
  1797. EOdefault_index
  1798. cp "${DEFAULT_DIR_WEB}"/index.html ${DEFAULT_DIR_TOOL}/index.html
  1799. }
  1800. default_error_page(){
  1801. if [[ -f "${DEFAULT_DIR_WEB}/50x.html" ]]; then
  1802. rm -rf "${DEFAULT_DIR_WEB}"/50x.html
  1803. fi
  1804. cat >> "${DEFAULT_DIR_WEB}/50x.html" << EOdefault_index
  1805. <!DOCTYPE html>
  1806. <html lang="en">
  1807. <head>
  1808. <title>Error</title>
  1809. <style>
  1810. body{text-align:center;padding:150px}
  1811. h1{font-size:50px}
  1812. body{font:20px Helvetica,sans-serif;color:#333}
  1813. article{display:block;text-align:left;max-width:650px;margin:0 auto}
  1814. a{color:#dc8100;text-decoration:none}
  1815. a:hover{color:#333;text-decoration:none}
  1816. </style>
  1817. </head>
  1818. <body>
  1819. <article>
  1820. <h1>An error occurred.</h1>
  1821. <div>
  1822. <p>Sorry, the page you are looking for is currently unavailable. Please try again later. If you need to you can always
  1823. <a href="mailto:${ADMIN_EMAIL}">contact us</a>, otherwise we'll be back online shortly!</p>
  1824. </div>
  1825. </article>
  1826. </body>
  1827. </html>
  1828. EOdefault_index
  1829. cp "${DEFAULT_DIR_WEB}"/50x.html ${DEFAULT_DIR_TOOL}/50x.html
  1830. }
  1831. wprocket_nginx(){
  1832. cd_dir /etc/nginx
  1833. git clone https://github.com/satellitewp/rocket-nginx.git
  1834. cd_dir /etc/nginx/rocket-nginx
  1835. cp rocket-nginx.ini.disabled rocket-nginx.ini
  1836. php rocket-parser.php
  1837. }
  1838. ############################################
  1839. # Config PHP-FPM
  1840. ############################################
  1841. # PHP Parameter
  1842. php_parameter(){
  1843. if [[ ${CPU_CORES} -ge 4 && ${CPU_CORES} -lt 6 && ${RAM_TOTAL} -gt 1049576 && ${RAM_TOTAL} -le 2097152 ]]; then
  1844. PM_MAX_CHILDREN=$((CPU_CORES * 6))
  1845. PM_MAX_REQUEST=2000
  1846. elif [[ ${CPU_CORES} -ge 4 && ${CPU_CORES} -lt 6 && ${RAM_TOTAL} -gt 2097152 && ${RAM_TOTAL} -le 3145728 ]]; then
  1847. PM_MAX_CHILDREN=$((CPU_CORES * 6))
  1848. PM_MAX_REQUEST=2000
  1849. elif [[ ${CPU_CORES} -ge 4 && ${CPU_CORES} -lt 6 && ${RAM_TOTAL} -gt 3145728 && ${RAM_TOTAL} -le 4194304 ]]; then
  1850. PM_MAX_CHILDREN=$((CPU_CORES * 6))
  1851. PM_MAX_REQUEST=2000
  1852. elif [[ ${CPU_CORES} -ge 4 && ${CPU_CORES} -lt 6 && ${RAM_TOTAL} -gt 4194304 ]]; then
  1853. PM_MAX_CHILDREN=$((CPU_CORES * 6))
  1854. PM_MAX_REQUEST=2000
  1855. elif [[ ${CPU_CORES} -ge 6 && ${CPU_CORES} -lt 8 && ${RAM_TOTAL} -gt 3145728 && ${RAM_TOTAL} -le 4194304 ]]; then
  1856. PM_MAX_CHILDREN=$((CPU_CORES * 6))
  1857. PM_MAX_REQUEST=2000
  1858. elif [[ ${CPU_CORES} -ge 6 && ${CPU_CORES} -lt 8 && ${RAM_TOTAL} -gt 4194304 ]]; then
  1859. PM_MAX_CHILDREN=$((CPU_CORES * 6))
  1860. PM_MAX_REQUEST=2000
  1861. elif [[ ${CPU_CORES} -ge 8 && ${CPU_CORES} -lt 16 && ${RAM_TOTAL} -gt 3145728 && ${RAM_TOTAL} -le 4194304 ]]; then
  1862. PM_MAX_CHILDREN=$((CPU_CORES * 6))
  1863. PM_MAX_REQUEST=2000
  1864. elif [[ ${CPU_CORES} -ge 8 && ${CPU_CORES} -lt 12 && ${RAM_TOTAL} -gt 4194304 ]]; then
  1865. PM_MAX_CHILDREN=$((CPU_CORES * 6))
  1866. PM_MAX_REQUEST=2000
  1867. elif [[ ${CPU_CORES} -ge 13 && ${CPU_CORES} -lt 16 && ${RAM_TOTAL} -gt 4194304 ]]; then
  1868. PM_MAX_CHILDREN=$((CPU_CORES * 6))
  1869. PM_MAX_REQUEST=2000
  1870. elif [[ ${CPU_CORES} -ge 17 && ${RAM_TOTAL} -gt 4194304 ]]; then
  1871. PM_MAX_CHILDREN=$((CPU_CORES * 5))
  1872. PM_MAX_REQUEST=2000
  1873. else
  1874. PM_MAX_CHILDREN=$((CPU_CORES * 5))
  1875. PM_MAX_REQUEST=500
  1876. fi
  1877. }
  1878. php_global_config(){
  1879. php_parameter
  1880. if [[ -f "/etc/php-fpm.conf" ]]; then
  1881. mv /etc/php-fpm.conf /etc/php-fpm.conf.orig
  1882. fi
  1883. if [[ ! -d "/var/run/php-fpm" ]]; then
  1884. mkdir -p /var/run/php-fpm
  1885. fi
  1886. cat >> "/etc/php-fpm.conf" << EOphp_fpm_conf
  1887. ;;;;;;;;;;;;;;;;;;;;;
  1888. ; FPM Configuration ;
  1889. ;;;;;;;;;;;;;;;;;;;;;
  1890. include=/etc/php-fpm.d/*.conf
  1891. [global]
  1892. pid = /var/run/php-fpm/php-fpm.pid
  1893. error_log = /var/log/php-fpm/error.log
  1894. log_level = warning
  1895. emergency_restart_threshold = 10
  1896. emergency_restart_interval = 1m
  1897. process_control_timeout = 10s
  1898. daemonize = yes
  1899. EOphp_fpm_conf
  1900. if [[ -f "/etc/php-fpm.d/www.conf" ]]; then
  1901. mv /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.conf.orig
  1902. fi
  1903. cat >> "/etc/php-fpm.d/www.conf" << EOwww_conf
  1904. [www]
  1905. listen = /var/run/php-fpm.sock;
  1906. listen.allowed_clients = 127.0.0.1
  1907. listen.owner = nginx
  1908. listen.group = nginx
  1909. listen.mode = 0660
  1910. user = nginx
  1911. group = nginx
  1912. pm = ondemand
  1913. pm.max_children = ${PM_MAX_CHILDREN}
  1914. pm.max_requests = ${PM_MAX_REQUEST}
  1915. pm.process_idle_timeout = 20
  1916. ;slowlog = /var/log/php-fpm/www-slow.log
  1917. chdir = /
  1918. php_admin_value[error_log] = /var/log/php-fpm/www-error.log
  1919. php_admin_flag[log_errors] = on
  1920. php_value[session.save_handler] = files
  1921. php_value[session.save_path] = /var/lib/php/session
  1922. php_value[soap.wsdl_cache_dir] = /var/lib/php/wsdlcache
  1923. php_admin_value[disable_functions] = exec,system,passthru,shell_exec,dl,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
  1924. ;php_admin_value[disable_functions] = exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
  1925. ;php_admin_value[open_basedir] = ${DEFAULT_DIR_TOOL}/:/tmp/:/var/tmp/:/dev/urandom:/usr/share/php/:/dev/shm:/var/lib/php/sessions/
  1926. security.limit_extensions = .php
  1927. EOwww_conf
  1928. if [[ ! -d "/var/lib/php/session" ]]; then
  1929. mkdir -p /var/lib/php/session
  1930. fi
  1931. if [[ ! -d "/var/lib/php/wsdlcache" ]]; then
  1932. mkdir -p /var/lib/php/wsdlcache
  1933. fi
  1934. if [[ ! -d "/var/log/php-fpm" ]]; then
  1935. mkdir -p /var/log/php-fpm
  1936. fi
  1937. chown -R nginx:nginx /var/lib/php/session
  1938. chown -R nginx:nginx /var/lib/php/wsdlcache
  1939. chown -R nginx:nginx /var/log/php-fpm
  1940. chmod 755 /var/lib/php/session
  1941. chmod 755 /var/lib/php/wsdlcache
  1942. }
  1943. php_global_config_2(){
  1944. php2_fpm_config_file="/etc/opt/remi/${PHP_VERSION_2}/php-fpm.conf"
  1945. php2_fpm_config_path="/etc/opt/remi/${PHP_VERSION_2}/php-fpm.d"
  1946. www2_config_file="/etc/opt/remi/${PHP_VERSION_2}/php-fpm.d/www.conf"
  1947. if [[ ${PHP_VERSION_2} == "php56" ]]; then
  1948. php2_fpm_config_file="/opt/remi/${PHP_VERSION_2}/root/etc/php-fpm.conf"
  1949. php2_fpm_config_path="/opt/remi/php56/root/etc/php-fpm.d"
  1950. www2_config_file="/opt/remi/${PHP_VERSION_2}/root/etc/php-fpm.d"
  1951. fi
  1952. if [[ -f "${php2_fpm_config_file}" ]]; then
  1953. mv "${php2_fpm_config_file}" "${php2_fpm_config_file}".orig
  1954. fi
  1955. if [[ ! -d "/opt/remi/${PHP_VERSION_2}/root/var/run/php-fpm" ]]; then
  1956. mkdir -p /opt/remi/"${PHP_VERSION_2}"/root/var/run/php-fpm
  1957. fi
  1958. cat >> "${php2_fpm_config_file}" << EOphp_fpm_2_conf
  1959. ;;;;;;;;;;;;;;;;;;;;;
  1960. ; FPM Configuration ;
  1961. ;;;;;;;;;;;;;;;;;;;;;
  1962. include=${php2_fpm_config_path}/*.conf
  1963. [global]
  1964. pid = /opt/remi/${PHP_VERSION_2}/root/var/run/php-fpm/php-fpm.pid
  1965. error_log = /opt/remi/${PHP_VERSION_2}/root/var/log/php-fpm/error.log
  1966. log_level = warning
  1967. emergency_restart_threshold = 10
  1968. emergency_restart_interval = 1m
  1969. process_control_timeout = 10s
  1970. daemonize = yes
  1971. EOphp_fpm_2_conf
  1972. if [[ -f "${www2_config_file}" ]]; then
  1973. mv "${www2_config_file}" "${www2_config_file}".orig
  1974. fi
  1975. cat >> "${www2_config_file}" << EOwww_2_conf
  1976. [www]
  1977. listen = /opt/remi/${PHP_VERSION_2}/root/var/run/php-fpm/php-fpm.sock;
  1978. listen.allowed_clients = 127.0.0.1
  1979. listen.owner = nginx
  1980. listen.group = nginx
  1981. listen.mode = 0660
  1982. user = nginx
  1983. group = nginx
  1984. pm = ondemand
  1985. pm.max_children = ${PM_MAX_CHILDREN}
  1986. pm.max_requests = ${PM_MAX_REQUEST}
  1987. pm.process_idle_timeout = 20
  1988. ;slowlog = /opt/remi/${PHP_VERSION_2}/root/var/log/php-fpm/www-slow.log
  1989. chdir = /
  1990. php_admin_value[error_log] = /opt/remi/${PHP_VERSION_2}/root/var/log/php-fpm/www-error.log
  1991. php_admin_flag[log_errors] = on
  1992. php_value[session.save_handler] = files
  1993. php_value[session.save_path] = /opt/remi/${PHP_VERSION_2}/root/var/lib/php/session
  1994. php_value[soap.wsdl_cache_dir] = /opt/remi/${PHP_VERSION_2}/root/var/lib/php/wsdlcache
  1995. php_admin_value[disable_functions] = exec,system,passthru,shell_exec,dl,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
  1996. ;php_admin_value[open_basedir] = ${DEFAULT_DIR_WEB}/:${DEFAULT_DIR_TOOL}/:/tmp/:/var/tmp/:/dev/urandom:/usr/share/php/:/dev/shm:/var/lib/php/sessions/
  1997. security.limit_extensions = .php
  1998. EOwww_2_conf
  1999. if [[ ! -d "/opt/remi/${PHP_VERSION_2}/root/var/lib/php/session" ]]; then
  2000. mkdir -p /opt/remi/"${PHP_VERSION_2}"/root/var/lib/php/session
  2001. fi
  2002. if [[ ! -d "/opt/remi/${PHP_VERSION_2}/root/var/lib/php/wsdlcache" ]]; then
  2003. mkdir -p /opt/remi/"${PHP_VERSION_2}"/root/var/lib/php/wsdlcache
  2004. fi
  2005. if [[ ! -d "/opt/remi/${PHP_VERSION_2}/root/var/log/php-fpm" ]]; then
  2006. mkdir -p /opt/remi/"${PHP_VERSION_2}"/root/var/log/php-fpm
  2007. fi
  2008. chown -R nginx:nginx /opt/remi/"${PHP_VERSION_2}"/root/var/lib/php/session
  2009. chown -R nginx:nginx /opt/remi/"${PHP_VERSION_2}"/root/var/lib/php/wsdlcache
  2010. chown -R nginx:nginx /opt/remi/"${PHP_VERSION_2}"/root/var/log/php-fpm
  2011. chmod 711 /opt/remi/"${PHP_VERSION_2}"/root/var/lib/php/session
  2012. chmod 711 /opt/remi/"${PHP_VERSION_2}"/root/var/lib/php/wsdlcache
  2013. }
  2014. # Custom PHP Ini
  2015. hostvn_custom_ini(){
  2016. cat > "/etc/php.d/00-hostvn-custom.ini" <<EOhostvn_custom_ini
  2017. date.timezone = Asia/Ho_Chi_Minh
  2018. max_execution_time = 300
  2019. max_input_time = 300
  2020. short_open_tag = On
  2021. realpath_cache_size = ${PHP_REAL_PATH_LIMIT}
  2022. realpath_cache_ttl = ${PHP_REAL_PATH_TTL}
  2023. memory_limit = ${MAX_MEMORY}M
  2024. upload_max_filesize = ${MAX_MEMORY}M
  2025. post_max_size = ${MAX_MEMORY}M
  2026. expose_php = Off
  2027. display_errors = Off
  2028. mail.add_x_header = Off
  2029. max_input_nesting_level = 128
  2030. max_input_vars = ${MAX_INPUT_VARS}
  2031. mysqlnd.net_cmd_buffer_size = 16384
  2032. mysqlnd.collect_memory_statistics = Off
  2033. mysqlnd.mempool_default_size = 16000
  2034. always_populate_raw_post_data=-1
  2035. EOhostvn_custom_ini
  2036. }
  2037. hostvn_custom_ini_2(){
  2038. cat > "${PHP2_INI_PATH}/00-hostvn-custom.ini" <<EOhostvn_custom_ini
  2039. date.timezone = Asia/Ho_Chi_Minh
  2040. max_execution_time = 300
  2041. max_input_time = 300
  2042. short_open_tag = On
  2043. realpath_cache_size = ${PHP_REAL_PATH_LIMIT}
  2044. realpath_cache_ttl = ${PHP_REAL_PATH_TTL}
  2045. memory_limit = ${MAX_MEMORY}M
  2046. upload_max_filesize = ${MAX_MEMORY}M
  2047. post_max_size = ${MAX_MEMORY}M
  2048. expose_php = Off
  2049. display_errors = Off
  2050. mail.add_x_header = Off
  2051. max_input_nesting_level = 128
  2052. max_input_vars = ${MAX_INPUT_VARS}
  2053. mysqlnd.net_cmd_buffer_size = 16384
  2054. mysqlnd.collect_memory_statistics = Off
  2055. mysqlnd.mempool_default_size = 16000
  2056. always_populate_raw_post_data=-1
  2057. EOhostvn_custom_ini
  2058. }
  2059. # Config PHP Opcache
  2060. php_opcache(){
  2061. if [[ -f "/etc/php.d/10-opcache.ini" ]]; then
  2062. mv /etc/php.d/10-opcache.ini /etc/php.d/10-opcache.ini.orig
  2063. fi
  2064. cat > "/etc/php.d/10-opcache.ini" << EOphp_opcache
  2065. zend_extension=opcache.so
  2066. opcache.enable=1
  2067. opcache.memory_consumption=${OPCACHE_MEM}
  2068. opcache.interned_strings_buffer=8
  2069. opcache.max_wasted_percentage=5
  2070. opcache.max_accelerated_files=65407
  2071. opcache.revalidate_freq=180
  2072. opcache.fast_shutdown=0
  2073. opcache.enable_cli=0
  2074. opcache.save_comments=1
  2075. opcache.enable_file_override=1
  2076. opcache.validate_timestamps=1
  2077. opcache.blacklist_filename=/etc/php.d/opcache-default.blacklist
  2078. EOphp_opcache
  2079. cat > "/etc/php.d/opcache-default.blacklist" << EOopcache_blacklist
  2080. /home/*/*/public_html/wp-content/plugins/backwpup/*
  2081. /home/*/*/public_html/wp-content/plugins/duplicator/*
  2082. /home/*/*/public_html/wp-content/plugins/updraftplus/*
  2083. /home/*/*/public_html/storage/*
  2084. EOopcache_blacklist
  2085. }
  2086. php_opcache_2(){
  2087. if [[ -f "${PHP2_INI_PATH}/10-opcache.ini" ]]; then
  2088. mv "${PHP2_INI_PATH}"/10-opcache.ini "${PHP2_INI_PATH}"/10-opcache.ini.orig
  2089. fi
  2090. cat > "${PHP2_INI_PATH}/10-opcache.ini" << EOphp_opcache
  2091. zend_extension=opcache.so
  2092. opcache.enable=1
  2093. opcache.memory_consumption=${OPCACHE_MEM}
  2094. opcache.interned_strings_buffer=8
  2095. opcache.max_wasted_percentage=5
  2096. opcache.max_accelerated_files=65407
  2097. opcache.revalidate_freq=180
  2098. opcache.fast_shutdown=0
  2099. opcache.enable_cli=0
  2100. opcache.save_comments=1
  2101. opcache.enable_file_override=1
  2102. opcache.validate_timestamps=1
  2103. opcache.blacklist_filename=${PHP2_INI_PATH}/opcache-default.blacklist
  2104. EOphp_opcache
  2105. cat > "${PHP2_INI_PATH}/opcache-default.blacklist" << EOopcache_blacklist
  2106. /home/*/*/public_html/wp-content/plugins/backwpup/*
  2107. /home/*/*/public_html/wp-content/plugins/duplicator/*
  2108. /home/*/*/public_html/wp-content/plugins/updraftplus/*
  2109. /home/*/*/public_html/storage/*
  2110. EOopcache_blacklist
  2111. }
  2112. ############################################
  2113. # Config MariaDB
  2114. ############################################
  2115. # MariaDB calculation
  2116. mariadb_calculation(){
  2117. if [[ ${RAM_TOTAL} -gt 400000 && ${RAM_TOTAL} -le 2099152 ]]; then #1GB Ram
  2118. max_allowed_packet="32M"
  2119. back_log="100"
  2120. max_connections="150"
  2121. key_buffer_size="32M"
  2122. myisam_sort_buffer_size="32M"
  2123. myisam_max_sort_file_size="2048M"
  2124. innodb_log_buffer_size="8M"
  2125. join_buffer_size="64K"
  2126. read_buffer_size="64K"
  2127. sort_buffer_size="128K"
  2128. table_definition_cache="4096"
  2129. table_open_cache="2048"
  2130. thread_cache_size="64"
  2131. tmp_table_size="32M"
  2132. max_heap_table_size="32M"
  2133. query_cache_limit="512K"
  2134. query_cache_size="16M"
  2135. innodb_open_files="2000"
  2136. innodb_buffer_pool_size="48M"
  2137. innodb_io_capacity="100"
  2138. aria_pagecache_buffer_size="8M"
  2139. aria_sort_buffer_size="8M"
  2140. net_buffer_length="8192"
  2141. read_rnd_buffer_size="256K"
  2142. innodb_log_file_size="128M"
  2143. innodb_read_io_threads="2"
  2144. aria_log_file_size="32M"
  2145. key_buffer="32M "
  2146. sort_buffer="16M"
  2147. read_buffer="16M"
  2148. write_buffer="16M"
  2149. fi
  2150. if [[ ${RAM_TOTAL} -gt 2099152 && ${RAM_TOTAL} -le 4198304 ]]; then #2GB Ram
  2151. max_allowed_packet="48M"
  2152. back_log="200"
  2153. max_connections="200"
  2154. key_buffer_size="32M"
  2155. myisam_sort_buffer_size="64M"
  2156. myisam_max_sort_file_size="2048M"
  2157. innodb_log_buffer_size="8M"
  2158. join_buffer_size="128K"
  2159. read_buffer_size="128K"
  2160. sort_buffer_size="256K"
  2161. table_definition_cache="8192"
  2162. table_open_cache="4096"
  2163. thread_cache_size="128"
  2164. tmp_table_size="128M"
  2165. max_heap_table_size="128M"
  2166. query_cache_limit="1024K"
  2167. query_cache_size="64M"
  2168. innodb_open_files="4000"
  2169. innodb_buffer_pool_size="192M"
  2170. innodb_io_capacity="200"
  2171. aria_pagecache_buffer_size="32M"
  2172. aria_sort_buffer_size="32M"
  2173. net_buffer_length="8192"
  2174. read_rnd_buffer_size="256K"
  2175. innodb_log_file_size="128M"
  2176. innodb_read_io_threads="2"
  2177. aria_log_file_size="32M"
  2178. key_buffer="32M "
  2179. sort_buffer="16M"
  2180. read_buffer="16M"
  2181. write_buffer="16M"
  2182. fi
  2183. if [[ ${RAM_TOTAL} -gt 4198304 && ${RAM_TOTAL} -le 8396608 ]]; then #4GB Ram
  2184. max_allowed_packet="64M"
  2185. back_log="200"
  2186. max_connections="350"
  2187. key_buffer_size="256M"
  2188. myisam_sort_buffer_size="256M"
  2189. myisam_max_sort_file_size="2048M"
  2190. innodb_log_buffer_size="8M"
  2191. join_buffer_size="256K"
  2192. read_buffer_size="256K"
  2193. sort_buffer_size="256K"
  2194. table_definition_cache="8192"
  2195. table_open_cache="4096"
  2196. thread_cache_size="256"
  2197. tmp_table_size="256M"
  2198. max_heap_table_size="256M"
  2199. query_cache_limit="1024K"
  2200. query_cache_size="80M"
  2201. innodb_open_files="4000"
  2202. innodb_buffer_pool_size="512M"
  2203. innodb_io_capacity="300"
  2204. aria_pagecache_buffer_size="64M"
  2205. aria_sort_buffer_size="64M"
  2206. net_buffer_length="16384"
  2207. read_rnd_buffer_size="512K"
  2208. innodb_log_file_size="256M"
  2209. innodb_read_io_threads="4"
  2210. aria_log_file_size="64M"
  2211. key_buffer="256M "
  2212. sort_buffer="32M"
  2213. read_buffer="32M"
  2214. write_buffer="32M"
  2215. fi
  2216. if [[ ${RAM_TOTAL} -gt 8396608 && ${RAM_TOTAL} -le 16793216 ]]; then #8GB Ram
  2217. max_allowed_packet="64M"
  2218. back_log="512"
  2219. max_connections="400"
  2220. key_buffer_size="384M"
  2221. myisam_sort_buffer_size="256M"
  2222. myisam_max_sort_file_size="2048M"
  2223. innodb_log_buffer_size="16M"
  2224. join_buffer_size="256K"
  2225. read_buffer_size="256K"
  2226. sort_buffer_size="512K"
  2227. table_definition_cache="8192"
  2228. table_open_cache="8192"
  2229. thread_cache_size="256"
  2230. tmp_table_size="512M"
  2231. max_heap_table_size="512M"
  2232. query_cache_limit="1024K"
  2233. query_cache_size="128M"
  2234. innodb_open_files="8000"
  2235. innodb_buffer_pool_size="1024M"
  2236. innodb_io_capacity="400"
  2237. aria_pagecache_buffer_size="64M"
  2238. aria_sort_buffer_size="64M"
  2239. net_buffer_length="16384"
  2240. read_rnd_buffer_size="512K"
  2241. innodb_log_file_size="384M"
  2242. innodb_read_io_threads="4"
  2243. aria_log_file_size="64M"
  2244. key_buffer="384M "
  2245. sort_buffer="64M"
  2246. read_buffer="64M"
  2247. write_buffer="64M"
  2248. fi
  2249. if [[ ${RAM_TOTAL} -gt 16793216 && ${RAM_TOTAL} -le 33586432 ]]; then #16GB Ram
  2250. max_allowed_packet="64M"
  2251. back_log="768"
  2252. max_connections="500"
  2253. key_buffer_size="512M"
  2254. myisam_sort_buffer_size="512M"
  2255. myisam_max_sort_file_size="4096M"
  2256. innodb_log_buffer_size="32M"
  2257. join_buffer_size="1M"
  2258. read_buffer_size="1M"
  2259. sort_buffer_size="2M"
  2260. table_definition_cache="10240"
  2261. table_open_cache="10240"
  2262. thread_cache_size="384"
  2263. tmp_table_size="768M"
  2264. max_heap_table_size="768M"
  2265. query_cache_limit="1024K"
  2266. query_cache_size="160M"
  2267. innodb_open_files="10000"
  2268. innodb_buffer_pool_size="4096M"
  2269. innodb_io_capacity="500"
  2270. aria_pagecache_buffer_size="128M"
  2271. aria_sort_buffer_size="128M"
  2272. net_buffer_length="16384"
  2273. read_rnd_buffer_size="512K"
  2274. innodb_log_file_size="640M"
  2275. innodb_read_io_threads="4"
  2276. aria_log_file_size="64M"
  2277. key_buffer="768M "
  2278. sort_buffer="128M"
  2279. read_buffer="128M"
  2280. write_buffer="128M"
  2281. fi
  2282. if [[ "$(expr "${RAM_TOTAL}" \>= 33586432)" = "1" ]]; then #32GB Ram
  2283. max_allowed_packet="64M"
  2284. back_log="1024"
  2285. max_connections="600"
  2286. key_buffer_size="768M"
  2287. myisam_sort_buffer_size="768M"
  2288. myisam_max_sort_file_size="8192M"
  2289. innodb_log_buffer_size="64M"
  2290. join_buffer_size="2M"
  2291. read_buffer_size="2M"
  2292. sort_buffer_size="2M"
  2293. table_definition_cache="10240"
  2294. table_open_cache="10240"
  2295. thread_cache_size="384"
  2296. tmp_table_size="1024M"
  2297. max_heap_table_size="1024M"
  2298. query_cache_limit="1536K"
  2299. query_cache_size="256M"
  2300. innodb_open_files="10000"
  2301. innodb_buffer_pool_size="8192M"
  2302. innodb_io_capacity="600"
  2303. aria_pagecache_buffer_size="128M"
  2304. aria_sort_buffer_size="128M"
  2305. net_buffer_length="16384"
  2306. read_rnd_buffer_size="512K"
  2307. innodb_log_file_size="768M"
  2308. innodb_read_io_threads="4"
  2309. aria_log_file_size="64M"
  2310. key_buffer="1024M "
  2311. sort_buffer="256M"
  2312. read_buffer="256M"
  2313. write_buffer="256M"
  2314. fi
  2315. if [[ "$(expr "${RAM_TOTAL}" \>= 64000000)" = "1" ]]; then #64GB Ram
  2316. max_allowed_packet="80M"
  2317. back_log="1024"
  2318. max_connections="800"
  2319. key_buffer_size="1024M"
  2320. myisam_sort_buffer_size="1024M"
  2321. myisam_max_sort_file_size="10240M"
  2322. innodb_log_buffer_size="64M"
  2323. join_buffer_size="2M"
  2324. read_buffer_size="2M"
  2325. sort_buffer_size="2M"
  2326. table_definition_cache="10240"
  2327. table_open_cache="10240"
  2328. thread_cache_size="384"
  2329. tmp_table_size="1536M"
  2330. max_heap_table_size="1536M"
  2331. query_cache_limit="1536K"
  2332. query_cache_size="256M"
  2333. innodb_open_files="10000"
  2334. innodb_buffer_pool_size="12288M"
  2335. innodb_io_capacity="800"
  2336. aria_pagecache_buffer_size="256M"
  2337. aria_sort_buffer_size="256M"
  2338. net_buffer_length="16384"
  2339. read_rnd_buffer_size="512K"
  2340. innodb_log_file_size="1024M"
  2341. innodb_read_io_threads="4"
  2342. aria_log_file_size="128M"
  2343. key_buffer="1536M "
  2344. sort_buffer="384M"
  2345. read_buffer="384M"
  2346. write_buffer="384M"
  2347. fi
  2348. }
  2349. config_my_cnf(){
  2350. mariadb_calculation
  2351. mkdir -p /var/log/mysql
  2352. mkdir -p /var/log/mysqld
  2353. chown -R mysql:mysql /var/log/mysql
  2354. chown -R mysql:mysql /var/log/mysqld
  2355. mv /etc/my.cnf /etc/my.cnf.orig
  2356. cat >> "/etc/my.cnf" << EOmy_cnf
  2357. [client]
  2358. socket=/var/lib/mysql/mysql.sock
  2359. [mysql]
  2360. max_allowed_packet = ${max_allowed_packet}
  2361. [mysqld]
  2362. local-infile=0
  2363. ignore-db-dir=lost+found
  2364. #character-set-server=utf8
  2365. datadir=/var/lib/mysql
  2366. socket=/var/lib/mysql/mysql.sock
  2367. #bind-address=127.0.0.1
  2368. tmpdir=/tmp
  2369. innodb=ON
  2370. #skip-federated
  2371. #skip-pbxt
  2372. #skip-pbxt_statistics
  2373. #skip-archive
  2374. #skip-name-resolve
  2375. #old_passwords
  2376. back_log = ${back_log}
  2377. max_connections = ${max_connections}
  2378. key_buffer_size = ${key_buffer_size}
  2379. myisam_sort_buffer_size = ${myisam_sort_buffer_size}
  2380. myisam_max_sort_file_size = ${myisam_max_sort_file_size}
  2381. join_buffer_size = ${join_buffer_size}
  2382. read_buffer_size = ${read_buffer_size}
  2383. sort_buffer_size = ${sort_buffer_size}
  2384. table_definition_cache = ${table_definition_cache}
  2385. table_open_cache = ${table_open_cache}
  2386. thread_cache_size = ${thread_cache_size}
  2387. wait_timeout = 1800
  2388. connect_timeout = 10
  2389. tmp_table_size = ${tmp_table_size}
  2390. max_heap_table_size = ${max_heap_table_size}
  2391. max_allowed_packet = ${max_allowed_packet}
  2392. #max_seeks_for_key = 4294967295
  2393. #group_concat_max_len = 1024
  2394. max_length_for_sort_data = 1024
  2395. net_buffer_length = ${net_buffer_length}
  2396. max_connect_errors = 100000
  2397. concurrent_insert = 2
  2398. read_rnd_buffer_size = ${read_rnd_buffer_size}
  2399. bulk_insert_buffer_size = 8M
  2400. # query_cache boost for MariaDB >10.1.2+
  2401. query_cache_limit = ${query_cache_limit}
  2402. query_cache_size = ${query_cache_size}
  2403. query_cache_type = 1
  2404. query_cache_min_res_unit = 2K
  2405. query_prealloc_size = 262144
  2406. query_alloc_block_size = 65536
  2407. transaction_alloc_block_size = 8192
  2408. transaction_prealloc_size = 4096
  2409. default-storage-engine = InnoDB
  2410. log_warnings=1
  2411. slow_query_log=0
  2412. long_query_time=1
  2413. slow_query_log_file=/var/lib/mysql/slowq.log
  2414. log-error=/var/log/mysql/mysqld.log
  2415. # innodb settings
  2416. #innodb_large_prefix=1
  2417. innodb_purge_threads=1
  2418. #innodb_file_format = Barracuda
  2419. innodb_file_per_table = 1
  2420. innodb_open_files = ${innodb_open_files}
  2421. innodb_data_file_path= ibdata1:10M:autoextend
  2422. innodb_buffer_pool_size = ${innodb_buffer_pool_size}
  2423. ## https://mariadb.com/kb/en/mariadb/xtradbinnodb-server-system-variables/#innodb_buffer_pool_instances
  2424. #innodb_buffer_pool_instances=2
  2425. #innodb_log_files_in_group = 2
  2426. innodb_log_file_size = ${innodb_log_file_size}
  2427. innodb_log_buffer_size = ${innodb_log_buffer_size}
  2428. innodb_flush_log_at_trx_commit = 2
  2429. innodb_thread_concurrency = 0
  2430. innodb_lock_wait_timeout=50
  2431. innodb_flush_method = O_DIRECT
  2432. #innodb_support_xa=1
  2433. # 200 * # DISKS
  2434. innodb_io_capacity = ${innodb_io_capacity}
  2435. innodb_io_capacity_max = 2000
  2436. innodb_read_io_threads = ${innodb_read_io_threads}
  2437. innodb_write_io_threads = 2
  2438. innodb_flush_neighbors = 1
  2439. # mariadb settings
  2440. [mariadb]
  2441. #thread-handling = pool-of-threads
  2442. #thread-pool-size= 20
  2443. #mysql --port=3307 --protocol=tcp
  2444. #extra-port=3307
  2445. #extra-max-connections=1
  2446. userstat = 0
  2447. key_cache_segments = 1
  2448. aria_group_commit = none
  2449. aria_group_commit_interval = 0
  2450. aria_log_file_size = ${aria_log_file_size}
  2451. aria_log_purge_type = immediate
  2452. aria_pagecache_buffer_size = ${aria_pagecache_buffer_size}
  2453. aria_sort_buffer_size = ${aria_sort_buffer_size}
  2454. [mariadb-5.5]
  2455. innodb_file_format = Barracuda
  2456. innodb_file_per_table = 1
  2457. #ignore_db_dirs=
  2458. query_cache_strip_comments=0
  2459. innodb_read_ahead = linear
  2460. innodb_adaptive_flushing_method = estimate
  2461. innodb_flush_neighbor_pages = 1
  2462. innodb_stats_update_need_lock = 0
  2463. innodb_log_block_size = 512
  2464. log_slow_filter =admin,filesort,filesort_on_disk,full_join,full_scan,query_cache,query_cache_miss,tmp_table,tmp_table_on_disk
  2465. [mysqld_safe]
  2466. socket=/var/lib/mysql/mysql.sock
  2467. log-error=/var/log/mysql/mysqld.log
  2468. #nice = -5
  2469. open-files-limit = 8192
  2470. [mysqldump]
  2471. quick
  2472. max_allowed_packet = ${max_allowed_packet}
  2473. [myisamchk]
  2474. tmpdir=/tmp
  2475. key_buffer = ${key_buffer}
  2476. sort_buffer = ${sort_buffer}
  2477. read_buffer = ${read_buffer}
  2478. write_buffer = ${write_buffer}
  2479. [mysqlhotcopy]
  2480. interactive-timeout
  2481. [mariadb-10.0]
  2482. innodb_file_format = Barracuda
  2483. innodb_file_per_table = 1
  2484. # 2 variables needed to switch from XtraDB to InnoDB plugins
  2485. #plugin-load=ha_innodb
  2486. #ignore_builtin_innodb
  2487. ## MariaDB 10 only save and restore buffer pool pages
  2488. ## warm up InnoDB buffer pool on server restarts
  2489. innodb_buffer_pool_dump_at_shutdown=1
  2490. innodb_buffer_pool_load_at_startup=1
  2491. innodb_buffer_pool_populate=0
  2492. ## Disabled settings
  2493. performance_schema=OFF
  2494. innodb_stats_on_metadata=OFF
  2495. innodb_sort_buffer_size=2M
  2496. innodb_online_alter_log_max_size=128M
  2497. query_cache_strip_comments=0
  2498. log_slow_filter =admin,filesort,filesort_on_disk,full_join,full_scan,query_cache,query_cache_miss,tmp_table,tmp_table_on_disk
  2499. EOmy_cnf
  2500. }
  2501. # Set MariaDB Root Password
  2502. set_mariadb_root_pwd(){
  2503. SQLPASS=$(generate_random_pwd)
  2504. cat > "/root/.my.cnf" <<EOmy_conf
  2505. [client]
  2506. user=root
  2507. password=${SQLPASS}
  2508. EOmy_conf
  2509. chmod 600 /root/.my.cnf
  2510. if [[ "${OS_VER}" -eq 8 ]]; then
  2511. /usr/bin/mysql_secure_installation << EOF
  2512. Y
  2513. ${SQLPASS}
  2514. ${SQLPASS}
  2515. Y
  2516. Y
  2517. Y
  2518. Y
  2519. EOF
  2520. else
  2521. /usr/bin/mysql_secure_installation << EOF
  2522. n
  2523. Y
  2524. ${SQLPASS}
  2525. ${SQLPASS}
  2526. Y
  2527. Y
  2528. Y
  2529. Y
  2530. EOF
  2531. fi
  2532. }
  2533. create_mysql_user(){
  2534. cat > "/tmp/mysql_query.temp" <<EOquery_temp
  2535. CREATE USER 'admin'@'localhost' IDENTIFIED BY '${SQLPASS}';
  2536. GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;
  2537. FLUSH PRIVILEGES;
  2538. EOquery_temp
  2539. mysql -uroot -p"${SQLPASS}" < /tmp/mysql_query.temp
  2540. rm -f /tmp/mysql_query.temp
  2541. }
  2542. ############################################
  2543. # Other Config
  2544. ############################################
  2545. limits_config(){
  2546. mv /etc/security/limits.conf /etc/security/limits.conf.orig
  2547. cat >> "/etc/security/limits.conf" <<EOlimits_config
  2548. * soft nofile 524288
  2549. * hard nofile 524288
  2550. nginx soft nofile 262144
  2551. nginx hard nofile 524288
  2552. nobody soft nofile 524288
  2553. nobody hard nofile 524288
  2554. root soft nofile 524288
  2555. root hard nofile 524288
  2556. EOlimits_config
  2557. ulimit -n 524288
  2558. if [ "${OS_VER}" = "7" ]; then
  2559. if [[ -f "/etc/security/limits.d/20-nproc.conf" ]]; then
  2560. mv /etc/security/limits.d/20-nproc.conf /etc/security/limits.d/20-nproc.conf.orig
  2561. cat > "/etc/security/limits.d/20-nproc.conf" <<EOnproc
  2562. # Default limit for number of user's processes to prevent
  2563. # accidental fork bombs.
  2564. # See rhbz #432903 for reasoning.
  2565. * soft nproc 8192
  2566. * hard nproc 8192
  2567. nginx soft nproc 32278
  2568. nginx hard nproc 32278
  2569. root soft nproc unlimited
  2570. EOnproc
  2571. fi
  2572. fi
  2573. }
  2574. sysctl_config(){
  2575. if [ "${OS_VER}" = "7" ]; then
  2576. if [ ! -f "/etc/sysctl.d/101-sysctl.conf" ]; then
  2577. touch /etc/sysctl.d/101-sysctl.conf
  2578. fi
  2579. echo "" > /etc/sysctl.d/101-sysctl.conf
  2580. cat >> "/etc/sysctl.d/101-sysctl.conf" <<EO101_sysctl
  2581. kernel.printk=4 1 1 7
  2582. fs.nr_open=12000000
  2583. fs.file-max=9000000
  2584. net.core.wmem_max=16777216
  2585. net.core.rmem_max=16777216
  2586. net.ipv4.tcp_rmem=8192 87380 16777216
  2587. net.ipv4.tcp_wmem=8192 65536 16777216
  2588. net.core.netdev_max_backlog=65536
  2589. net.core.somaxconn=65535
  2590. net.core.optmem_max=8192
  2591. net.ipv4.tcp_fin_timeout=10
  2592. net.ipv4.tcp_keepalive_intvl=30
  2593. net.ipv4.tcp_keepalive_probes=3
  2594. net.ipv4.tcp_keepalive_time=240
  2595. net.ipv4.tcp_max_syn_backlog=65536
  2596. net.ipv4.tcp_sack=1
  2597. net.ipv4.tcp_syn_retries=3
  2598. net.ipv4.tcp_synack_retries = 2
  2599. net.ipv4.tcp_tw_recycle = 0
  2600. net.ipv4.tcp_tw_reuse = 0
  2601. net.ipv4.tcp_max_tw_buckets = 1440000
  2602. vm.swappiness=10
  2603. vm.min_free_kbytes=65536
  2604. net.ipv4.ip_local_port_range=1024 65535
  2605. net.ipv4.tcp_slow_start_after_idle=0
  2606. net.ipv4.tcp_limit_output_bytes=65536
  2607. net.ipv4.tcp_rfc1337=1
  2608. net.ipv4.conf.all.accept_redirects = 0
  2609. net.ipv4.conf.all.accept_source_route = 0
  2610. net.ipv4.conf.all.log_martians = 1
  2611. net.ipv4.conf.all.rp_filter = 1
  2612. net.ipv4.conf.all.secure_redirects = 0
  2613. net.ipv4.conf.all.send_redirects = 0
  2614. net.ipv4.conf.default.accept_redirects = 0
  2615. net.ipv4.conf.default.accept_source_route = 0
  2616. net.ipv4.conf.default.log_martians = 1
  2617. net.ipv4.conf.default.rp_filter = 1
  2618. net.ipv4.conf.default.secure_redirects = 0
  2619. net.ipv4.conf.default.send_redirects = 0
  2620. net.ipv4.icmp_echo_ignore_broadcasts = 1
  2621. net.ipv4.icmp_ignore_bogus_error_responses = 1
  2622. net.netfilter.nf_conntrack_helper=0
  2623. net.nf_conntrack_max = 524288
  2624. net.netfilter.nf_conntrack_tcp_timeout_established = 28800
  2625. net.netfilter.nf_conntrack_generic_timeout = 60
  2626. net.ipv4.tcp_challenge_ack_limit = 999999999
  2627. net.ipv4.tcp_mtu_probing = 1
  2628. net.ipv4.tcp_base_mss = 1024
  2629. net.unix.max_dgram_qlen = 4096
  2630. EO101_sysctl
  2631. if [[ "$(grep -o 'AMD EPYC' /proc/cpuinfo | sort -u)" = 'AMD EPYC' ]]; then
  2632. echo "kernel.watchdog_thresh = 20" >> /etc/sysctl.d/101-sysctl.conf
  2633. fi
  2634. /sbin/sysctl --system
  2635. sed -i 's/vm.swappiness/#vm.swappiness/g' /usr/lib/tuned/virtual-guest/tuned.conf
  2636. echo "vm.swappiness = 10" >> /usr/lib/tuned/virtual-guest/tuned.conf
  2637. fi
  2638. }
  2639. ############################################
  2640. # Log Rotation
  2641. ############################################
  2642. log_rotation(){
  2643. cat > "/etc/logrotate.d/nginx" << EOnginx_log
  2644. /home/*/logs/access.log /home/*/logs/error.log /home/*/logs/nginx_error.log {
  2645. create 640 nginx nginx
  2646. daily
  2647. dateext
  2648. missingok
  2649. rotate 5
  2650. maxage 7
  2651. compress
  2652. size=100M
  2653. notifempty
  2654. sharedscripts
  2655. postrotate
  2656. [ -f /var/run/nginx.pid ] && kill -USR1 \`cat /var/run/nginx.pid\`
  2657. endscript
  2658. su nginx nginx
  2659. }
  2660. EOnginx_log
  2661. cat > "/etc/logrotate.d/php-fpm" << EOphp_fpm_log
  2662. /home/*/logs/php-fpm*.log {
  2663. daily
  2664. dateext
  2665. compress
  2666. maxage 7
  2667. missingok
  2668. notifempty
  2669. sharedscripts
  2670. size=100M
  2671. postrotate
  2672. /bin/kill -SIGUSR1 \`cat /var/run/php-fpm/php-fpm.pid 2>/dev/null\` 2>/dev/null || true
  2673. endscript
  2674. su nginx nginx
  2675. }
  2676. EOphp_fpm_log
  2677. cat > "/etc/logrotate.d/mysql" << EOmysql_log
  2678. /home/*/logs/mysql*.log {
  2679. create 640 mysql mysql
  2680. notifempty
  2681. daily
  2682. rotate 3
  2683. maxage 7
  2684. missingok
  2685. compress
  2686. postrotate
  2687. # just if mysqld is really running
  2688. if test -x /usr/bin/mysqladmin && \
  2689. /usr/bin/mysqladmin ping &>/dev/null
  2690. then
  2691. /usr/bin/mysqladmin flush-logs
  2692. fi
  2693. endscript
  2694. su mysql mysql
  2695. }
  2696. EOmysql_log
  2697. }
  2698. ############################################
  2699. # Install phpMyAdmin
  2700. ############################################
  2701. #Config phpMyAdmin
  2702. config_phpmyadmin(){
  2703. BLOWFISH_SECRET=$(< /dev/urandom tr -dc A-Za-z0-9 | head -c100)
  2704. rm -rf "${DEFAULT_DIR_TOOL}"/phpmyadmin/setup
  2705. mkdir -p "${DEFAULT_DIR_TOOL}"/phpmyadmin/tmp
  2706. if [[ "${PHP_VERSION}" != "php56" ]]; then
  2707. DECLARE="declare(strict_types=1);"
  2708. fi
  2709. cat > "${DEFAULT_DIR_TOOL}/phpmyadmin/config.inc.php" <<EOCONFIGINC
  2710. <?php
  2711. ${DECLARE}
  2712. \$cfg['blowfish_secret'] = '${BLOWFISH_SECRET}';
  2713. \$i = 0;
  2714. \$i++;
  2715. \$cfg['Servers'][\$i]['auth_type'] = 'cookie';
  2716. \$cfg['Servers'][\$i]['host'] = 'localhost';
  2717. \$cfg['Servers'][\$i]['connect_type'] = 'tcp';
  2718. \$cfg['Servers'][\$i]['compress'] = false;
  2719. \$cfg['Servers'][\$i]['AllowNoPassword'] = false;
  2720. \$cfg['UploadDir'] = '';
  2721. \$cfg['SaveDir'] = '';
  2722. \$cfg['PmaNoRelation_DisableWarning'] = true;
  2723. \$cfg['VersionCheck'] = false;
  2724. \$cfg['TempDir'] = '${DEFAULT_DIR_TOOL}/phpmyadmin/tmp';
  2725. \$cfg['CaptchaLoginPublicKey'] = '';
  2726. \$cfg['CaptchaLoginPrivateKey'] = '';
  2727. \$cfg['ExecTimeLimit'] = 600;
  2728. EOCONFIGINC
  2729. chown -R nginx:nginx "${DEFAULT_DIR_TOOL}"/phpmyadmin
  2730. chown -R nginx:nginx "${DEFAULT_DIR_TOOL}"/phpmyadmin
  2731. }
  2732. create_phpmyadmin_db(){
  2733. cat > "/tmp/phpmyadmin.temp" << EOphpmyadmin_temp
  2734. CREATE DATABASE phpmyadmin COLLATE utf8_general_ci;
  2735. FLUSH PRIVILEGES;
  2736. EOphpmyadmin_temp
  2737. mysql -u root -p"${SQLPASS}" < /tmp/phpmyadmin.temp
  2738. rm -f /tmp/phpmyadmin.temp
  2739. curl -o phpmyadmin.sql "${EXT_LINK}"/phpmyadmin.sql
  2740. mysql -u root -p"${SQLPASS}" phpmyadmin < phpmyadmin.sql
  2741. rm -rf phpmyadmin.sql
  2742. }
  2743. install_phpmyadmin(){
  2744. # Singapore Local
  2745. #echo "89.187.162.49 files.phpmyadmin.net" >> /etc/hosts
  2746. if [[ "${PHP_VERSION}" == "php56" ]]; then
  2747. PHPMYADMIN_VERSION="4.9.5"
  2748. fi
  2749. cd_dir "${DEFAULT_DIR_TOOL}"
  2750. wget "${PMA_LINK}"/"${PHPMYADMIN_VERSION}"/phpMyAdmin-"${PHPMYADMIN_VERSION}"-english.zip
  2751. unzip phpMyAdmin-"${PHPMYADMIN_VERSION}"-english.zip
  2752. rm -rf "${DEFAULT_DIR_TOOL}"/phpMyAdmin-"${PHPMYADMIN_VERSION}"-english.zip
  2753. mv phpMyAdmin-"${PHPMYADMIN_VERSION}"-english phpmyadmin
  2754. rm -rf "${DEFAULT_DIR_TOOL}"/phpmyadmin/setup
  2755. config_phpmyadmin
  2756. cd_dir "${DIR}"
  2757. chown -R nginx:nginx /usr/share/nginx/html "${DEFAULT_DIR_TOOL}"/phpmyadmin
  2758. create_phpmyadmin_db
  2759. }
  2760. ############################################
  2761. # Install PureFTP
  2762. ############################################
  2763. install_pure_ftpd(){
  2764. yum -y install pure-ftpd
  2765. PURE_CONF_PATH="/etc/pure-ftpd"
  2766. if [[ -f "${PURE_CONF_PATH}/pure-ftpd.conf" ]]; then
  2767. mv "${PURE_CONF_PATH}"/pure-ftpd.conf "${PURE_CONF_PATH}"/pure-ftpd.conf.orig
  2768. fi
  2769. cat >> "${PURE_CONF_PATH}/pure-ftpd.conf" << EOpure_ftpd_conf
  2770. ############################################################
  2771. # #
  2772. # Configuration file for pure-ftpd #
  2773. # #
  2774. ############################################################
  2775. ChrootEveryone yes
  2776. BrokenClientsCompatibility no
  2777. MaxClientsNumber 50
  2778. Daemonize yes
  2779. MaxClientsPerIP 15
  2780. VerboseLog no
  2781. DisplayDotFiles yes
  2782. AnonymousOnly no
  2783. NoAnonymous yes
  2784. SyslogFacility ftp
  2785. DontResolve yes
  2786. MaxIdleTime 15
  2787. PureDB /etc/pure-ftpd/pureftpd.pdb
  2788. LimitRecursion 10000 8
  2789. AnonymousCanCreateDirs no
  2790. MaxLoad 4
  2791. PassivePortRange 35000 35999
  2792. AntiWarez yes
  2793. #Bind ${IPADDRESS},21
  2794. Umask 133:022
  2795. MinUID 99
  2796. AllowUserFXP yes
  2797. AllowAnonymousFXP no
  2798. ProhibitDotFilesWrite no
  2799. ProhibitDotFilesRead no
  2800. AutoRename no
  2801. AnonymousCantUpload no
  2802. AltLog stats:/var/log/pureftpd.log
  2803. PIDFile /run/pure-ftpd.pid
  2804. CallUploadScript no
  2805. MaxDiskUsage 99
  2806. CustomerProof yes
  2807. TLS 1
  2808. TLSCipherSuite HIGH:MEDIUM:+TLSv1:!SSLv2:+SSLv3
  2809. CertFile /etc/pure-ftpd/ssl/pure-ftpd.pem
  2810. ExtCert /var/run/pure-certd.sock
  2811. EOpure_ftpd_conf
  2812. mkdir -p "${PURE_CONF_PATH}"/ssl
  2813. openssl dhparam -out "${PURE_CONF_PATH}"/ssl/pure-ftpd-dhparams.pem 2048
  2814. openssl req -x509 -days 7300 -sha256 -nodes -subj "/C=VN/ST=Ho_Chi_Minh/L=Ho_Chi_Minh/O=Localhost/CN=${IPADDRESS}" -newkey rsa:2048 -keyout "${PURE_CONF_PATH}"/ssl/pure-ftpd.pem -out "${PURE_CONF_PATH}"/ssl/pure-ftpd.pem
  2815. chmod 600 "${PURE_CONF_PATH}"/ssl/pure-ftpd*.pem
  2816. touch /etc/pure-ftpd/pureftpd.passwd
  2817. systemctl start pure-ftpd
  2818. systemctl enable pure-ftpd
  2819. }
  2820. ############################################
  2821. # Change SSH Port
  2822. ############################################
  2823. change_ssh_port() {
  2824. sed -i "s/#Port 22/Port ${SSH_PORT}/g" /etc/ssh/sshd_config
  2825. semanage port -a -t ssh_port_t -p tcp "${SSH_PORT}"
  2826. }
  2827. ############################################
  2828. # Install ACME
  2829. ############################################
  2830. install_acme() {
  2831. curl https://get.acme.sh | sh
  2832. }
  2833. ############################################
  2834. # Generate htpasswd
  2835. ############################################
  2836. gen_htpasswd(){
  2837. htpasswd -b -c "${USR_DIR}"/nginx/auth/.htpasswd admin "${ADMIN_TOOL_PWD}"
  2838. }
  2839. ############################################
  2840. # Opcache Dashboard
  2841. ############################################
  2842. opcache_dashboard(){
  2843. mkdir -p "${DEFAULT_DIR_TOOL}"/opcache
  2844. wget -q "${GITHUB_RAW_LINK}"/amnuts/opcache-gui/master/index.php -O "${DEFAULT_DIR_TOOL}"/opcache/index.php
  2845. chown -R nginx:nginx "${DEFAULT_DIR_TOOL}"/opcache
  2846. chown -R nginx:nginx "${USR_DIR}"/nginx/auth
  2847. }
  2848. ############################################
  2849. # phpSysInfo
  2850. ############################################
  2851. php_sys_info(){
  2852. cd_dir "${DEFAULT_DIR_TOOL}"
  2853. wget -q "${GITHUB_URL}"/phpsysinfo/phpsysinfo/archive/v"${PHP_SYS_INFO_VERSION}".zip
  2854. unzip -q v"${PHP_SYS_INFO_VERSION}".zip && rm -f v"${PHP_SYS_INFO_VERSION}".zip
  2855. mv phpsysinfo-"${PHP_SYS_INFO_VERSION}" serverinfo
  2856. cd serverinfo && mv phpsysinfo.ini.new phpsysinfo.ini
  2857. cd_dir "${DIR}"
  2858. chown -R nginx:nginx "${DEFAULT_DIR_TOOL}"
  2859. }
  2860. ############################################
  2861. # phpmemcachedadmin
  2862. ############################################
  2863. phpmemcachedadmin(){
  2864. cd_dir "${DEFAULT_DIR_TOOL}"
  2865. git clone https://github.com/elijaa/phpmemcachedadmin.git
  2866. rm -rf "${DEFAULT_DIR_TOOL}"/phpmemcachedadmin/docker
  2867. mv phpmemcachedadmin memcached
  2868. chown -R nginx:nginx "${DEFAULT_DIR_TOOL}"/memcached
  2869. cd_dir "${DIR}"
  2870. }
  2871. ############################################
  2872. # Redis Admin Gui
  2873. ############################################
  2874. redisdadmin(){
  2875. cd_dir "${DEFAULT_DIR_TOOL}"
  2876. git clone https://github.com/ErikDubbelboer/phpRedisAdmin.git
  2877. mv phpRedisAdmin redis
  2878. cd_dir "${DEFAULT_DIR_TOOL}"/redis
  2879. git clone https://github.com/nrk/predis.git vendor
  2880. cd .. && chown -R nginx:nginx redis
  2881. cd_dir "${DIR}"
  2882. }
  2883. ############################################
  2884. # Rclone
  2885. ############################################
  2886. install_rclone(){
  2887. curl https://rclone.org/install.sh | sudo bash
  2888. }
  2889. install_admin_tool(){
  2890. gen_htpasswd
  2891. opcache_dashboard
  2892. php_sys_info
  2893. if [[ "${prompt_memcached}" =~ ^([yY])$ ]]; then
  2894. phpmemcachedadmin
  2895. fi
  2896. if [[ "${prompt_redis}" =~ ^([yY])$ ]]; then
  2897. redisdadmin
  2898. fi
  2899. install_rclone
  2900. }
  2901. ############################################
  2902. # Install CSF Firewall
  2903. ############################################
  2904. csf_gui(){
  2905. sed -i 's/UI = "0"/UI = "1"/g' /etc/csf/csf.conf
  2906. sed -i "s/UI_PORT = \"6666\"/UI_PORT = \"${CSF_UI_PORT}\"/g" /etc/csf/csf.conf
  2907. sed -i 's/UI_USER = "username"/UI_USER = "admin"/g' /etc/csf/csf.conf
  2908. sed -i "s/UI_PASS = \"password\"/UI_PASS = \"${ADMIN_TOOL_PWD}\"/g" /etc/csf/csf.conf
  2909. }
  2910. install_csf(){
  2911. yum -y install perl-Perl4-CoreLibs perl-LWP-Protocol-https perl-libwww-perl perl-GDGraph perl-IO-Socket-SSL.noarch perl-Net-SSLeay perl-Net-LibIDN perl-IO-Socket-INET6 perl-Socket6 libpng-devel
  2912. curl -o "${DIR}"/csf.tgz https://download.configserver.com/csf.tgz
  2913. tar -xf csf.tgz
  2914. cd_dir "${DIR}/csf"
  2915. sh install.sh
  2916. cd_dir "${DIR}"
  2917. rm -rf csf*
  2918. if [[ "${prompt_ssh}" =~ ^([yY])$ ]]; then
  2919. sed -i "s/21,22/21,22,${SSH_PORT}/g" /etc/csf/csf.conf
  2920. sed -i "s/PORTS_sshd = \"22\"/PORTS_sshd = \"22,${SSH_PORT}\"/g" /etc/csf/csf.conf
  2921. fi
  2922. sed -i "s/993,995/993,995,9200,9300,30000:50000/g" /etc/csf/csf.conf
  2923. sed -i "s/443,465/443,${RANDOM_ADMIN_PORT},465/g" /etc/csf/csf.conf
  2924. sed -i "s/443,587/443,465,587,${RANDOM_ADMIN_PORT}/g" /etc/csf/csf.conf
  2925. sed -i 's/TESTING = "1"/TESTING = "0"/g' /etc/csf/csf.conf
  2926. sed -i 's/RESTRICT_SYSLOG = "0"/RESTRICT_SYSLOG = "2"/g' /etc/csf/csf.conf
  2927. sed -i 's/CT_LIMIT = "0"/CT_LIMIT = "600"/g' /etc/csf/csf.conf
  2928. sed -i 's/ICMP_IN = "0"/ICMP_IN = "1"/; s/ICMP_IN_RATE = "1/ICMP_IN_RATE = "5/' /etc/csf/csf.conf
  2929. sed -i 's/PORTFLOOD = ""/PORTFLOOD = "21;tcp;20;300"/g' /etc/csf/csf.conf
  2930. echo '#!/bin/sh' > /usr/sbin/sendmail
  2931. chmod +x /usr/sbin/sendmail
  2932. cat >> "/etc/csf/csf.pignore" << EOCSF
  2933. exe:/usr/sbin/nginx
  2934. exe:/usr/sbin/php-fpm
  2935. exe:/usr/sbin/rpcbind
  2936. exe:/usr/share/elasticsearch/bin/elasticsearch
  2937. exe:/usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller
  2938. cmd:/usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller
  2939. exe:/usr/share/elasticsearch/bin/systemd-entrypoint
  2940. exe:/usr/bin/pkttyagent
  2941. exe:/usr/share/elasticsearch/jdk/bin/java
  2942. exe:/usr/bin/redis-server
  2943. cmd:/usr/bin/redis-server 127.0.0.1:6379
  2944. exe:/usr/bin/rsync
  2945. exe:/usr/bin/memcached
  2946. EOCSF
  2947. {
  2948. echo ""
  2949. echo "216.239.32.0/19 # Googlebot"
  2950. echo "64.233.160.0/19 # Googlebot"
  2951. echo "72.14.192.0/18 # Googlebot"
  2952. echo "209.85.128.0/17 # Googlebot"
  2953. echo "66.102.0.0/20 # Googlebot"
  2954. echo "74.125.0.0/16 # Googlebot"
  2955. echo "66.249.64.0/19 #Googlebot"
  2956. } >> /etc/csf/csf.allow
  2957. {
  2958. echo ""
  2959. echo ".googlebot.com"
  2960. echo ".crawl.yahoo.net"
  2961. echo ".search.msn.com"
  2962. echo ".google.com"
  2963. } >> /etc/csf/csf.rignore
  2964. csf_gui
  2965. }
  2966. ############################################
  2967. # Cronjob Update Cloudflare IP Range
  2968. ############################################
  2969. cf_ip(){
  2970. crontab -l > cloudflare
  2971. echo "23 */36 * * * /var/hostvn/menu/cronjob/csfcf.sh >/dev/null 2>&1" >> cloudflare
  2972. crontab cloudflare
  2973. rm -rf cloudflare
  2974. }
  2975. ############################################
  2976. # Install ClamAV
  2977. ############################################
  2978. install_clamav(){
  2979. if [ "${OS_VER}" -eq 8 ]; then
  2980. dnf install clamav-server clamav-update clamav-filesystem clamav clamav-scanner-systemd clamav-devel clamav-lib clamav-server-systemd -y
  2981. else
  2982. yum -y install clamav-server clamav-update clamav-filesystem clamav clamav-scanner-systemd clamav-devel clamav-lib clamav-server-systemd
  2983. fi
  2984. setsebool -P antivirus_can_scan_system 1
  2985. setsebool -P clamd_use_jit 1
  2986. sed -i -e "s/^Example/#Example/" /etc/clamd.d/scan.conf
  2987. sed -i -e "s/#LocalSocket /LocalSocket /" /etc/clamd.d/scan.conf
  2988. sed -i -e "s/^Example/#Example/" /etc/freshclam.conf
  2989. {
  2990. echo "DatabaseCustomURL http://cdn.malware.expert/malware.expert.ndb"
  2991. echo "DatabaseCustomURL http://cdn.malware.expert/malware.expert.hdb"
  2992. echo "DatabaseCustomURL http://cdn.malware.expert/malware.expert.ldb"
  2993. echo "DatabaseCustomURL http://cdn.malware.expert/malware.expert.fp"
  2994. } >> /etc/freshclam.conf
  2995. }
  2996. install_av(){
  2997. install_clamav
  2998. }
  2999. ######################################
  3000. # Finished
  3001. ############################################
  3002. check_service_status(){
  3003. NGINX_STATUS="$(pgrep -f nginx)"
  3004. if [[ -z "${NGINX_STATUS}" ]]; then
  3005. echo "${NGINX_NOT_WORKING}" >> "${LOG}"
  3006. fi
  3007. MARIADB_STATUS="$(pgrep -f mariadb)"
  3008. if [[ -z "${MARIADB_STATUS}" ]]; then
  3009. echo "${MARIADB_NOT_WORKING}" >> "${LOG}"
  3010. fi
  3011. PURE_STATUS="$(pgrep -f pure-ftpd)"
  3012. if [[ -z "${PURE_STATUS}" ]]; then
  3013. echo "${PUREFTP_NOT_WORKING}" >> "${LOG}"
  3014. fi
  3015. PHP_STATUS="$(pgrep -f php-fpm)"
  3016. if [[ -z "${PHP_STATUS}" ]]; then
  3017. echo "${PHP_NOT_WORKING}" >> "${LOG}"
  3018. fi
  3019. LFD_STATUS="$(pgrep -f lfd)"
  3020. if [[ -z "${LFD_STATUS}" ]]; then
  3021. echo "${LFD_NOT_WORKING}" >> "${LOG}"
  3022. fi
  3023. }
  3024. start_service() {
  3025. systemctl enable nginx
  3026. systemctl enable mariadb
  3027. systemctl enable php-fpm
  3028. systemctl start php-fpm
  3029. csf -e
  3030. systemctl start lfd
  3031. systemctl enable lfd
  3032. systemctl enable csf
  3033. if [[ "${MULTI_PHP}" =~ ^(Y|y)$ ]]; then
  3034. systemctl enable "${PHP_VERSION_2}"-php-fpm
  3035. systemctl start "${PHP_VERSION_2}"-php-fpm
  3036. fi
  3037. cd_dir /etc/nginx/rocket-nginx
  3038. php rocket-parser.php
  3039. check_service_status
  3040. setsebool -P httpd_execmem 1
  3041. }
  3042. install_wpcli_packages(){
  3043. sed -i '/memory_limit/d' /etc/php.d/00-hostvn-custom.ini
  3044. echo "memory_limit = -1" >> /etc/php.d/00-hostvn-custom.ini
  3045. systemctl php-fpm restart
  3046. wp package install iandunn/wp-cli-rename-db-prefix
  3047. wp package install markri/wp-sec
  3048. sed -i '/memory_limit/d' /etc/php.d/00-hostvn-custom.ini
  3049. echo "memory_limit = ${MAX_MEMORY}M" >> /etc/php.d/00-hostvn-custom.ini
  3050. systemctl php-fpm restart
  3051. }
  3052. ############################################
  3053. # Create menu
  3054. ############################################
  3055. add_menu(){
  3056. cd_dir "${BASH_DIR}"
  3057. wget "${EXT_LINK}"/menu.tar.gz > /dev/null
  3058. tar -xvf menu.tar.gz && rm -rf menu.tar.gz > /dev/null
  3059. mkdir -p "${BASH_DIR}"/users
  3060. mkdir -p /var/log/hostvn
  3061. mkdir -p /var/hostvn/wpcron
  3062. chmod 711 menu users wpcron
  3063. chmod +x ./menu/* ./menu/*/* ./menu/*/*/* ./menu/*/*/*/* > /dev/null
  3064. dos2unix ./menu/* > /dev/null
  3065. dos2unix ./menu/*/* > /dev/null
  3066. dos2unix ./menu/*/*/* > /dev/null
  3067. mv "${BASH_DIR}"/menu/hostvn /usr/bin/hostvn && chmod +x /usr/bin/hostvn
  3068. sed -i "s/IPADDRESS/#IPADDRESS/g" "${BASH_DIR}"/menu/helpers/variable_common
  3069. {
  3070. echo ""
  3071. echo "IPADDRESS=${IPADDRESS}"
  3072. } >> "${BASH_DIR}"/menu/helpers/variable_common
  3073. if [[ ! -f "/var/hostvn/ipaddress" ]]; then
  3074. cat >> "/var/hostvn/ipaddress" << END
  3075. #!/bin/bash
  3076. IPADDRESS=${IPADDRESS}
  3077. END
  3078. fi
  3079. }
  3080. ############################################
  3081. # Write Info
  3082. ############################################
  3083. write_info(){
  3084. touch "${FILE_INFO}"
  3085. {
  3086. echo "script_version=${SCRIPTS_VERSION}"
  3087. echo "ssh_port=${SSH_PORT}"
  3088. echo "admin_port=${RANDOM_ADMIN_PORT}"
  3089. echo "csf_port=${CSF_UI_PORT}"
  3090. echo "ftp_port=21"
  3091. echo "admin_pwd=${ADMIN_TOOL_PWD}"
  3092. echo "mysql_pwd=${SQLPASS}"
  3093. echo "admin_email=${ADMIN_EMAIL}"
  3094. echo "php1_release=yes"
  3095. echo "php2_release=${PHP2_RELEASE}"
  3096. echo "php1_version=${PHP_VERSION}"
  3097. echo "php2_version=${PHP_VERSION_2}"
  3098. echo "lang=vi"
  3099. } >> "${FILE_INFO}"
  3100. touch /etc/hostvn.lock
  3101. chmod 600 "${FILE_INFO}" /etc/hostvn.lock
  3102. }
  3103. ############################################
  3104. # Run Script
  3105. ############################################
  3106. # Prepare before install
  3107. create_bash_dir
  3108. config_selinux
  3109. set_timezone
  3110. set_os_arch
  3111. create_log
  3112. set_email
  3113. # Select options
  3114. input_ip
  3115. select_php_ver
  3116. select_php_multi
  3117. if [[ "${MULTI_PHP}" =~ ^(Y|y)$ ]]; then
  3118. select_php_ver_2
  3119. check_duplicate_php
  3120. fi
  3121. option_clamav
  3122. option_memcached
  3123. option_redis
  3124. option_pureftp
  3125. option_change_ssh_port
  3126. # Install
  3127. install_nginx
  3128. if [[ ! -f "/usr/lib/systemd/system/nginx.service" ]]; then
  3129. clear
  3130. printf "%s\n" "${INST_NGINX_ERR}"
  3131. sleep 3
  3132. exit
  3133. fi
  3134. nginx_brotli
  3135. install_naxsi
  3136. install_mariadb
  3137. if [[ ! -f "/usr/lib/systemd/system/mariadb.service" ]]; then
  3138. clear
  3139. printf "%s\n" "${INST_MARIADB_ERR}"
  3140. sleep 3
  3141. exit
  3142. fi
  3143. install_php
  3144. if [[ "${MULTI_PHP}" =~ ^(Y|y)$ ]]; then
  3145. install_php_2
  3146. if [[ ! -f "/usr/lib/systemd/system/${PHP_VERSION_2}-php-fpm.service" ]]; then
  3147. clear
  3148. PHP2_RELEASE="no"
  3149. printf "%s\n" "${INST_PHP_ERR_2}"
  3150. sleep 3
  3151. fi
  3152. fi
  3153. if [[ ! -f "/usr/lib/systemd/system/php-fpm.service" ]]; then
  3154. clear
  3155. printf "%s\n" "${INST_PHP_ERR}"
  3156. sleep 3
  3157. exit
  3158. fi
  3159. if [[ ! -f "/usr/lib/systemd/system/php-fpm.service" ]]; then
  3160. clear
  3161. printf "%s\n" "${INST_PHP_ERR}"
  3162. sleep 3
  3163. exit
  3164. fi
  3165. install_composer
  3166. install_wpcli
  3167. memory_calculation
  3168. if [[ "${prompt_memcached}" =~ ^([yY])$ ]]; then
  3169. install_memcached
  3170. fi
  3171. if [[ "${prompt_redis}" =~ ^([yY])$ ]]; then
  3172. install_redis
  3173. fi
  3174. install_igbinary
  3175. if [[ "${MULTI_PHP}" =~ ^(Y|y)$ ]]; then
  3176. install_igbinary_2
  3177. fi
  3178. if [[ -f "${PHP_MODULES_DIR}/igbinary.so" ]]; then
  3179. install_php_memcached
  3180. install_php_redis
  3181. fi
  3182. if [[ -f "${PHP_MODULES_DIR_2}/igbinary.so" ]]; then
  3183. install_php_memcached_2
  3184. install_php_redis_2
  3185. fi
  3186. # Config
  3187. self_signed_ssl
  3188. cal_ssl_cache_size
  3189. create_nginx_conf
  3190. create_extra_conf
  3191. create_wp_cache_conf
  3192. vhost_custom
  3193. default_vhost
  3194. default_index
  3195. default_error_page
  3196. wprocket_nginx
  3197. php_global_config
  3198. hostvn_custom_ini
  3199. php_opcache
  3200. if [[ "${MULTI_PHP}" =~ ^(Y|y)$ ]]; then
  3201. php_global_config_2
  3202. hostvn_custom_ini_2
  3203. php_opcache_2
  3204. fi
  3205. config_my_cnf
  3206. set_mariadb_root_pwd
  3207. create_mysql_user
  3208. limits_config
  3209. sysctl_config
  3210. log_rotation
  3211. # Install other tool
  3212. install_phpmyadmin
  3213. if [[ "${prompt_pureftpd}" =~ ^([yY])$ ]]; then
  3214. install_pure_ftpd
  3215. fi
  3216. install_acme
  3217. install_csf
  3218. install_admin_tool
  3219. cf_ip
  3220. if [[ "${prompt_inst_av}" =~ ^([yY])$ ]]; then
  3221. install_av
  3222. fi
  3223. #Fix phpmyadmin error /var/lib/php/session
  3224. chown -R nginx. /var/lib/php/session
  3225. chmod 0755 /var/lib/php/session
  3226. # End install
  3227. add_menu
  3228. start_service
  3229. write_info
  3230. ssh_login_noti
  3231. if [[ "${prompt_ssh}" =~ ^([yY])$ ]]; then
  3232. change_ssh_port
  3233. fi
  3234. clear
  3235. sleep 1
  3236. printf "=========================================================================\n"
  3237. printf " Cai dat thanh cong \n"
  3238. printf " File luu thong tin: %s\n" "${FILE_INFO}"
  3239. printf " Neu can ho tro vui long truy cap %s\n" "${AUTHOR_CONTACT}"
  3240. printf "==========================================================================\n"
  3241. printf " Luu lai thong tin duoi day de truy cap SSH va phpMyAdmin \n"
  3242. printf " ${RED}%s${NC} \n" "De mo Menu su dung lenh: hostvn"
  3243. printf "==========================================================================\n"
  3244. printf "SSH Port : %s\n" "${SSH_PORT}"
  3245. printf "phpMyAdmin : %s\n" "http://${IPADDRESS}:${RANDOM_ADMIN_PORT}/phpmyadmin"
  3246. printf "Link Opcache Dashboard : %s\n" "http://${IPADDRESS}:${RANDOM_ADMIN_PORT}/opcache"
  3247. printf "Link Server Info : %s\n" "http://${IPADDRESS}:${RANDOM_ADMIN_PORT}/serverinfo"
  3248. if [[ "${prompt_memcached}" =~ ^([yY])$ ]]; then
  3249. printf "Link php Memcached Admin : %s\n" "http://${IPADDRESS}:${RANDOM_ADMIN_PORT}/memcached"
  3250. fi
  3251. if [[ "${prompt_redis}" =~ ^([yY])$ ]]; then
  3252. printf "Link Redis Admin : %s\n" "http://${IPADDRESS}:${RANDOM_ADMIN_PORT}/redis"
  3253. fi
  3254. printf "Link CSF GUI : %s\n" "https://${IPADDRESS}:${CSF_UI_PORT}"
  3255. echo "User phpMyAdmin va Admin Tool: admin "
  3256. printf "Password Admin tool : %s\n" "${ADMIN_TOOL_PWD}"
  3257. printf "Password phpMyAdmin : %s\n" "${SQLPASS}"
  3258. printf "=========================================================================\n"
  3259. sleep 3
  3260. shutdown -r now