PufferPanel auto installer for Ubuntu 16.04LTS - Pastee Link



  • Was playing around with trying to edit the auto installer for Ubuntu 16.04LTS and made a few minor changes. For Ubuntu 16.04 the default release of PHP is Version 7.0 thus many of the directories for fpm and just php in general have changed. This includes the commands to install the dependencies.

    Install the dependencies:

    sudo apt update
    sudo apt install -y openssl curl nginx git mysql-client mysql-server php-fpm php-cli php-curl php-mysql php-mcrypt
    

    Then enable mcrypt and restart fpm

    sudo phpenmod mcrypt
    sudo systemctl restart php7.0-fpm.service
    

    You can download my installer file here: https://pastee.org/wvrtt or I have placed it below:

    Notes on what was changed:

    • Optional: Hard code your IP or hostname on line 84 (Replace {$newHost} with your IP or hostname
    • Line 181 - Changed www.conf location for fpm to /etc/php/7.0/fpm/pool.d/www.conf
    • Line 183 - Changed www.conf location for fpm to /etc/php/7.0/fpm/pool.d/www.conf
    • Line 266 - Changed nginx restart command to systemctl restart nginx.service
    #!/usr/bin/env bash
    
    red=$(tput setf 4)
    green=$(tput setf 2)
    yellow=$(tput setf 6)
    blue=$(tput setf 1)
    normal=$(tput sgr0)
    bold=$(tput bold)
    
    mysqlHost="localhost"
    mysqlPort="3306"
    mysqlDb="pufferpanel"
    mysqlUser="root"
    mysqlPass=""
    
    DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
    
    function printSeparator() {
        echo "------------"
    }
    
    function loadConfig() {
        if [ "${mysqlHost}" == "" ]; then
            configPath=${DIR}/config.json
            mysqlHost=$(php -r 'echo json_decode(file_get_contents("'${configPath}'"))->mysql->host;');
            mysqlDb=$(php -r 'echo json_decode(file_get_contents("'${configPath}'"))->mysql->database;');
            mysqlUser=$(php -r 'echo json_decode(file_get_contents("'${configPath}'"))->mysql->username;');
            mysqlPass=$(php -r 'echo json_decode(file_get_contents("'${configPath}'"))->mysql->password;');
            mysqlPort=$(php -r 'echo json_decode(file_get_contents("'${configPath}'"))->mysql->port;');
        fi
    }
    
    function configureMysql() {
    
        type mysql 1>/dev/null 2>&1
        if [ $? -ne 0 ]; then
            echo "MySQL is not found within your PATH, cannot proceed"
            exit 1;
        fi
    
        echo "Thank you for using the PufferPanel installer!"
        echo "Before we can complete the installation, we need to ask you some questions"
        echo "These questions will help configure PufferPanel so that you can get to using it"
        printSeparator
        echo "MySQL Configuration"
        echo -n "Enter the MySQL host [localhost]: "
        read temp
        if [ "${temp}" != "" ]; then
            mysqlHost=${temp}
        fi
        echo -n "Enter the MySQL port [3306]: "
        read temp
        if [ "${temp}" != "" ]; then
            mysqlPort=${temp}
        fi
        echo -n "Enter the MySQL username (MUST HAVE GRANT) [root]: "
        read temp
        if [ "${temp}" != "" ]; then
            mysqlUser=${temp}
        fi
        notValid=true
        while ${notValid}; do
            echo -n "Enter the MySQL account password: "
            read -s temp
            if [ "${temp}" != "" ]; then
                mysqlPass=${temp}
            fi
            if mysql -h ${mysqlHost} -P ${mysqlPort} -u ${mysqlUser} --password="${mysqlPass}" -e "exit"; then
                notValid=false
            else
                print "Database connection could not be established"
            fi
        done
    
        echo ""
        echo "Creating pufferpanel account and installing database..."
        mysql -h ${mysqlHost} -P ${mysqlPort} -u ${mysqlUser} --password="${mysqlPass}" < install/install.sql
    
        newUser="pufferpanel"
        newPw=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
        newHost=$(mysql -h ${mysqlHost} -P ${mysqlPort} -D ${mysqlDb} -u ${mysqlUser} --password="${mysqlPass}" -e "SELECT host FROM information_schema.processlist WHERE ID=connection_id()" | head -n 3 | tail -n 1)
    
        mysql -h ${mysqlHost} -P ${mysqlPort} -D ${mysqlDb} -u ${mysqlUser} --password="${mysqlPass}" -e "
         GRANT SELECT, UPDATE, DELETE, ALTER, INSERT ON pufferpanel.* TO 'pufferpanel'@'${newHost}' IDENTIFIED BY '${newPw}';
         GRANT SELECT, UPDATE, DELETE, ALTER, INSERT ON pufferpanel.* TO 'pufferpanel'@'localhost' IDENTIFIED BY '${newPw}';
         GRANT SELECT, UPDATE, DELETE, ALTER, INSERT ON pufferpanel.* TO 'pufferpanel'@'172.17.42.%' IDENTIFIED BY '${newPw}';
        "
    
        echo "{
        \"mysql\": {
            \"host\": \"${mysqlHost}\",
            \"database\": \"${mysqlDb}\",
            \"username\": \"${newUser}\",
            \"password\": \"${newPw}\",
            \"port\": \"${mysqlPort}\",
            \"ssl\": {
                \"use\": false
            }
        }
    }" > config.json
        echo "MySQL has been configured and the database was installed"
        echo "Switching to new user for further commands"
        mysqlHost=""
        loadConfig
    }
    
    function configureSite() {
        echo "Configuring site details"
        siteUrl=""
        while [ "${siteUrl}" == "" ]; do
            echo -n "Please enter the domain or IP (if you do not have a domain) for your site (do NOT include http(s)://): "
            read siteUrl
        done
        siteUrl=$(echo ${siteUrl} | sed 's/^http\(\|s\):\/\///g')
        if [[ "${siteUrl}" == */ ]]; then
            siteUrl="${siteUrl%?}"
        fi
    
        loadConfig
        mysql -h ${mysqlHost} -P ${mysqlPort} -D ${mysqlDb} -u ${mysqlUser} --password="${mysqlPass}" -e "
            INSERT INTO acp_settings (setting_ref, setting_val) VALUES
                ('company_name', 'PufferPanel'),
                ('master_url', 'http://${siteUrl}/'),
                ('main_website', 'http://${siteUrl}/'),
                ('transport_token', NULL),
                ('transport_email', NULL),
                ('transport_method','php'),
                ('captcha_pub',NULL),
                ('captcha_priv',NULL),
                ('default_language', 'en'),
                ('https', 0),
                ('allow_subusers', 0) ON DUPLICATE KEY UPDATE setting_val = VALUES(setting_val)"
        echo "Settings saved to database"
    }
    
    function configureUser() {
        loadConfig
        echo "Please enter the following information for the new admin user"
        username=""
        email=""
        password=""
        uuid=$(uuidgen)
        while [ "${username}" == "" ]; do
            echo -n "Username: "
            read username
        done
        while [ "${email}" == "" ]; do
            echo -n "Email: "
            read email
        done
        while [ "${password}" == "" ]; do
            echo -n "Password: "
            read -s password
        done
        password=$(php -r "echo password_hash('"${password}"', PASSWORD_BCRYPT);");
        time=$(php -r 'echo time();');
    
        echo ""
        echo "Installing user..."
        mysql -h ${mysqlHost} -P ${mysqlPort} -D ${mysqlDb} -u ${mysqlUser} --password="${mysqlPass}" -e "
            INSERT INTO users VALUES (NULL, '${uuid}', '${username}', '${email}', '${password}', 'en', ${time}, NULL, NULL, 1, 0, 1, 0, NULL) ON DUPLICATE KEY UPDATE password='${password}'"
    }
    
    function configureNginx() {
    
        if [ -d "/etc/nginx" ]; then
            echo "Installing nginx config (if possible)"
        else
            echo "Nginx folder does not exist, will not install config"
            return
        fi
        if [ "${siteUrl}" == "" ]; then
            loadConfig
            siteUrl=$(mysql -h ${mysqlHost} -P ${mysqlPort} -D ${mysqlDb} -u ${mysqlUser} --password="${mysqlPass}" -e "
                SELECT setting_val FROM acp_settings WHERE setting_ref='master_url'" | head -n 3 | tail -n 1 | sed 's/^http\(\|s\):\/\///g')
            if [[ "${siteUrl}" == */ ]]; then
                siteUrl="${siteUrl%?}"
            fi
        fi
    
        phpSocket=$(grep "listen[| ]\?=[| ]" /etc/php/7.0/fpm/pool.d/www.conf 2>/dev/null | awk -F'[=&]' '{print $2}' | sed -e 's/ //')
        if [ "${phpSocket}" = "" ]; then
            phpSocket=$(grep "listen[| ]\?=[| ]" /etc/php/7.0/fpm/pool.d/www.conf 2>/dev/null | awk -F'[=&]' '{print $2}' | sed -e 's/ //')
            if [ "${phpSocket}" = "" ]; then
                echo "Could not determine where PHP config is, cannot install config"
                return
            fi
        fi
    
        if [[ "$(echo ${phpSocket:0:1})" == "/" ]]; then
            phpSocket="unix:${phpSocket}"
        fi
    
        conf="server {
            listen 80;
            root ${PWD};
            index index.php;
    
            server_name ${siteUrl};
    
            client_max_body_size 20m;
            client_body_timeout 120s;
    
            location / {
                try_files /public/router.php =404;
                fastcgi_split_path_info ^(.+?\.php)(/.*)$;
                fastcgi_pass ${phpSocket};
                fastcgi_index router.php;
                fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
                include /etc/nginx/fastcgi_params;
            }
    
            location /assets {
                try_files /app/\$uri =404;
            }
        }
    
        #server {
        #    listen 443;
        #    root ${PWD};
        #    index index.php;
        #
        #    server_name ${siteUrl};
        #
        #    ssl on;
        #    ssl_certificate     /etc/nginx/ssl/${siteUrl}.crt;
        #    ssl_certificate_key /etc/nginx/ssl/${siteUrl}.key;
        #
        #    location / {
        #        try_files /public/router.php =404;
        #        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        #        fastcgi_pass ${phpSocket};
        #        fastcgi_index router.php;
        #        fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
        #        include /etc/nginx/fastcgi_params;
        #    }
        #
        #    location /assets {
        #        try_files /app/\$uri =404;
        #    }
        #}
        "
    
        if [ -d "/etc/nginx/sites-enabled" ]; then
            if [ -f "/etc/nginx/sites-enabled/pufferpanel.conf" ]; then
                echo "An existing configuration exists in /etc/nginx/sites-enabled"
                return
            fi
            if [ -f "/etc/nginx/sites-available/pufferpanel.conf" ]; then
                echo "An existing configuration exists in /etc/nginx/sites-available"
                return
            fi
            echo "${conf}" > /etc/nginx/sites-available/pufferpanel.conf
            ln -s /etc/nginx/sites-available/pufferpanel.conf /etc/nginx/sites-enabled/pufferpanel.conf
        elif [ -d "/etc/nginx/conf.d/" ]; then
            if [ -f "/etc/nginx/conf.d/pufferpanel.conf" ]; then
                echo "An existing configuration exists in /etc/nginx/conf.d"
                return
            fi
            echo "${conf}" > /etc/nginx/conf.d/pufferpanel.conf
        else
            echo "Could not determine where to install the config"
            return
        fi
    
        systemctl restart nginx.service
    }
    
    case $1 in
        install)
            type php 1>/dev/null 2>&1
            if [ $? -ne 0 ]; then
                echo "PHP is not found within your PATH, cannot proceed"
                exit 1;
            fi
    
            result=$(php -r 'exit (version_compare(PHP_VERSION, "5.5.0") < 0 ? "1" : "0");');
            if [ "$result" == "0" ]; then
                echo "PHP 5.5.0+: [${green}Installed${normal}]"
            else
                echo "PHP 5.5.0+: [${red}Not Installed${normal}]"
                canInstall=false
            fi
    
            extensions=("curl" "hash" "openssl" "mcrypt" "pdo" "pdo_mysql")
            canInstall=1
            for i in ${extensions[@]}; do
                phpcmd=$(php -r 'echo extension_loaded("'${i}'") ? 1 : 0;')
                if [ "$phpcmd" -eq "1" ]; then
                    echo "PHP-${i}: [${green}Installed${normal}]"
                else
                    echo "PHP-${i}: [${red}Not Installed${normal}]"
                    canInstall=0
                fi
            done
            if [ "${canInstall}" -eq "0" ]; then
                if [ "$2" = "-f" ]; then
                    canInstall=1
                    echo "Forcing installer due to flag being present"
                else
                    echo "Dependencies are missing, cannot install"
                    exit 1
                fi
            fi
    
            printSeparator
            configureMysql
            printSeparator
            configureSite
            printSeparator
            configureUser
            type nginx 1>/dev/null 2>&1
            if [ $? -eq 0 ]; then
                configureNginx
            fi
    
            printSeparator
            shopt -s nocasematch
            echo -n "Would you like to thank us? Each thanks gives us the motivation to provide this software to you. [Y/n]: "
            read thanks
            if [[ "${thanks}" == "Y" ]] || [[ "${thanks}" == "" ]]; then
                curl -X POST https://thankyou.pufferpanel.com >/dev/null 2>&1
            fi
    
            printSeparator
            echo "Thank you for installing PufferPanel!"
            echo "Assuming that the installation completed, you will be able to visit your new panel at ${blue}http://${siteUrl}${normal}"
            ;;
        updatesite)
            configureSite
            ;;
        adduser)
            configureUser
            ;;
        addnginx)
            ;;
        update)
            chmod +x install/update
            install/update
            ;;
        *)
            echo "PufferPanel"
            echo "Usage: ./pufferpanel [install/update]"
            ;;
    esac
    

    Using these modifications, I was able to successfully install pufferpanel on Ubuntu 16.04LTS. I have not done any testing yet with installing nodes, servers, adding users, etc. I don't foresee any issues but will update as I find them.

    To the PufferPanel admins, not sure how you want to handle this, but seeing as how Ubuntu 16.04 is a LTS release and is beginning to be used more often I would recommend adding a section to the documentation on installation for 16.04. There isn't many changes other than using systemd and the changes in php 7.0. Your install script actually checks for php5+ but doesn't take into account location changes.

    result=$(php -r 'exit (version_compare(PHP_VERSION, "5.5.0") < 0 ? "1" : "0");');
            if [ "$result" == "0" ]; then
                echo "PHP 5.5.0+: [${green}Installed${normal}]"
            else
                echo "PHP 5.5.0+: [${red}Not Installed${normal}]"
                canInstall=false
            fi
    
    

    Thanks,
    DMehaffy



  • A note when installing nodes:

    If you attempt to run the auto-deploy script on another server you will get an error about not finding the openjdk 7 package. To resolve this simply run the following command on the remote server before running the auto-deploy command:

    sudo add-apt-repository ppa:openjdk-r/ppa 
    sudo apt-get update
    

    Personally I believe this auto deploy needs to be changed to auto install Java 1.8 as it is on the centos auto-deploy but those changes can be done manually after install.

    Edit: After attempting to add a default minecraft server (No mods bukkit, spigot, whatever) an error appears in the console about Java 1.8

    To remedy this issue you just need to install the default jdk (aka java 1.8 from the ubuntu repo)

    sudo apt-get install -y default-jdk
    

    Once you have Java 1.8 the default minecraft server will run perfectly.

    After the auto deploy is finished, I manually changed out the self signed certificates for my AlphaSSL wildcard one and the Panel connected with the Node (although it did take a minute to actually start talking and appear online in the panel)

    I will continue to update as I test everything.

    • DMehaffy


  • thanks so much but the pastee link says 502 bad gateway.

    also if i do-release-upgrade will i lose all of my data



  • Yeah it looks like Pastee might be down, either way I pasted the exact same thing below the Pastee link.

    I have not tested doing a Distro Upgrade on 16.04. My install was tested on a fresh install of 16.04.

    I am also using Nginx and Apache2 at the same time (Created an Nginx reverse proxy to Apache2 and have Apache2 running only on localhost:8080)

    I would say do a complete backup of everything including your SQL databases and attempt the upgrade, if your running a virtual machine you can always do a snapshot and revert back if it doesn't work. (I run all my servers on XenServer 7 with VMs for everything and do snapshots before I do any major changes)



  • In the future, the project's preferred pasting service is https://paste.ee



  • @derrickmehaffy i just use a crappy ovh vps and i don't want to have to pay to make a backup



  • @PacksGamingHD said in PufferPanel auto installer for Ubuntu 16.04LTS - Pastee Link:

    @derrickmehaffy i just use a crappy ovh vps and i don't want to have to pay to make a backup

    Just do the backup yourself? I imagine you have sftp/ftp access and you also probably have access to the command line.

    Export a MySQL backup then do a files backup.



  • @puffrfish said in PufferPanel auto installer for Ubuntu 16.04LTS - Pastee Link:

    In the future, the project's preferred pasting service is https://paste.ee

    Definitely noted, when I wrote that up I was quite tired lol I think that's the one I was aiming for but missed, I'll reload and edit my link.



  • @derrickmehaffy said in PufferPanel auto installer for Ubuntu 16.04LTS - Pastee Link:

    @puffrfish said in PufferPanel auto installer for Ubuntu 16.04LTS - Pastee Link:

    In the future, the project's preferred pasting service is https://paste.ee

    Definitely noted, when I wrote that up I was quite tired lol I think that's the one I was aiming for but missed, I'll reload and edit my link.

    Well it looks like paste.ee is also having some nginx issues at the moment.



  • @derrickmehaffy i don't even know what my mysql details and i've fucked with mysql and phpmyadmin and i don't even know anymore



  • @PacksGamingHD The Mysql ip is currently not open for remote unless you do in mysql config

    #bind address
    

    Then the user is root password is defined when you made the mysql database database in the setup.

    Phpmyadmin is a pain to setup but I finally figured out how.



  • PhpMyAdmin is a good tool if your in the Database quite a bit, otherwise if you want something simple you can use Webmin. It'll give you pretty basic controls over mysql but also everything else on the server.



  • @derrickmehaffy said in PufferPanel auto installer for Ubuntu 16.04LTS - Pastee Link:

    PhpMyAdmin is a good tool if your in the Database quite a bit, otherwise if you want something simple you can use Webmin. It'll give you pretty basic controls over mysql but also everything else on the server.

    Yeah but I just get annoyed enough to wasted 2 hours to finally install..



  • My setup is a tad more complicated, as I dont host the sql server(s) on the pufferpanel host itself. I run a Galera Cluster on 3 different machines with an HAProxy to load balance. Its easier for me just to manage Database/User creation using MySQL's Workbench on a Bastion Host.

    Benefit to my setup is all my machines connect to one "server" that is load balanced between 3 different mysql servers. And anytime I add/change/remove anything they all sync at the same time. I essentially have 3 backups of everything with better mysql response times so I -could- use phpmyadmin but workbench is so much easier and user friendly lol. It doesn't particularly care for MariaDB Galera though.



  • confirmed and worked for ubuntu 16.04

    was able to get a server running on it fine with the modified code. thanks



  • can it work with apache?



  • @ariqcs said in PufferPanel auto installer for Ubuntu 16.04LTS - Pastee Link:

    can it work with apache?

    Assuming you are using PufferPanel 0.8.6 you can read the Apache documentation here: http://www.pufferpanel.com/v0.8.6/docs/apache-configuration


Log in to reply
 

Looks like your connection to PufferPanel Community was lost, please wait while we try to reconnect.