Script in BASH Install Ubuntu 16.04 PHP 5.6

apt-get update -y
apt-get upgrade -y
apt-get install -y apache2
apt-get install -y mysql-client mysql-server
apt-get install -y git

apt-get install -y mc

apt-get install -y zip

apt-get install -y curl

apt-get install software-properties-common

add-apt-repository ppa:ondrej/php
apt-get update

apt-get install -y php5.6 libapache2-mod-php5.6 php5.6-cli php5.6-common

apt-get install -y php5.6-mbstring php5.6-gd php5.6-intl php5.6-xml php5.6-mysql

apt-get install -y php5.6-mcrypt php5.6-zip php5.6-curl php5.6-gd php5.6-soap apt-get install -y php5.6-ldap php5.6 php5.6-xmlrpc php5.6-xsl
a2enmod ssl rewrite

apt-get install phpmyadmin

service apache2 restart

curl -sS https://getcomposer.org/installer | sudo php — –install-dir=/usr/local/bin –filename=composer

 

Script in BASH Install Ubuntu 16.04 PHP 7.0

This will install Common libraries for php 7.0, last version of mysql and phpmyadmin

#/bin/bash/

apt-get update -y
apt-get upgrade -y
apt-get install -y apache2
apt-get install -y mysql-client mysql-server
apt-get install -y aspell aspell-en aspell-he
apt-get install -y ghostscript
apt-get install -y graphviz
apt-get install -y clamav
apt-get install -y git
add-apt-repository ppa:ondrej/php

apt-get update -y

apt-get install -y php7.0 libapache2-mod-php7.0 php7.0-cli php7.0-common

apt-get install -y php7.0-mbstring php7.0-gd php7.0-intl php7.0-xml php7.0-mysql

apt-get install -y php7.0-mcrypt php7.0-zip php7.0-curl php7.0-gd php7.0-soap

apt-get install -y php7.0-ldap php7.0 php7.0-xmlrpc php7.0-xsl php7.0-pspell
a2enmod ssl rewrite
apt-get install -y libreoffice
apt-get install -y phpmyadmin
apt-get install -y unoconv
apt-get install -y mc

apt-get install -y mc

service apache2 restart

sudo echo “<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName webnetkit.com
DocumentRoot /var/www/webnetkit
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>” > /etc/apache2/sites-available/webnetkit.conf

a2ensite your-domain.conf

curl -sS https://getcomposer.org/installer | sudo php — –install-dir=/usr/local/bin –filename=composer

Cron Backups for Moodle Db and Moodledata

Create directory /var/backups

mkdir /var/backups
crontab -e

Add Database backup to the cron file:

#Backup Database (Before each day starts, backup Moodle prod DB from MySQL/MariaDB)
4 4 * * * root mysqldump dbname -u user -ppsaaword | gzip > /var/backups/moodle-db-`date +\%Y-\%m-\%d-\%H-\%M-\%S`.sql.gz

Add moodledata backup to the cron file:

4 10 * * * zip -r /var/backups/moodledata-`date +\%Y-\%m-\%d-\%H-\%M-\%S`.zipĀ  /var/www/moodledata

 

Save 30 lasts backups

# Keep 30 SQL database backups and moodledata backups (last 30 backups of moodle)
 2 2 * * * find /var/backups/* -mtime +10 -exec rm {} \;

 

Moodle upload custom file in PHP

How to upload custom file Moodle function

 if(isset($_FILES['imageactivity']) && !empty($_FILES['imageactivity'])){ 
 $file_url = $_FILES['imageactivity']['tmp_name'];
 $file_content = file_get_contents($file_url);
 $file_name = $_FILES['imageactivity']['name'];
 
 
 $fs = get_file_storage();
 $draftitemid = file_get_unused_draft_itemid(); 
 $contextid_local = 70;
 
 // Prepare file record object
 $fileinfo = array(
 'contextid' => 165, // ID of context 165
 'component' => 'user', // usually = table name
 'filearea' => 'draft', // usually = table name
 'itemid' => $draftitemid, // usually = ID of row in table 0
 'filepath' => '/', // any path beginning and ending in /
 'userid' => $USER->id,
 'source' => $file_name, 
 'filename' => $file_name); // any filename
 
 // Create file containing content
 $fs->create_file_from_string($fileinfo, $file_content); 
 
 file_prepare_draft_area($draftitemid, $contextid_local, 'local_metadata', 'image', 0); 
 file_save_draft_area_files($draftitemid, $contextid_local, 'local_metadata', 'image', $draftitemid); 
 }