Optimize your website with a few linux command line tools

When optimizing your website you will notice that images, and static resources are the most delaying the load of your website. You can use numerous tool to optimize them on the fly and cache them in WordPress or Joomla cache. I personally prefer to optimize them for once and save them on the disk.

The latter is requiring some access to the Linux command line and is therefore reserved for the most tech oriented people. I am presenting here some tools: Guetzli and PNGQuant, uglifyJS but there are more available. At this point of time these tools are the best in their category.

Optimizing JPEG files

Guetzli is a Google JPEG encoder that aims for excellent compression density at high visual quality. Guetzli-generated images are typically 20-30% smaller than images of equivalent quality generated by libjpeg. Guetzli generates only sequential (non progressive) JPEG due to faster decompression speeds they offer.

Install it

apt install guetzli # linux
brew install guetzli # macos
# windows user should use binary releases https://github.com/google/guetzli/releases

It is recommended to always do a backup of the folder containing your images, just in case. (real men don’t do backup but they often cries). I run Guetzli recursively in all sub-folder using find

find . -type f -name "*.jpg" -exec guetzli {} {} \;

Optimizing PNG files

pngquant is a command-line utility and a library for lossy compression of PNG images. The conversion reduces file sizes significantly (often as much as 70%) and preserves full alpha transparency. Generated images are compatible with all web browsers and operating systems.

apt install pngquant # linux
wget https://pngquant.org/pngquant.tar.bz2 # macos
# windows user should use binary releases https://pngquant.org/pngquant-windows.zip

I use the same technique, running pngquant recursively in all sub-folder using find

find . -iname "*.png" -exec pngquant -f -ext .png --verbose {} {} \;

Optimizing JavaScript files

Warning: i do not recommend to optimize official files of WordPress or Joomla. Some build int scanner that checksum internal file may detect this changes as a security breach: new code checksum do not match official WordPress expect checksum anymore.
It can be use for plugins and your own custom JavaScript code through.

UglifyJS is a general-purpose JavaScript parser/compressor/beautifier toolkit. 

find . -maxdepth 1 -iname "*.js" -exec uglifyjs --compress --mangle -o {} -- {} \;

Docker essential tools: Dive to navigate docker image content

If you want to explore the content of a docker image, Dive is THE tool for exploring a docker image, layer contents, and discovering ways to shrink the size of your Docker image.

Note that we will be exploring the image not the container: viewing the container and the image are not the same thing. You can get most of the time a bash access to a running container with 

docker run -it image_name sh

Or following for images with an entrypoint

docker run -it --entrypoint sh image_name

NOTE: there is no guarantee that an image will have any sort of interactive shell. many minimal images contain only the binaries necessary to support a service.

An image is not running, consider it like a definition of a future container. You can still view the content, this is possible since each “layerid” directory contains json file describing layer property and filesystem associated with that layer. Docker stores Container images as layers to optimize storage space by reusing layers across images.

Beside Dive, you can also use docker inspect

docker image inspect image_id

But Dive is a lot better as it allow to navigate and see the filesystem changes in a nice norton commander interface.

Features

Show Docker image contents broken down by layer

As you select a layer on the left, you are shown the contents of that layer combined with all previous layers on the right. Also, you can fully explore the file tree with the arrow keys.

Indicate what’s changed in each layer

Files that have changed, been modified, added, or removed are indicated in the file tree. This can be adjusted to show changes for a specific layer, or aggregated changes up to this layer.

Estimate “image efficiency”

The lower left pane shows basic layer info and an experimental metric that will guess how much wasted space your image contains. This might be from duplicating files across layers, moving files across layers, or not fully removing files. Both a percentage “score” and total wasted file space is provided.

Quick build/analysis cycles

You can build a Docker image and do an immediate analysis with one command: dive build -t some-tag .

You only need to replace your docker build command with the same dive build command.

CI Integration

Analyze and image and get a pass/fail result based on the image efficiency and wasted space. Simply set CI=true in the environment when invoking any valid dive command.

To install it:

docker pull wagoodman/dive

then just provide your image tag/id/digest

docker run –rm -it -v /var/run/docker.sock:/var/run/docker.sock wagoodman/dive:latest <your-image>

Get more by visiting the project page https://github.com/wagoodman/dive 

Nginx Specify a Vary: Accept-Encoding header

nginx (pronounced “engine-x”) is an open source Web server and a reverse proxy server for HTTP, SMTP, POP3 and IMAP protocols, with a strong focus on high concurrency, performance and low memory usage. It is licensed under a BSD-like license and it runs on Unix, #Linux, BSD variants, Mac OS X, Solaris, AIX and Microsoft Windows [WikiPedia]

Instructs proxy servers to cache two versions of the resource: one compressed, and one uncompressed. This helps avoid issues with public proxies that do not detect the presence of a Content-Encoding header properly.

Configuration files are provided using Gist  https://gist.github.com/1620307 and are CONSTANTLY updated for added security and speed. Gist is a simple way to share snippets and pastes with others. All gists are git repositories, so they are automatically versioned, forkable and usable as a git repository. I recommend you to starred them to stay up to date.

Continue reading Nginx Specify a Vary: Accept-Encoding header

Apache Maven copy local file to a remote server server using SSH

I will show you in an Apache #Maven configuration file how to copy files to server each time the package phase is executed.

Solution with Ant SCP task

This snippet of code is a ready to use code that make use of Apache Ant task scp, Just put this snippet of code in your #Maven module where the assembly is executed or anywhere else to push all tar.gz files to a server just run a #maven mvn package, you can add as many ant task and push to many server the same file during the reactor build.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <id>server-copy</id>
            <goals>
                <goal>run</goal>
            </goals>
            <phase>package</phase>
            <configuration>
                <target>
                    <echo message="Push to server/home/"/>
                    <scp trust="yes" todir="user:password@server:/home/">
                        <fileset dir="${basedir}/target">
                            <include name="**/*.tar.gz"/>
                        </fileset>
                    </scp>
                </target>
            </configuration>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant-jsch</artifactId>
            <version>1.8.2</version>
        </dependency>
    </dependencies>
</plugin>

Solution with #maven-deploy-plugin

The #maven-deploy-plugin allows you to configure the deploy phase to deploy to a server using scp. There is a page in the documentation that describes how it can be done.

Deploy #maven artifact using Maven Wagon SCP

Another alternative would be to use Maven Wagon SCP like described in this post for example

Vmware Virtual Appliance Ubuntu 11.10 x64 Server

Download and install the latest  VMware Player 4.0.2 to run this Virtual Appliance “Ubuntu 11.10 x64 Server”

ubuntu-logo_0

Ready to user stock #Ubuntu 64 bit Server 11.10 (Oneiric Ocelot) on Vmware

This virtual appliance may be used by multi purpose operations, such as source control management server, development server, ftp server, or for testing some changes before rolling them out against your productive server and so on…

 

 

Download for FREE  #Ubuntu 11.10 x64 Server.7z (2.2GB) for Vmware

From http://linux.waltercedric.com/

  • VM Information
    • CPU’s : 1
    • Memory : 1G
    • Disk : 20G
  • Authentication Credentials
    • Username : user
    • Password : user1234

Continue reading Vmware Virtual Appliance Ubuntu 11.10 x64 Server

Vmware Virtual Appliance Ubuntu 11.10 x64 Desktop

Download and install VMware Player 4.0.2 to run this Virtual Appliance “Ubuntu 11.10 x64 Server”

ubuntu-logo_05

Ready to user stock #Ubuntu 64 bit Desktop 11.10 (Oneiric Ocelot) on Vmware

This virtual appliance may be used by multi purpose operations, such as source control management server, development server, ftp server, and so on…

 

Download for FREE #Ubuntu 11.10 x64 Desktop.7z (4.65GB) for Vmware 

From http://linux.waltercedric.com/

  • VM Information
    • CPU’s : 1
    • Memory : 1G
    • Disk : 20G
  • Authentication Credentials
    • Username : user
    • Password : user1234

Continue reading Vmware Virtual Appliance Ubuntu 11.10 x64 Desktop

Best nginx configuration for Joomla

nginx (pronounced “engine-x”) is an open source Web server and a reverse proxy server for HTTP, SMTP, POP3 and IMAP protocols, with a strong focus on high concurrency, performance and low memory usage. It is licensed under a BSD-like license and it runs on Unix, #Linux, BSD variants, Mac OS X, Solaris, AIX and Microsoft Windows [WikiPedia]

These are my reusable settings for any #Joomla hosting, these are the most secure, and fastest settings to the best of my knowledge.

Configuration files are provided using Gist and are CONSTANTLY updated for added security and speed. Gist is a simple way to share snippets and pastes with others. All gists are git repositories, so they are automatically versioned, forkable and usable as a git repository. I recommend you to starred them to stay up to date.

Joomla.conf for nginx

Create a new directory nginx/conf to be able to place reusable nginx settings:

mkdir -p /etc/nginx/conf
vi /etc/nginx/conf/joomla.conf

Edit or create joomla.conf, you can find the latest joomla.conf documented version in one of my Gist at https://gist.github.com/1620307 https://gist.github.com/1620307.js?file=joomla.conf

Adding a new Joomla Site to nginx

Create required directory anywhere on your disk, here is an example with a domain www.example.com

mkdir -p /var/www/vhosts/example.com/httpdocs mkdir -p /var/www/vhosts/example.com/logs

Set the right permission to the user and group you have defined in nginx.conf

chown -fR www-data:www-data /var/www/vhosts/example.com/httpdocs

Copy the nginx template and adapt to your liking

cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example vi /etc/nginx/sites-available/example

Edit or create example, you can find the latest file example documented version in one of my Gist at https://gist.github.com/1620307 https://gist.github.com/1620307.js?file=www.example.com

this file include Joomla.conf to avoid duplicating nginx settings

Activate the new domain

ln -s /etc/nginx/sites-available/example /etc/nginx/sites-enabled/example
service nginx restart

OSGi-Bundle with the Maven-Bundle-Plugin

OSGi (Open Service Gateway Initiative) is a #Java framework for developing and deploying modular software programs and libraries.OSGi has two parts. The first part is a specification for modular components called bundles, which are commonly referred to as plug-ins. The specification defines an infrastructure for a bundle’s life cycle and determines how bundles will interact.  The second part of OSGi is a #Java Virtual Machine (JVM)-level service registry that bundles can use to publish, discover and bind to services in a service-oriented architecture (SOA).

In this small post, I will show you how to make your first OSGi bundle using the Bundle Plugin for #Maven from Apache Felix

Continue reading OSGi-Bundle with the Maven-Bundle-Plugin

Mysql database backup in Linux Crontab

Here is the easiest way to run a daily backup of your database using linux crontab. Thanks to our everyday increasing mailbox size (Thanks Gmail) and their nature to be quite safe for saving document, let’s use them to store the full backup of all our Mysql database!

Requirements

  • Having a shell access to your linux box
  • Creating a user with limited mysql rights: SELECT and LOCK_TABLES is enough, For example a user backup_user with a password ChhdeqyqUzd75687fOnmYar
  • Installing Mpack: Tools for encoding/decoding MIME messages. Mpack and munpack are utilities for encoding and decoding (respectively) binary files in MIME (Multipurpose Internet Mail Extensions) format mail messages. For compatibility with older forms of transferring binary files, the munpack program can also decode messages in split-uuencoded format.

Edit your crontab

crontab -e 

and put inside on one line the following

0 1 * * * /usr/bin/mysqldump -ubackup_user –pChhdeqyqUzd75687fOnmYar yourdb |
gzip > /database_`date +'%m-%d-%Y'`.sql.gz ;
mpack -s "Databases backup"
-c application/gzip /database_`date +'%m-%d-%Y'`.sql.gz email@gmail.com

You can replace the word yourdb with your tablename or –all-databases to dump all database. With the above line a backup will be run at 1AM every day and sent in your mailbox.

Joomla! 1.5.22 Released

Joomla_Logo

From the official press release

The #Joomla Project announces the immediate availability of #Joomla 1.5.22 [senu takaa ama woi]. This is a security release, and we recommend users upgrade immediately.

The Development Working Group’s goal is to continue to provide regular, frequent updates to the #Joomla community.

Download

You can also download these files from my Unofficial Miror of Joomla! files (nearly 1000 files with all versions of all #Joomla! are available)

http://mirror.waltercedric.com