Скрипт установки для Debian 9

$ apt install php5-cgi php5-cli php5-common php5-curl php5-dev php5-fpm php5-gd php5-intl php5-json php5-mcrypt php5-memcache php5-memcached php5-mongo php5-mysql php5-readline php5-redis php5-sqlite php5-xsl php5-geoip php5-ssh2

Установка различных версий PHP

Описание

Автоматическая установка и обновление зависимых пакетов

Автоматическая устанока и настройка серверов GIT, PHP 5.6, PHP-FPM, Nginx, Redis, MySQL (mariadb), RabbitMQ, Exim4

Автоматическое конфигурирование пакетов

Установка автоматического бекапа БД MySQL (https://github.com/Mirocow/mysql_utils.git)

Устанока скрипта для создания сайта (https://github.com/Mirocow/site-create)

Установка

# nano debian-install.sh # bash ./debian-install.sh

В debian-install.sh вставляем ниже следующий текст и нащимаем Ctrl-x, затем y (сохраняем и выходим)

Для Debian 9, чтоб работал php5, необходимо добавить в /etc/apt/sources.list deb http://ftp.debian.org/debian jessie main contrib deb-src http://ftp.debian.org/debian jessie main contrib deb http://security.debian.org/ jessie/updates main contrib deb-src http://security.debian.org/ jessie/updates main contrib
#!/bin/sh distrib="stretch" check_result() { if [ $1 -ne 0 ]; then echo "Error: $2" exit $1 fi } promptyn () { while true; do read -p "$1" yn case $yn in [Yy]* ) return 0;; [Nn]* ) return 1;; * ) echo "Please answer yes or no.";; esac done } prompt () { while read -p "$1" variable && [[ -z "$variable" ]] ; do echo "$1" done echo $variable; } installpkg() { for pkg in $@ do if [ $(dpkg-query -W -f='${Status}' $pkg 2>/dev/null | grep -c "ok installed") -eq 0 ]; then echo "Install $pkg ..." apt-get install -y $pkg; fi done } set_default_value() { eval variable=\$$1 if [ -z "$variable" ]; then eval $1=$2 fi if [ "$variable" != 'yes' ] && [ "$variable" != 'no' ]; then eval $1=$2 fi } if [ "x$(id -u)" != 'x0' ]; then check_result 1 "Script can be run executed only by root" fi apt-get update && apt-get upgrade -y installpkg apt apt-utils wget sudo nano rename debconf-utils pwgen mailutils default_pass=$(pwgen -s 18 1 -n -c -s -y) hostname=$(prompt "Enter the Internet domain name (e.g. nixcraft.com) : "); if promptyn "Do you wish to install default programs? [mc, git, etc] " ; then echo -e "Install default programs"; installpkg mc git mercurial bash-completion bzip2 numactl dnsutils fi if promptyn "Do you wish to install developers programs? [gcc, g++, etc] "; then echo -e "Install development soft"; installpkg checkinstall gcc build-essential g++ libboost-dev libboost-program-options-dev libboost-all-dev libevent-dev uuid-dev clang cmake fi if promptyn "Do you wish to install system monitors? [htop, iptraf] "; then echo -e "Install system monitors"; installpkg htop iptraf jnettop iftop fi if promptyn "Do you wish to uninstall systemd and install systemv? "; then installpkg sysvinit-core sysvinit-utils cp /usr/share/sysvinit/inittab /etc/inittab fi if promptyn "Do you wish to install FTP Server (PRO-Ftpd)? "; then installpkg proftpd fi if promptyn "Do you wish to install MySql? "; then installpkg software-properties-common if promptyn "Do you wish to install MySql (Percona) (y) or Mariadb (n)?"; then apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db echo " # Percona #deb http://repo.percona.com/apt ${distrib} testing #deb-src http://repo.percona.com/apt ${distrib} testing " > /etc/apt/sources.list.d/mysql.list apt-get update installpkg percona-server-server-5.7 percona-server-client-5.7 percona-server-common-5.7 percona-toolkit -y sevice mysql start check_result $? "mysql start failed" echo -e "[client]\npassword='$f'\n" > /root/.my.cnf chmod 600 /root/.my.cnf mysql -e "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('${default_pass}');" mysql -e "UPDATE mysql.user SET plugin = '' WHERE user = 'root' AND host = 'localhost';" mysql -e "DELETE FROM mysql.user WHERE User=''" mysql -e "DROP DATABASE test" >/dev/null 2>&1 mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'" mysql -e "DELETE FROM mysql.user WHERE user='' or password='';" mysql -e "FLUSH PRIVILEGES" echo -e "Install MySQL (Percona)" update-rc.d mysql defaults set_default_value 'mysql' 'true' else # for sid apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8 # for jessie apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db echo " # MariaDB 10.1 repository list - created 2016-08-05 19:23 UTC # http://downloads.mariadb.org/mariadb/repositories/ deb [arch=amd64,i386] http://mirror.timeweb.ru/mariadb/repo/10.1/debian ${distrib} main deb-src http://mirror.timeweb.ru/mariadb/repo/10.1/debian ${distrib} main " > /etc/apt/sources.list.d/mysql.list apt-get update installpkg mariadb-server mariadb-client mariadb-common mytop service mysql start check_result $? "mysql start failed" echo -e "[client]\npassword='${default_pass}'\n" > /root/.my.cnf chmod 600 /root/.my.cnf mysql -e "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('${default_pass}');" mysql -e "UPDATE mysql.user SET plugin = '' WHERE user = 'root' AND host = 'localhost';" mysql -e "DELETE FROM mysql.user WHERE User=''" mysql -e "DROP DATABASE test" >/dev/null 2>&1 mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'" mysql -e "DELETE FROM mysql.user WHERE user='' or password='';" mysql -e "FLUSH PRIVILEGES" echo -e "Install MySQL (Mariadb)" update-rc.d mysql defaults set_default_value 'mysql' 'true' fi fi if promptyn "Do you wish to install PostgreSql? "; then installpkg postgresql-9.6 postgresql-contrib-9.6 echo "ALTER USER postgres WITH ENCRYPTED PASSWORD '${default_pass}';" |sudo -u postgres psql echo " local all postgres md5 " >> /etc/postgresql/9.6/main/pg_hba.conf service postgresql restart fi if promptyn "Do you wish to install Nginx? "; then wget -q http://nginx.org/keys/nginx_signing.key -O- | apt-key add - echo " # nginx deb http://nginx.org/packages/debian ${distrib} nginx deb-src http://nginx.org/packages/debian ${distrib} nginx " > /etc/apt/sources.list.d/nginx.list apt-get update service nginx stop > /dev/null 2>&1 installpkg nginx -y service nginx start check_result $? "nginx start failed" echo -e "Install Nginx" update-rc.d nginx defaults set_default_value 'nginx' 'true' fi if promptyn "Do you wish to install PHP-FPM? "; then wget -q http://www.dotdeb.org/dotdeb.gpg -O- | apt-key add - php_ver=$(prompt "Please select php version like 5, 6.0, 7.0, 7.1: ") echo " # php-fpm dotdeb deb http://packages.dotdeb.org ${distrib} all deb-src http://packages.dotdeb.org ${distrib} all " > /etc/apt/sources.list.d/php-fpm.list apt-get update service php${php_ver}-fpm stop >/dev/null 2>&1 if [ $php_ver -eq 5 ]; then installpkg -u -t stable php${php_ver} php${php_ver}-dev php${php_ver}-sqlite php${php_ver}-mcrypt php${php_ver}-xsl php${php_ver}-cli php${php_ver}-common php${php_ver}-mysql php${php_ver}-gd php${php_ver}-fpm php${php_ver}-cgi php-pear php${php_ver}-curl fi if [ $php_ver -eq 7 ]; then installpkg -u -t stable php${php_ver} php${php_ver}-dev php${php_ver}-sqlite php${php_ver}-mcrypt php${php_ver}-xsl php${php_ver}-cli php${php_ver}-common php${php_ver}-mysql php${php_ver}-gd php${php_ver}-fpm php${php_ver}-cgi php-pear php${php_ver}-curl php${php_ver}-xcache php${php_ver}-redis fi if [ $php_ver -eq 71 ]; then installpkg -u -t stable php${php_ver} php${php_ver}-dev php${php_ver}-sqlite php${php_ver}-mcrypt php${php_ver}-xsl php${php_ver}-cli php${php_ver}-common php${php_ver}-mysql php${php_ver}-gd php${php_ver}-fpm php${php_ver}-cgi php-pear php${php_ver}-curl php${php_ver}-xcache php${php_ver}-redis fi echo "cgi.fix_pathinfo = 0" >> /etc/php${php_ver}/fpm/php.ini service php${php_ver}-fpm start check_result $? "php${php_ver}-fpm start failed" echo -e "Install PHP-FPM" update-rc.d php${php_ver}-fpm defaults set_default_value "php${php_ver}-fpm' 'true" fi if promptyn "Do you wish to install RabbitMQ? "; then wget -q http://packages.erlang-solutions.com/debian/erlang_solutions.asc -O- | apt-key add - wget -q https://www.rabbitmq.com/rabbitmq-signing-key-public.asc -O- | apt-key add - echo " # Erlang deb http://packages.erlang-solutions.com/debian ${distrib} contrib # RabbitMq deb http://www.rabbitmq.com/debian/ testing main " > /etc/apt/sources.list.d/rabbitmq.list apt-get update service rabbitmq-server start installpkg rabbitmq-server check_result $? "rabbitmq-server start failed" echo -e "Install RabbitMQ" update-rc.d rabbitmq-server defaults set_default_value 'rabbitmq-server' 'true' fi if promptyn "Do you wish to install Redis server? "; then installpkg redis-server service redis-server start check_result $? "redis-server start failed" echo -e "Install Redis" update-rc.d redis-server defaults set_default_value 'redis-server' 'true' fi if promptyn "Do you wish to install DNS server? "; then if promptyn "Do you wish to install bind (y) or pdns (n) server?"; then installpkg bind9 bind9utils bind9-libs service bind9 start echo -e "Install DNS Server" set_default_value 'bind' 'true' else installpkg pdns-server pdns-backend-mysql pdns-recursor echo -e "Install DNS Server" set_default_value 'pdns' 'true' fi fi if promptyn "Do you wish to install Shorewall? "; then installpkg shorewall fi if promptyn "Do you wish to install Postfix/Exim4? "; then installpkg exim4-daemon-heavy mailutils service exim4 stop > /dev/null 2>&1 gpasswd -a Debian-exim mail touch /etc/exim4/exim4.conf.template touch /etc/exim4/dnsbl.conf touch /etc/exim4/spam-blocks.conf touch /etc/exim4/white-blocks.conf chmod 640 /etc/exim4/exim4.conf.template rm -rf /etc/exim4/domains mkdir -p /etc/exim4/domains rm -f /etc/alternatives/mta ln -s /usr/sbin/exim4 /etc/alternatives/mta service sendmail stop > /dev/null 2>&1 service postfix stop > /dev/null 2>&1 service exim4 start check_result $? "exim4 start failed" update-rc.d exim4 defaults set_default_value 'exim' 'true' dpkg-reconfigure exim4-config fi if promptyn "Do you wish to install Dovecot? "; then gpasswd -a dovecot mail chown -R root:root /etc/dovecot* service dovecot stop > /dev/null 2>&1 installpkg dovecot-imapd dovecot-pop3d dovecot-common service dovecot start check_result $? "dovecot start failed" update-rc.d dovecot defaults set_default_value 'dovecot' 'true' fi if promptyn "Do you wish to install fail2ban? "; then installpkg fail2ban -y if [ "$exim" = 'no' ]; then fline=$(cat /etc/fail2ban/jail.local |grep -n exim-iptables -A 2) fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -) sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local fi update-rc.d fail2ban defaults service fail2ban start check_result $? "fail2ban start failed" fi if promptyn "Do you wish to install Mysql backup system? "; then echo -e "Install MySql backup system"; apt-get update installpkg git git clone https://github.com/Mirocow/mysql_utils.git /root/mysql_utils echo ' # Run MySql backup system 25 6 * * * root /bin/bash ~/mysql_utils/backup.sh --dir="/var/backups/mysql" --compress=bzip2 --exclude="mysql" --lifetime="3 day ago" ' >> /etc/crontab fi if promptyn "Do you wish to install create site script? "; then echo -e "Install create site scriptm"; wget https://raw.githubusercontent.com/Mirocow/site-create/master/site-create.sh -O /root/site-create.sh fi rm /var/cache/apt/archives/*.deb -f if promptyn "Do you wish to set default shell settings? "; then echo -e "Base system configure" echo ' # ~/.bashrc: executed by bash(1) for non-login shells. # Note: PS1 and umask are already set in /etc/profile. You should not # need this unless you want different defaults for root. # PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ ' # umask 022 # You may uncomment the following lines if you want `ls' to be colorized: # export LS_OPTIONS='--color=auto' # eval "`dircolors`" # alias ls='ls $LS_OPTIONS' # alias ll='ls $LS_OPTIONS -l' # alias l='ls $LS_OPTIONS -lA' # # Some more alias to avoid making mistakes: # alias rm='rm -i' # alias cp='cp -i' # alias mv='mv -i' # If not running interactively, don't do anything case $- in *i*) ;; *) return;; esac # # My config # #search in history with arrows #bind \e[A: history-search-backward 2>/dev/null #bind \e[B: history-search-forward 2>/dev/null alias nano="nano -u -w " HISTSIZE=-1 HISTFILESIZE=-1 export HISTCONTROL=ignoreboth shopt -s cmdhist shopt -s histappend shopt -s checkwinsize shopt -s extglob ulimit -c 0 # set variable identifying the chroot you work in (used in the prompt below) if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then debian_chroot=$(cat /etc/debian_chroot) fi # set a fancy prompt (non-color, unless we know we "want" color) case "$TERM" in xterm-color|*-256color) color_prompt=yes;; esac force_color_prompt=yes if [ -n "$force_color_prompt" ]; then if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then # We have color support; assume it's compliant with Ecma-48 # (ISO/IEC-6429). (Lack of such support is extremely rare, and such # a case would tend to support setf rather than setaf.) color_prompt=yes else color_prompt= fi fi if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' else PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' fi unset color_prompt force_color_prompt # If this is an xterm set the title to user@host:dir case "$TERM" in xterm*|rxvt*) PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" ;; *) ;; esac # enable color support of ls and also add handy aliases if [ -x /usr/bin/dircolors ]; then test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" alias ls='ls --color=auto' alias dir='dir --color=auto' alias vdir='vdir --color=auto' alias grep='grep --color=auto' alias fgrep='fgrep --color=auto' alias egrep='egrep --color=auto' fi # colored GCC warnings and errors export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi if ! shopt -oq posix; then if [ -f /usr/share/bash-completion/bash_completion ]; then . /usr/share/bash-completion/bash_completion elif [ -f /etc/bash_completion ]; then . /etc/bash_completion fi fi # # Functions # function h(){ history| grep "$@"; } ' >> ~/.bashrc source ~/.bashrc echo ' set tabsize "2" ' >> ~/.nanorc fi apt-get update apt-get upgrade apt-get autoremove -y