-
Notifications
You must be signed in to change notification settings - Fork 0
/
lemp-basic.sh
184 lines (158 loc) · 7.19 KB
/
lemp-basic.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/sh
set -e
clear
if [[ $EUID = 0 ]]; then
echo "Please run this script as non-root sudo user"
exit 1
fi
sudo service ssh restart
# Set SSH Port
read -e -p $'Set/Change SSH port : ' -i "22" ssh_port_number
sudo sed -i 's/#Port 22/Port '$ssh_port_number'/g' /etc/ssh/sshd_config
sudo service ssh restart
# Change System timezone
read -e -p $'Change System TimeZone ? [Default is UTC]: ' -i "Asia/Tehran" system_default_timezone
sudo timedatectl set-timezone $system_default_timezone
read -e -p $'Folder name for domain(s) ? : ' -i "test" domain_folder_name
read -e -p $'Enter domains FQDN (seperated by space , exp: test.com www.test.com ) : \n' www_domains
read -e -p $'Select PHP Version [7.4|8.1]: ' -i "8.1" php_version
read -e -p $'Install PHP-xDebug: ' -i "n" if_install_php_xdebug
read -e -p $'Install PHP-imagick: ' -i "n" if_install_php_imagick
read -e -p $'Install Composer [y/n]: ' -i "y" if_install_composer
read -e -p $'DataBase is MySQL8 / Change it to MariaDb-10.6 ? : ' -i "n" if_change_db_to_mariadb
read -e -p $'Enter DataBase root password: \n' database_root_password
read -e -p $'Install PHPMyAdmin on pma folder ? : ' -i "y" if_install_pma
if [[ $if_install_pma =~ ^([Yy])$ ]]
then
read -e -p $'Enter PHPMyAdmin FQDN: \n' pma_fqdn
fi
read -e -p $'Install Redis ? : ' -i "y" if_install_redis
#############################################################################
sudo apt --yes update && sudo apt -q --yes upgrade
sudo apt --yes install software-properties-common aria2 bzip2 ca-certificates curl git gnupg gosu htop iotop iperf libcap2-bin libpng-dev make gcc nano net-tools nmap chrony openssh-server openssl p7zip poppler-utils apt-transport-https lsb-release python2 sqlite3 supervisor traceroute unar unzip wget zip zsh
cd /home/$USER/
mkdir -p www
cd www
mkdir -p $domain_folder_name
sudo add-apt-repository --yes ppa:ondrej/php
sudo apt --yes update
# install php
if [[ $php_version = "8.1" ]]
then
# install with 8.1
sudo apt --yes install php8.1-cli php8.1-fpm php8.1-dev php8.1-pgsql php8.1-sqlite3 php8.1-gd php8.1-curl php8.1-memcached php8.1-imap php8.1-mysql php8.1-mbstring php8.1-xml php8.1-zip php8.1-bcmath php8.1-soap php8.1-intl php8.1-readline php8.1-pcov php8.1-msgpack php8.1-igbinary php8.1-ldap php8.1-redis php8.1-swoole php8.1-apcu php8.1-opcache php8.1-mongodb php8.1-gmp
if [[ $if_install_php_xdebug =~ ^([Yy])$ ]]
then
sudo apt --yes install php8.1-xdebug
fi
if [[ $if_install_php_imagick =~ ^([Yy])$ ]]
then
sudo apt --yes install php8.1-imagick
fi
else
# install with 7.4
sudo apt --yes install php7.4-cli php7.4-fpm php7.4-dev php7.4-pgsql php7.4-sqlite3 php7.4-gd php7.4-curl php7.4-memcached php7.4-imap php7.4-mysql php7.4-mbstring php7.4-xml php7.4-zip php7.4-bcmath php7.4-soap php7.4-intl php7.4-readline php7.4-pcov php7.4-msgpack php7.4-igbinary php7.4-ldap php7.4-redis php7.4-swoole php7.4-apcu php7.4-opcache php7.4-mongodb php7.4-gmp
if [[ $if_install_php_xdebug =~ ^([Yy])$ ]]
then
sudo apt --yes install php7.4-xdebug
fi
if [[ $if_install_php_imagick =~ ^([Yy])$ ]]
then
sudo apt --yes install php7.4-imagick
fi
fi
# install composer
if [[ $if_install_composer =~ ^([Yy])$ ]]
then
sudo php -r "readfile('http://getcomposer.org/installer');" | sudo php -- --install-dir=/usr/bin/ --filename=composer
fi
# install pma
if [[ $if_install_pma =~ ^([Yy])$ ]]
then
mkdir -p pma
curl -L "https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-english.tar.gz" -o pma.tgz
tar -xzf pma.tgz -C pma --strip-components=1
rm -f pma.tgz
# copy config
fi
# install redis
if [[ $if_install_redis =~ ^([Yy])$ ]]
then
# install redis
sudo add-apt-repository --yes ppa:redislabs/redis
sudo apt --yes update
sudo apt --yes install redis
sudo systemctl enable --now redis-server
fi
# Install MySQL Server based on selection
if [[ $if_change_db_to_mariadb =~ ^([Yy])$ ]]
then
# install mariadb
sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
sudo add-apt-repository "deb [arch=amd64,arm64,ppc64el] http://sfo1.mirrors.digitalocean.com/mariadb/repo/10.6/ubuntu $(lsb_release -cs) main"
sudo apt --yes update
sudo apt --yes install mariadb-server
else
# install mysql8
sudo apt --yes install mysql-server
fi
## change mysql-mariadb root password
if [[ $if_change_db_to_mariadb =~ ^([Yy])$ ]]
then
sudo mysql_secure_installation <<EOF
y
y
$database_root_password
$database_root_password
y
y
y
y
EOF
else
sudo mysql -e "DELETE FROM mysql.user WHERE User='';"
sudo mysql -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');"
sudo mysql -e "DROP DATABASE IF EXISTS test;DELETE FROM mysql.db WHERE db='test' OR db='test_%';"
sudo mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '${database_root_password}';FLUSH PRIVILEGES;"
fi
# install nginx + configuration (nginx+phpfpm)
## php-fpm config
sudo apt --yes install nginx
sudo mv /etc/php/$php_version/fpm/pool.d/www.conf /etc/php/$php_version/fpm/pool.d/www.conf.bak
sudo curl -L "https://github.com/ariadata/ubuntu-sh/raw/master/files/php-fpm-$php_version-www-template.conf" -o /etc/php/$php_version/fpm/pool.d/www.conf
sudo sed -i 's/ubuntu/'$USER'/g' /etc/php/$php_version/fpm/pool.d/www.conf
## default page for site
curl -L "https://github.com/ariadata/ubuntu-sh/raw/master/files/under_cunstruction.html" -o /home/$USER/www/$domain_folder_name/index.html
## nginx config for domains
sudo curl -L "https://github.com/ariadata/ubuntu-sh/raw/master/files/nginx-basic-template.conf" -o /etc/nginx/sites-available/$domain_folder_name
sudo ln -s /etc/nginx/sites-available/$domain_folder_name /etc/nginx/sites-enabled/$domain_folder_name
sudo sed -i "s/##domain_name##/$www_domains/g" /etc/nginx/sites-available/$domain_folder_name
sudo sed -i "s/##folder_path##/\/home\/$USER\/www\/$domain_folder_name/g" /etc/nginx/sites-available/$domain_folder_name
sudo sed -i "s/##php_version##/$php_version/g" /etc/nginx/sites-available/$domain_folder_name
## nginx config for pma
if [[ $if_install_pma =~ ^([Yy])$ ]]
then
sudo curl -L "https://github.com/ariadata/ubuntu-sh/raw/master/files/nginx-basic-template.conf" -o /etc/nginx/sites-available/phpmyadmin
sudo ln -s /etc/nginx/sites-available/phpmyadmin /etc/nginx/sites-enabled/phpmyadmin
sudo sed -i "s/##domain_name##/$pma_fqdn/g" /etc/nginx/sites-available/phpmyadmin
sudo sed -i "s/##folder_path##/\/home\/$USER\/www\/pma/g" /etc/nginx/sites-available/phpmyadmin
sudo sed -i "s/##php_version##/$php_version/g" /etc/nginx/sites-available/phpmyadmin
fi
## nginx change default
sudo curl -L "https://github.com/ariadata/ubuntu-sh/raw/master/files/nginx-default-template.conf" -o /etc/nginx/sites-available/default
## mysql+mariadb conf
sudo curl -L "https://github.com/ariadata/ubuntu-sh/raw/master/files/mysql-custom-config.cnf" -o /etc/mysql/conf.d/custom.cnf
## create user mariadb-mysql
# sudo mysql -u root -p${database_root_password} -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '$database_root_password' WITH GRANT OPTION;FLUSH PRIVILEGES;"
##
sudo apt --yes update && sudo apt -q --yes upgrade
sudo apt --yes autoremove
rm -f lemp-basic.sh
clear
## reboot at the end
read -e -p $'Finished, Reboot Now ? : ' -i "y" if_reboot_at_end
if [[ $if_reboot_at_end =~ ^([Yy])$ ]]
then
sudo reboot
exit
fi