Skip to content

Commit 38c6dee

Browse files
authored
Added step wise installation
1 parent e6476ec commit 38c6dee

File tree

1 file changed

+64
-39
lines changed

1 file changed

+64
-39
lines changed

setup.sh

+64-39
Original file line numberDiff line numberDiff line change
@@ -11,58 +11,79 @@ if [[ $os_name != "Ubuntu" ]] && [[ $os_name != "Debian" ]]; then
1111
echo "This script can only be run on Ubuntu or Debian!" ; exit 1
1212
fi
1313

14+
# Check where to start based on flag files
15+
if [ -f "/var/tmp/php_installation_complete" ]; then
16+
echo "Installation already completed."
17+
exit 0
18+
elif [ -f "/var/tmp/php_web_server_installed" ]; then
19+
echo "Web server already installed. Proceeding to MariaDB installation..."
20+
goto_mariadb=true
21+
elif [ -f "/var/tmp/php_versions_installed" ]; then
22+
echo "PHP versions already installed. Proceeding to web server installation..."
23+
goto_webserver=true
24+
elif [ -f "/var/tmp/php_repository_added" ]; then
25+
echo "PHP repository already added. Proceeding to PHP versions installation..."
26+
goto_php_versions=true
27+
fi
28+
1429
# Update system and install PHP repository
15-
apt-get update && apt-get upgrade -y
16-
apt-get install software-properties-common -y
17-
add-apt-repository ppa:ondrej/php -y
18-
apt-get update
30+
if [ ! "$goto_php_versions" ]; then
31+
apt-get update && apt-get upgrade -y
32+
apt-get install software-properties-common -y
33+
add-apt-repository ppa:ondrej/php -y
34+
apt-get update
35+
touch /var/tmp/php_repository_added
36+
fi
1937

2038
# Available PHP versions
2139
available_versions=$(apt-cache pkgnames | grep -Po '^php[0-9]\.[0-9]+$' | sort -Vu)
22-
echo "Available PHP versions (with 'php' prefix): $available_versions"
2340
available_versions=${available_versions//php/} # Remove "php" prefix
24-
echo "Available PHP versions: $available_versions"
25-
2641

2742
# Ask for PHP versions to install
28-
read -p "Enter PHP versions to install (separated by comma): " php_versions
29-
IFS=',' read -ra versions <<< "$php_versions"
30-
for version in "${versions[@]}"; do
31-
if [[ ! " $available_versions " =~ " php$version " ]]; then
32-
echo "Version $version is not available. Exiting..."
33-
exit 1
34-
fi
35-
done
36-
IFS=$'\n' sorted_versions=($(sort -V <<<"${versions[*]}"))
37-
unset IFS
38-
highest_version=${sorted_versions[-1]}
39-
40-
# Install PHP versions and extensions
41-
extensions=("bcmath" "xml" "fpm" "mysql" "zip" "intl" "ldap" "gd" "cli" "bz2" "curl" "mbstring" "pgsql" "opcache" "soap" "cgi" "imap" "apcu" "xsl")
42-
for version in "${versions[@]}"; do
43-
apt-get install "php${version}" $(printf "php${version}-%s " "${extensions[@]}") -y || {
44-
echo "Failed to install PHP version $version. Exiting..."
45-
exit 1
46-
}
47-
done
43+
if [ ! "$goto_php_versions" ]; then
44+
read -p "Enter PHP versions to install (separated by comma): " php_versions
45+
IFS=',' read -ra versions <<< "$php_versions"
46+
for version in "${versions[@]}"; do
47+
if [[ ! " $available_versions " =~ " $version " ]]; then
48+
echo "Version $version is not available. Exiting..."
49+
exit 1
50+
fi
51+
done
52+
IFS=$'\n' sorted_versions=($(sort -V <<<"${versions[*]}"))
53+
unset IFS
54+
highest_version=${sorted_versions[-1]}
55+
56+
# Install PHP versions and extensions
57+
extensions=("bcmath" "xml" "fpm" "mysql" "zip" "intl" "ldap" "gd" "cli" "bz2" "curl" "mbstring" "pgsql" "opcache" "soap" "cgi" "imap" "apcu" "xsl")
58+
for version in "${versions[@]}"; do
59+
apt-get install "php${version}" $(printf "php${version}-%s " "${extensions[@]}") -y || {
60+
echo "Failed to install PHP version $version. Exiting..."
61+
exit 1
62+
}
63+
done
64+
touch /var/tmp/php_versions_installed
65+
fi
4866

4967
# Ask for web server to install and handle installation
50-
read -p "Enter the web server to install (apache or nginx): " web_server
51-
web_server=${web_server,,} # Convert to lowercase
52-
if [[ $web_server == 'apache' ]]; then
53-
apt-get install apache2 -y && apt-get remove nginx -y
54-
elif [[ $web_server == 'nginx' ]]; then
55-
apt-get install nginx -y && apt-get remove apache2 -y
68+
if [ ! "$goto_webserver" ] && [ ! "$goto_php_versions" ]; then
69+
read -p "Enter the web server to install (apache or nginx): " web_server
70+
web_server=${web_server,,} # Convert to lowercase
71+
if [[ $web_server == 'apache' ]]; then
72+
apt-get install apache2 -y && apt-get remove nginx -y
73+
elif [[ $web_server == 'nginx' ]]; then
74+
apt-get install nginx -y && apt-get remove apache2 -y
75+
fi
76+
touch /var/tmp/php_web_server_installed
5677
fi
5778

5879
# Install and configure MariaDB
59-
apt-get install mariadb-server -y
60-
mysql_secure_installation
61-
62-
# Install PHPMyAdmin and configure for NGINX if applicable
63-
apt-get install phpmyadmin -y
80+
if [ ! "$goto_mariadb" ] && [ ! "$goto_webserver" ] && [ ! "$goto_php_versions" ]; then
81+
apt-get install mariadb-server -y
82+
mysql_secure_installation
83+
# Install PHPMyAdmin and configure for NGINX if applicable
84+
apt-get install phpmyadmin -y
6485

65-
if [[ $web_server == 'apache' ]]; then
86+
if [[ $web_server == 'apache' ]]; then
6687
cat > /etc/apache2/conf-available/phpmyadmin.conf << EOF
6788
Alias /phpmyadmin /usr/share/phpmyadmin
6889
<Directory /usr/share/phpmyadmin>
@@ -152,6 +173,10 @@ fi
152173
password=$(openssl rand -base64 16)
153174
mysql -u root -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '${password}'; FLUSH PRIVILEGES;"
154175

176+
177+
touch /var/tmp/php_installation_complete
178+
fi
179+
155180
echo "Installation completed!"
156181
echo "MySQL root username: root"
157182
echo "MySQL root password: ${password}"

0 commit comments

Comments
 (0)