Fix ‘403 Forbidden’ error on Apache 2.4 HTTP server in Ubuntu

In the latest versions (specifically version 2.4.3 and above) of the Apache 2.4 HTTP server, on a new installation, you may receive the ‘403 Forbidden’ HTTP error when attempting display your site.  To increase security, the Apache developers changed the default configuration to block all requests.  To fix this, you must explicitly grant permissions via your site configuration file.

In Ubuntu Linux, you will need to edit the appropriate site configuration file.  Typically, the name of this file is 000-default.conf and it is located in /etc/apache2/sites-available directory. Open this file in a text editor (remember to open it using sudo, since it is a system file) and add the following line in the <Directory> section:

Require all granted

For example, the updated <Directory> section may now look like:

        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
                Require all granted
        </Directory>

To make this change take effect, you must restart the Apache web server using this command:

sudo service apache2 restart

References

Stack Overflow – Apache VirtualHost 403 Forbidden

Increase session time-out in phpMyAdmin

If you do any development with PHP and MySQL, undoubtedly, you are familiar with phpMyAdmin, which is a web-based tool for managing and editing MySQL databases. While phpMyAdmin is an excellent tool, one of it’s annoying aspects is the default session time-out of 30 minutes. However, you can make a quick configuration change to extend the time-out to most any value that you like.

To do this, just open the config.inc.php file for phpMyAdmin (which is in the /etc/phpmyadmin directory on Ubuntu Linux) in an editor as the administrative user (i.e., use sudo in Linux). Then, add these lines within the 'Servers' configuration section:

/* Set session time out to 8 hours (28800 seconds) */
$cfg['Servers'][$i]['LoginCookieValidity'] = 28800;

Save the changes and restart the Apache web server:

sudo service apache2 restart

The next time that you log into phpMyAdmin, you will stay logged in for 8 hours (or whatever duration you specified). For more information, see phpMyAdmin documentation for LoginCookieValidatity.

Install latest version of Adminer MySQL administration tool on Ubuntu Linux

Adminer is a lightweight, PHP-based MySQL administration tool that is a great alternative to PHPMyAdmin. It comes as a single file and can easily be installed globally on your Ubuntu Linux box, including a Vagrant box.

The prerequisites for installing and using Adminer are PHP, MySQL, and Apache, the so-called LAMP stack. To install them on Ubuntu, in the terminal, run:

sudo apt-get install php5 php5-cli php 5-mysql mysql-server apache2

You’ll be prompted for configuration information during the installation.

Once the LAMP stack is installed, install Adminer by running these commands in the terminal:

sudo mkdir /usr/share/adminer
sudo wget -O /usr/share/adminer/latest.php "http://www.adminer.org/latest.php"
sudo ln -s /usr/share/adminer/latest.php /usr/share/adminer/adminer.php
echo "Alias /adminer.php /usr/share/adminer/adminer.php" | sudo tee /etc/apache2/conf.d/adminer.conf
sudo service apache2 restart

After installing Adminer, open a web browser and navigate to http://localhost/adminer.php. The Adminer login screen should be displayed. You can now log in to any of the MySQL databases configured.

If you want to upgrade to a new version of Adminer later, since you created a symlink to the latest.php, you can simply run this command in the terminal:

sudo wget -O /usr/share/adminer/latest.php "http://www.adminer.org/latest.php"

Prevent upgrade of (“lock” version) specific packages in Debian/Ubuntu Linux

In many cases, you may need to preserve the current version of a package in Debian or Ubuntu Linux. For example, your production environment may use an older version of a package and, in your development environment (perhaps on a Vagrant virtual machine), you want to make sure you use the same version. The apt package manager provides functionality to “lock” (or, as it’s called in Debian/Ubuntu, to “hold”) the version of a package. The command is simple:

sudo apt-mark hold package_name

where package_name is the name of the package, such as grub-pc. You can include multiple package names on the command line by separating each with a space.

For more information, see the Ubuntu help topic on apt “pinning”.

Use PHP array_map() function to remove white space from array elements

One common scenario in PHP is take an input list, such as some search criteria entered by a user, and tokenize the input into individual items using a separator, such as comma. The PHP explode() function works great for splitting up the individual values into an array(). However, if have white space before or after the separator, each of the elements of the new array will contain that white space. You could use a foreach loop, with the $key => $value syntax to apply the trim() function to each item. But PHP has the perfect function already built in: array_map().

array_map() takes a callback function as its first argument and an array as the second argument. It applies the specified callback function to each element of the array that is passed in. You simply provide the name of the callback function as a string (either in single or double quotes) and the function can be a function within your code or any of the built-in PHP functions. For example, to put all of the pieces together, you could do something like this:

$input = "apricot, banana, cherry, dewberry, eggplant, fig";
$output_trimmed = array_map("trim", explode(',', $input));

Make your .bash_profile aliases available anywhere

Bash aliases are one of the truly great timesavers when working in Unix/Linux. I’ve picked up quite a few aliases from others on my travels around the Internet and many have become second nature. Moreover, in quite a few cases, I’ve (almost) forgotten the original command!

Lately, I’ve done a lot of development work using Vagrant and, honestly, I’d never want to go back to trying to set up development environments on individual machines, since Vagrant makes standardization so simple. At the same time, even though my Vagrant box is pretty well standardized, everyone probably has their on bash aliases that they like to use. So, here’s how to have the best of both worlds!

What we want to do is provide a simple way to grab our bash aliases from Github and apply them from most any machine.

  1. Put your bash aliases (or any other bash settings!) into a file a file named .bash_alias and add this file to your Github account. The conventional practice is to put these in a repository named dotfiles.
  2. Determine the “raw git” URL to your new .bash_alias on Github. Essentially, this URL starts with https://raw.githubusercontent.com/ and then follows the standard pattern for Github URLs of your username, repository name, branch, and file name. For example, my .bash_aliases “raw” URL is https://raw.githubusercontent.com/TimothyDJones/dotfiles/master/.bash_aliases.
  3. Now, here’s where all of the magic happens! When you want to apply your aliases on a machine that you are logged into, such as a Vagrant box, just run this command at the shell:
    curl https://raw.githubusercontent.com/TimothyDJones/dotfiles/master/.bash_aliases -o /tmp/.bash_aliases; source /tmp/.bash_aliases
    

    Viola! All of your aliases are now available on this machine. And, of course, you can add this command to your .bash_profile on that machine, so that it will run automatically everytime you log in.

Note: When dealing with your Unix/Linux configuration files (“dotfiles”), it is very important to pay attention to the line endings of your files. Windows and Unix/Linux use different conventions. The best way to account for this is to set the autocrlf parameter in the dotfile repository on your workstation by running:

git config core.autocrlf true

Install FFmpegYAG in Ubuntu 14.10 (Utopic Unicorn) 64-bit

FFmpegYAG is in excellent audio/video encoder/decoder (converter) GUI front-end for ffmpeg that uses wxWidgets. The latest version (0.7.5) includes a Debian package, but it is built/configured for Ubuntu 14.04 (Trusty Tahr)/Linux Mint 17. Nevertheless, you can install it in Ubuntu 14.10 (Utopic Unicorn) by installing a few dependent packages from Ubuntu 14.04.

Download the amd64 architecture versions of the following packages from Ubuntu 14.04:

Download FFmpegYAG from the Sourceforge site.

Copy all of the downloaded Debian packages into an empty directory (such as ffmpegyag).

In the terminal navigate to the directory where you saved all of the files (e.g., ffmpegyag) and run this command:

sudo gdebi *.deb

You will be prompted to install the various packages and choose ‘Y’ for each prompt.

After completing the installation, you should now have a FFmpegYAG menu item in the Multimedia Ubuntu menu.