Skip to content

Instantly share code, notes, and snippets.

@alexkorep
Last active November 21, 2021 13:43
Show Gist options
  • Select an option

  • Save alexkorep/66b0de398426c98f862c9a2e55358f13 to your computer and use it in GitHub Desktop.

Select an option

Save alexkorep/66b0de398426c98f862c9a2e55358f13 to your computer and use it in GitHub Desktop.

Revisions

  1. alexkorep revised this gist Nov 21, 2021. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions Install LAMP+Wordpress
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,8 @@
    #/bin/sh

    # to run:
    # bash <(curl -sL https://gist.github.com/alexkorep/66b0de398426c98f862c9a2e55358f13/raw/2ab974e4db402e202f9282b108a8b9200270013a/Install%2520LAMP+Wordpress)

    install_dir="/var/www/html"
    #Creating Random WP Database Credenitals
    db_name="wp`date +%s`"
  2. alexkorep revised this gist Nov 21, 2021. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions Install LAMP+Wordpress
    Original file line number Diff line number Diff line change
    @@ -36,8 +36,9 @@ echo "user=root">>/root/.my.cnf
    echo "password="$mysqlrootpass>>/root/.my.cnf
    ####Install PHP
    apt -y install php
    apt -y php-mysql
    apt -y php-gd
    apt -y install php-mysql
    apt -y install php-gd
    apt -y install libapache2-mod-php

    sed -i '0,/AllowOverride\ None/! {0,/AllowOverride\ None/ s/AllowOverride\ None/AllowOverride\ All/}' /etc/apache2/apache2.conf #Allow htaccess usage

  3. alexkorep created this gist Nov 21, 2021.
    98 changes: 98 additions & 0 deletions Install LAMP+Wordpress
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,98 @@
    #/bin/sh

    install_dir="/var/www/html"
    #Creating Random WP Database Credenitals
    db_name="wp`date +%s`"
    db_user=$db_name
    db_password=`date |md5sum |cut -c '1-12'`
    sleep 1
    mysqlrootpass=`date |md5sum |cut -c '1-12'`
    sleep 1

    apt update

    #### Install Packages for https and mysql
    apt -y install apache2
    apt -y install mysql-server


    #### Start http
    rm /var/www/html/index.html
    systemctl enable apache2
    systemctl start apache2

    #### Start mysql and set root password

    systemctl enable mysql
    systemctl start mysql

    /usr/bin/mysql -e "USE mysql;"
    /usr/bin/mysql -e "UPDATE user SET Password=PASSWORD($mysqlrootpass) WHERE user='root';"
    /usr/bin/mysql -e "FLUSH PRIVILEGES;"
    touch /root/.my.cnf
    chmod 640 /root/.my.cnf
    echo "[client]">>/root/.my.cnf
    echo "user=root">>/root/.my.cnf
    echo "password="$mysqlrootpass>>/root/.my.cnf
    ####Install PHP
    apt -y install php
    apt -y php-mysql
    apt -y php-gd

    sed -i '0,/AllowOverride\ None/! {0,/AllowOverride\ None/ s/AllowOverride\ None/AllowOverride\ All/}' /etc/apache2/apache2.conf #Allow htaccess usage

    systemctl restart apache2

    ####Download and extract latest WordPress Package
    if test -f /tmp/latest.tar.gz
    then
    echo "WP is already downloaded."
    else
    echo "Downloading WordPress"
    cd /tmp/ && wget "http://wordpress.org/latest.tar.gz";
    fi

    /bin/tar -C $install_dir -zxf /tmp/latest.tar.gz --strip-components=1
    chown www-data: $install_dir -R

    #### Create WP-config and set DB credentials
    /bin/mv $install_dir/wp-config-sample.php $install_dir/wp-config.php

    /bin/sed -i "s/database_name_here/$db_name/g" $install_dir/wp-config.php
    /bin/sed -i "s/username_here/$db_user/g" $install_dir/wp-config.php
    /bin/sed -i "s/password_here/$db_password/g" $install_dir/wp-config.php

    cat << EOF >> $install_dir/wp-config.php
    define('FS_METHOD', 'direct');
    EOF

    cat << EOF >> $install_dir/.htaccess
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress
    EOF

    chown www-data: $install_dir -R

    ##### Set WP Salts
    grep -A50 'table_prefix' $install_dir/wp-config.php > /tmp/wp-tmp-config
    /bin/sed -i '/**#@/,/$p/d' $install_dir/wp-config.php
    /usr/bin/lynx --dump -width 200 https://api.wordpress.org/secret-key/1.1/salt/ >> $install_dir/wp-config.php
    /bin/cat /tmp/wp-tmp-config >> $install_dir/wp-config.php && rm /tmp/wp-tmp-config -f
    /usr/bin/mysql -u root -e "CREATE DATABASE $db_name"
    /usr/bin/mysql -u root -e "CREATE USER '$db_name'@'localhost' IDENTIFIED WITH mysql_native_password BY '$db_password';"
    /usr/bin/mysql -u root -e "GRANT ALL PRIVILEGES ON $db_name.* TO '$db_user'@'localhost';"

    ######Display generated passwords to log file.
    echo "Database Name: " $db_name
    echo "Database User: " $db_user
    echo "Database Password: " $db_password
    echo "Mysql root password: " $mysqlrootpass