Category Archives: Linux

SVG to PNG conversion with transparent background in ImageMagick

Here’s a quick way to convert SVG to PNG with transparent background

convert -background none image.svg image.png

Adjust size

If you want to scale the image to a larger size without antialiasing (which makes the image look fuzzy), you can add the density parameter, like this:

convert -density 200 -background none image.svg image.png

Simply increase the density value to increase the image size.

To install ImageMagick on OS X with Homebrew:

brew install imagemagick

For Ubuntu:

sudo apt-get install imagemagick

Display output of multiple log files with tail

To show the output from all log files in a directory, run:

tail -f *.log

Output example:

==> log1 <==
1.2.3.4 - - [16/Nov/2014:03:31:06 +0000] "GET /robots.txt HTTP/1.1" 200 107
1.2.3.4 - - [16/Nov/2014:03:31:07 +0000] "GET / HTTP/1.1" 200 7777
1.2.3.4 - - [16/Nov/2014:03:36:05 +0000] "GET /robots.txt HTTP/1.1" 200 107

==> log2 <==
1.2.3.4 - - [16/Nov/2014:05:39:36 +0000] "GET / HTTP/1.1" 200 34569
1.2.3.4 - - [16/Nov/2014:05:40:44 +0000] "POST /wp-admin/ HTTP/1.0" 200 961
1.2.3.4 - - [16/Nov/2014:05:40:57 +0000] "POST /wp-admin/ HTTP/1.0" 200 50505

Best Apache VirtualHost configuration for PHP projects

Here is an example of an Apache VirtualHost config that provides your site with security through open_basedir and writes both a regular access log, as well as a PHP error log.

<VirtualHost *:80>
ServerName      example.com
ServerAlias     www.example.com

DocumentRoot    /var/www/html/example.com

php_admin_value open_basedir /var/www/html/example.com

CustomLog       /var/log/httpd/example.com-access.log common
ErrorLog        /var/log/httpd/example.com-error.log
</VirtualHost>

Note
In order for open_basedir to work with file uploads, you need to add the following to your php.ini configuration file:

upload_tmp_dir = /tmp

I’m always looking to improve this configuration – send me a comment if you have a better version!

Debian LAMP stack in one command

Start out with the basics – Apache, MySQL and PHP + extensions

apt-get install mysql-server mysql-client apache2 php5 php5-cli libapache2-mod-php5 php5-mysql php5-curl php5-gd php-pear php5-imagick php5-mcrypt php5-memcache php5-mhash php5-sqlite php5-xmlrpc php5-xsl php5-json php5-dev libpcre3-dev

I recommend using this on Debian Jessie. That way you get a bleeding edge version of PHP (5.5.8 as of right now)

OpCode cache and APCu (Optional)

pecl install ZendOpcache-beta
pecl install apcu-beta

Add the following to /etc/php5/apache2/php.ini

zend_extension=opcache.so
extension=apcu.so

Configure Opcache by adding this to /etc/php5/apache2/php.ini

opcache.max_accelerated_files=30000
opcache.memory_consumption=160
opcache.revalidate_freq=0

Restart apache. The extensions should be available and configured. (You can verify this via phpinfo(); )

Useful tools (Optional)

apt-get install htop vim

PHP 5.5 on Raspbian Raspberry Pi

php 5.5.8

Raspberry pi runs Debian Wheezy, but with just one quick line change we can upgrade to Debian Jessie which is a newer version and provides PHP 5.5 binaries (5.5.8 at the time of this blog post.)

Start out by editing the APT sources:

vim /etc/apt/sources.list

Change wheezy to jessie, so that it looks like this:

deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi

(Don’t add or remove any lines, just change the one above)

Now run:

apt-get update && apt-get upgrade && apt-get autoremove

If you havent aready installed PHP, you can do it now via:

apt-get install php5 php5-cli

Finally, confirm your PHP version:

php -v

This should result in:

PHP 5.5.8-2 (cli) (built: Jan 18 2014 07:39:52)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies

Installing EPEL and Remi repo on CentOS 6

Install the repos with the following commands:

wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
sudo rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm

Now, enable the Remi repo to be always enabled by editing:

sudo vim /etc/yum.repos.d/remi.repo

Set:

enabled=1

…on the topmost repo (right under the [remi] tag).

That’s it!

Source