Posts Tagged ‘apache’

How to serve .well-known on Heroku

Saturday, April 22nd, 2017 | Programming

If you want to use Apple Pay on your website, you need to serve a file from inside the .well-known directory. This is a nightmare.

For a start, you can’t create a directory called .well-known on Mac. So you have to find another solution. mod_rewrite to the rescue perhaps? You may be able to get this working, but I couldn’t. I just got a 403 permission denied on Heroku.

client denied by server configuration: /app/public/.well-known

So I decided to try Alias instead.

This was easy to configure on my localhost. I created a directory without the period and then used Alias to map it.

Alias "/.well-known" "/Users/me/Projects/ProjectName/well-known"

To configure it in Heroku, I created a custom Apache configuration file.

Alias "/.well-known" "${HEROKU_APP_DIR}/well-known"

And then configured my Procfile to load this.

web: vendor/bin/heroku-php-apache2 -C heroku-apache.conf public/

So far, so good. Except this didn’t work either because I had not given the directory permission in the Apache config. So I expanded my custom config file.

<Directory "${HEROKU_APP_DIR}/well-known">
    Options FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

This got it working. However, it took my homepage offline. It seems that when you include a custom Apache configuration file, it knocks out the standard DirectoryIndex that Heroku has. Or, there is something else really obviously wrong that I am missing. That’s entirely possible, but I haven’t spotted it yet.

And I did manage to fix it by adding in a new DirectoryIndex to my .htaccess file.

DirectoryIndex index.php

Finally, you have Heroku serving the directory correctly.

PMA_Message not found in phpMyAdmin

Thursday, May 2nd, 2013 | Programming, Tech

You may get an error similar to the following in phpMyAdmin.

PHP Fatal error: Class ‘PMA_Message’ not found in /usr/share/phpMyAdmin/libraries/Message.class.php

This is caused when Apache is unable to create a session – perhaps because of a permissions issue on the session folder, or perhaps because you have run out of disk space.

Restarting Apache on Gentoo

Tuesday, January 29th, 2013 | Life, Tech

Normally, you can restart Apache using the restart command for the init.d script.

/etc/init.d/apache2 restart

However, you may encounter the following error.

chris@server /root $ sudo /etc/init.d/apache2 restart
 * Stopping apache2 ...[ ok ]
 * Starting apache2 ...
 * start-stop-daemon: /usr/sbin/apache2 is already running 

This is due to a bug in the init.d script. You can resolve this with a one line change.

vim /etc/init.d/apache2

Change line 105 for the one below (they should look very similar).

while ( test -f "${PIDFILE}" && pgrep -P ${PID} apache2 >/dev/null ) \

Save it and run the restart command again to check it has worked.

chris@server /root $ sudo /etc/init.d/apache2 restart
 * Caching service dependencies ...                                                                              [ ok ]
 * Stopping apache2 ...                                                                                          [ ok ]
 * Starting apache2 ...

If you get an output like the above, you’ll know it’s worked.

MaxClients (150) is not an integer multiple

Wednesday, January 23rd, 2013 | Life, Tech

Starting Apache on Gentoo, you may get warnings similar to the following.

chris@server ~/lime $ sudo /etc/init.d/apache2 stop
Password: 
 * Stopping apache2 ...
WARNING: MaxClients (150) is not an integer multiple
 of ThreadsPerChild (35), lowering MaxClients to 140
 for a maximum of 4 child processes,
WARNING: MaxClients (25) must be at least as large
 as ThreadsPerChild (35). Automatically
 increasing MaxClients to 35.                                                                                    [ ok ]
chris@server ~/lime $ sudo /etc/init.d/apache2 start
 * Starting apache2 ...
WARNING: MaxClients (150) is not an integer multiple
 of ThreadsPerChild (35), lowering MaxClients to 140
 for a maximum of 4 child processes,
WARNING: MaxClients (25) must be at least as large
 as ThreadsPerChild (35). Automatically
 increasing MaxClients to 35.

You can resolve these warnings by editing your mpm file and changing ThreadsPerChild so that MaxClients becomes a multiple of it. In this case, setting it to 25 should do the trick.

sudo vim /etc/apache2/modules.d/00_mpm.conf

Change the values and save the file. Now restart Apache and it should stop the warnings.

You could also change MaxClients, but this would only resolve the first warning, and not the second.

PHP complains date.timezone is not set

Wednesday, November 28th, 2012 | Programming, Tech

Sometimes, PHP will kick up a fuss complaining about date.timezone not being set. We found this on the Symfony framework and were able to replicate it on standalone scripts.

[Exception]
DateTime::__construct(): It is not safe to rely on the system's timezone settings.
You are required to use the date.timezone setting or the date_default_timezone_set()
function. In case you used any of those methods and you are still getting this
warning, you most likely misspelled the timezone identifier.
We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead

Normally, you would fix this by editing your php.ini file and adding a declaration there.

date.timezone = "Europe/Berlin"

But we had already done this and it still wasn’t working! After some further investigation, it seemed that PHP simply couldn’t access the value.

echo(ini_get("date.timezone"));

This doesn’t make any sense, and we never got to the bottom of what was going on, but there are two ways around the problem. Firstly, you could modify your PHP script so that it makes a call to set the system timezone.

date_default_timezone_set("Europe/Berlin");

However, this involves having to modify your code, which is bad as you don’t want to have to set the timezone manually, especially in a piece of code which could be deployed to servers in different timezones.

A better approach is to set it in the vhosts directive in Apache.

php_value "date.timezone" "Europe/Berlin"

This isn’t the cleanest solution but allowed us to solve an otherwise unexplainable error.

Using Apache Bench to load test your website

Monday, June 25th, 2012 | Life, Tech

Apache comes with a cool load testing script called Apache Bench, which lets you throw loads of requests at a URL. It comes bundled with Apache, so if you’re running the LAMP stack, you probably already have it.

The syntax is simple.

ab -n 1000 http://www.google.com/

This will throw a thousand requests at Google and then produce a report on how long it look. You can also use the -c option to set the number of concurrent requests. There are lots more options too – see the Apache docs for full details.

ImageMagick, Apache and Debian

Thursday, June 7th, 2012 | Life, Tech

Following on from my previous post about installing ImageMagick from source, to get it working with Apache you need to do the following. First, we need to install something from Pecl. So make sure you have the pecl command at hand – if not, install it.

apt-get install pear

Then run the following.

apt-get install php5-dev
pecl install imagick

Finally, add the extension to your php.ini.

extension=imagick.so

Integrating SVN with Apache

Sunday, July 6th, 2008 | Life, Tech

If you want to allow access to SVN via Apache, it’s actually nice and easy to install and configure it on a blank system. First, install Apache.

yum install httpd httpd-devel httpd-manual

Next, install Subversion.

yum install subversion

Now we need to bridge he two.

yum install mod_dav_svn

Once you have done this, we have everything we need. So we can go ahead and edit the Subversion configuration to add the Subversion directory to Apache.

vim subversion.conf

Finally, start and reload Apache, then go about creating your SVN repository.