Joomla

From Newroco Tech Docs
Revision as of 10:43, 18 January 2018 by Lucian.pricop (talk | contribs) (→‎Find images not used by Joomla)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Install

  • Install the packages: apache2 php5 php5-gd
  • Install mysql-server and php5-mysql, take note of the root password
  • Download the latest Joomla archive and extract all the code in /var/www/
  • chown -R root:www-data /var/www
  • chmod -R g+w /var/www
  • sudo -i && mysql
  • vim .my.cnf and paste the code below putting in the real root password. This will enable you to login as mysql root without the password
[mysqldump]
user=root
password=<the root password>
[mysql]
user=root
password=<the root password>
  • sudo vim /etc/php5/apache2/php.ini - edit the maximum file size to 5MB
  • Create database and db role
create database <db name>
grant all privileges on <db name>.* to '<role name>'@'localhost' identified by '<role password>';
  • Go to the web interface and follow the online instructions using the database name, role name and role password defined in the previous step.
  • If this is a migration to a much newer version now is the perfect time to use SP Transfer plugin to take all the articles, menus, etc from the old website.
  • Check everything worked correctly before making any changes to the menus or articles otherwise the transfer will have to be done once more, but to a fresh install of Joomla!
  • Follow the mysql DB backup procedure here.
  • Enable .htaccess from Joomla Admin
  • Enable mod_rewrite in Apache:
 sudo a2enmod RewriteEngine
 sudo /etc/init.d/apache2 restart
  • Copy the template, discover it and install it from the Admin interface

File Permissions

Set the permissions for your Joomla folders to 755
Set the permissions for your Joomla files to 644
Set the permissions for your configuration.php file to 444
Never use 777(full access) permissions!

If root is owner and www-data as group, 664 is in order for files.

chown -R root:www-data /var/www
chmod -R 664 /var/www
chmod 444 /var/www/configuration.php

Access MYSQL

sudo -i && mysql

Recommended packages

  • Adaptive Images - it will feed to the browser an image better suited for smaller screens automatically.

Recommended plugins

  • OA Contacts - built for OA to display all staff added to the back end as contacts
  • OA Projects - built for OA to display all projects from a specified category in a nice list
  • Simple Transition Gallery - displays in a nice transition images and captions with animations
  • Simple Image Gallery (by JoomlaWorks) - a nice way to display all the photos from a folder
  • Ultimate Feed Display - displays a feed in a module, it can be from the same website
  • Social Backlinks plugin - makes publishing articles to Facebok, twitter and linkedin easy
  • JCE Editor - a much better WYSIWYG editor than TinyMCE
  • GoSquared Plugin - for tracking on GoSquared
  • Kunena - for forums
  • Joes Word Cloud + Lucian's multi colour hack - shows a random list of words from articles of a certain category ina nice tag cloud
  • Simple Email Form - for sending e-mails from a form on the website.
  • jHackGuard - a Joomla 2.5/3.0 security plugin developed by SiteGround. With this plugin your Joomla is protected against the most popular hacking attacks - SQL Injections, Remote URL/File Inclusions, Remote Code Executions and XSS Based Attacks!

Basic and frequent Joomla procedures

  • Login to the back end by going to http://<public website url>/administrator
  • Manage users (add, change name, password) from Users->"User manager" when connected to the back end.
  • When fearing hackers all Joomla files can be locked from writing and unlocked only when installing new plugins. When everything is locked, the media manager can not upload new photos, so to temporarily unlocking it you'd have to give write permissions to the media folder which usually is <website doc root>/images . Provided that www-data is the group of all the files in /var/www do this while connected with ssh
sudo chmod -R g+w /var/www/images

and when done with the media manager

sudo chmod -R g-w /var/www/images

On the current website the procedure should be this (paths accurate)

sudo chmod -R g+w /var/www/www.oxfordarchaeology.com/images

and when done with the media manager

sudo chmod -R g-w /var/www/www.oxfordarchaeology.com/images
  • Never ever upgrade Joomla on production VMs, a lot of people complain about unsuspected basic functions missing after minor upgrades!!!


Prepare for update

We need to make a backup of all files, a backup of the database, then make sure your account has write access to files and allow www-data to write to all files.

sudo rm /var/lib/db_backups/joomla*.tar.gz
sudo tar -zcpf /var/lib/db_backups/joomla<currdate>.tar.gz /var/www/html
sudo -i && mysql
sudo /opt/bin/mysql_backup.sh --nosleep
sudo chown -R <your user name>:www-data /var/www/html/*
sudo chmod -R g+w /var/www/html/*

Now you can go to Control Panel, and update first Joomla, then all plugins that require updates.

Restore saved version

This assumes your CWD is the web server's folder

sudo rm -R *
sudo tar -zxpf /var/lib/db_backups/joomla<currdate>.tar.gz 
sudo mv var/www/html/* ./
sudo rm -R var
sudo gunzip /var/lib/db_backups/<database name>.gz 
sudo -i && mysql
mysql
create database <database name>2; --or another version number if it's been through a restore before
grant all privileges on <database name>2.* to '<user name>'@'localhost' identified by '<password>'; --you can obtain these details from configuration.php
mysql <database name>2 < /var/lib/db_backups/<database name>.sql
--update joomla configuration.php with the new database name
--check that all pages work correctly, no errors, no warnings, etc
--if everything checks out
drop database <database name>;

After update or restore

sudo chmod -R g-w /var/www/html/administrator/
sudo chmod -R g+w /var/www/html/administrator/cache/
sudo chmod -R g-w /var/www/html/bin
sudo chmod -R g-w /var/www/html/cli
sudo chmod -R g-w /var/www/html/components/
sudo chmod -R g-w /var/www/html/includes/
sudo chmod -R g-w /var/www/html/language/
sudo chmod -R g-w /var/www/html/layouts/
sudo chmod -R g-w /var/www/html/libraries/
sudo chmod -R g-w /var/www/html/modules
sudo chmod -R g-w /var/www/html/plugins
sudo chmod -R g-w /var/www/html/templates/
sudo chmod -R g+w /var/www/html/cache
sudo chmod g-w /var/www/html/index.php
sudo chmod g-w /var/www/html/configuration.php
sudo chmod g-w /var/www/html/.htaccess

Find images not used by Joomla

The file below deletes the files found by jfindfiles.sh not used in any aticle not recommended to run before scrutinising the list of not used files!

#!/bin/bash

if [ -z "$1" ]; then
    echo -e "Usage: $(basename $0) FILE\n"
    exit 1
fi

if [ ! -e "$1" ]; then
    echo -e "$1: File doesn't exist.\n"
    exit 1
fi

while read -r line; do
    [ -n "$line" ] && rm -- "$line"
done < "$1"

Save the below as jfunctions.sh in the Joomla root folder - run this first to configure some parameters needed by jfindfiles.sh

#!/bin/sh

# jfunctions - general bash functions for use in Joomla bash scripts
# Supports Joomla versions 2.5 - 3.x
#
# Copyright 2014 - 2016 Rene Kreijveld - r.kreijveld@dsd.nu
#
# This program is free software; you may redistribute it and/or modify it.
#
# Version history
# 3.0 Initial version
# 3.1 Code rewrite
# 3.2 Modification of all echo -e statements and remove backticks
# 3.3 Update to support Joomla 3.5
# 3.4 Dropped support for Joomla versions lower than 2.5

# Define general variables
version=3.4

# Check if configuration.php exists.
if [ ! -e ./configuration.php ]
	then
	echo ""
	echo "File configuration.php not found. Are you at the root of the site?"
	echo ""
	exit 1
fi

# Find MySQL Socket
if [ -S /var/lib/mysql/mysql.sock ]; then
	mysock=/var/lib/mysql/mysql.sock
elif [ -S /var/run/mysqld/mysqld.sock ]; then
	mysock=/var/run/mysqld/mysqld.sock
elif [ -S /Applications/MAMP/tmp/mysql/mysql.sock ]; then
	mysock=/Applications/MAMP/tmp/mysql/mysql.sock
elif [ -S /tmp/mysql.sock ]; then
	mysock=/tmp/mysql.sock
fi

# Grab information from Joomla 2.5/3.x configuration.
sitename=$(grep '$sitename =' ./configuration.php | cut -d \' -f 2 | sed 's/ /_/g')
sitenameclean=$(grep '$sitename =' ./configuration.php | cut -d \' -f 2)
database=$(grep '$db =' ./configuration.php | cut -d \' -f 2)
dbuser=$(grep '$user =' ./configuration.php | cut -d \' -f 2)
password=$(grep '$password =' ./configuration.php | cut -d \' -f 2)
host=$(grep '$host =' ./configuration.php | cut -d \' -f 2)
prefix=$(grep '$dbprefix =' ./configuration.php | cut -d \' -f 2)
versr=$(grep 'RELEASE =' ./libraries/cms/version/version.php | cut -d \' -f 2)
versd=$(grep 'DEV_LEVEL =' ./libraries/cms/version/version.php | cut -d \' -f 2)
verss=$(grep 'DEV_STATUS =' ./libraries/cms/version/version.php | cut -d \' -f 2)

Save the below as jfindfiles.sh in the Joomla root folder - this searches the database for all files in Joomla folders and finds which are linked to and which are not. It produces two text files with these file names: {sitename}-used.txt {sitename}-notused.txt

#!/bin/sh

# jfindfiles -- Find used and unused content files in your Joomla website
#
# This scripts supports Joomla versions 2.5 - 3.x
#
# Copyright 2014 Rene Kreijveld - email@renekreijveld.nl
#
# This program is free software; you may redistribute it and/or modify it.
#
# 
# Warning! This script needs the file jfunctions. This has to be installed in the same directory as this script.
#

# general variables
mypath=$(cd $(dirname ${0}); pwd -P)
myname=$(basename ${0})

# include general functions
. ${mypath}/jfunctions.sh

# version
version=2.2

# Setup Vvariables
start=./images
curdir=`pwd`

echo "Creating database dump..."

# Dump the database to a .sql file
if mysqldump --skip-opt --add-drop-table --add-locks --create-options --disable-keys --lock-tables --quick --set-charset --host=${host} --user=${dbuser} --password=${password} ${database} > ${database}.sql
then
	echo "Database dump ${database}.sql created."
else
	echo "Error creating database dump."
	exit 1
fi

dbdump=${curdir}/${database}.sql
usedfile=${curdir}/${sitename}-used.txt
notusedfile=${curdir}/${sitename}-notused.txt
echo "The following files were mentioned in your Joomla database:" > ${usedfile}
echo "The following files were NOT mentioned in your Joomla database:" > ${notusedfile}
echo "Checking for used and unused files..."

# Move into the images/stories directory
cd ${start}
# Find all files and check if they are mentioned in the database dump
for file in `find . -type f -print | cut -c 3- | sed 's/ /#}/g'`
do
	file2=`echo $file | sed 's/#}/ /g'`
	file3=`echo $file | sed 's/#}/%20/g'`
	if grep -c "$file2" ${dbdump} > 0; then 
		echo $file2 >> ${usedfile} 
	elif grep -c "$file3" ${dbdump} > 0; then 
		echo $file3 >> ${usedfile} 
	else 
		echo $file3 >> ${notusedfile} 
	fi 
done

# Move back to the root of the website
cd ${curdir}

# Cleanup database dump
rm ${dbdump}

# Report findings
echo "Files checking done."
echo "Check the following text-files for results:"
echo "${usedfile}"
echo "${notusedfile}"



Below is an older stand alone script for the same task, but with inline configuration

#!/bin/bash

# jfindfiles -- Find used and unused content files in your Joomla website
#
# This scripts supports Joomla versions 2.5 - 3.x
#
# Copyright 2014 Rene Kreijveld - email@renekreijveld.nl
#
# This program is free software; you may redistribute it and/or modify it.
#

# Setup Vvariables
database=website
sitename=website
start=./images
curdir=`pwd`

echo "Creating database dump..."

# Dump the database to a .sql file
if mysqldump --skip-opt --add-drop-table --add-locks --create-options --disable-keys --lock-tables --quick --set-charset ${database} > ${database}.sql
then
        echo "Database dump ${database}.sql created."
else
        echo "Error creating database dump."
        exit 1
fi


dbdump=${curdir}/${database}.sql
usedfile=${curdir}/${sitename}-used.txt
notusedfile=${curdir}/${sitename}-notused.txt
echo "The following files were mentioned in your Joomla database:" > ${usedfile}
echo "The following files were NOT mentioned in your Joomla database:" > ${notusedfile}
echo "Checking for used and unused files..."

# Move into the images/stories directory
cd ${start}
# Find all files and check if they are mentioned in the database dump
for file in `find . -type f -print | cut -c 3- | sed 's/ /#}/g'`
do
	file2=`echo $file | sed 's/#}/ /g'`
	file3=`echo $file | sed 's/#}/%20/g'`
	result1=`grep -c "$file2" ${dbdump}`
	result2=`grep -c "$file3" ${dbdump}`
	if [[ $result1 = 0 ]]; then
		if [[ $result2 = 0 ]]; then
			echo $file2 >> ${notusedfile}
		else
			echo $file2 >> ${usedfile}
		fi
	else
		echo $file2 >> ${usedfile}
	fi
done

# Move back to the root of the website
cd ${curdir}

# Cleanup database dump
rm ${dbdump}

# Report findings
echo "Files checking done."
echo "Check the following text-files for results:"
echo "${usedfile}"
echo "${notusedfile}"