Tag Archives: php

PHP display_errors for Dreamhost

DreamHost has recently disabled all PHP warnings by default.

I guess that’s a good idea in a production environment, but I’ve been using Dreamhost for teaching PHP since we left our previous web hosting provider MyServerWorld in 2010.

I’m not sure why Dreamhost decided to change error handling recently, but now my students don’t know where the mistakes in their code are. The fact that this happened just before the main assignment wasn’t great timing.

Dreamhost’s Knowledge Base only shows how to turn on logging into a file, not how to display the error message as before. The following instructions are useful for my BT2201 and BT3023 students, but maybe also for other Dreamhost users.

Turning on display_errors

To see the error message, rather than a generic ‘500 internal server error’ we can change the php.ini file (called phprc on Dreamhost).

  • Every account should see a ‘.php’ folder when logged in via (S)FTP.
  • In that folder, there will be different folders for the different versions of php offered. Currently, that’s everything from 5.3 to 7.2. I assume they are all there because an account can have more than one domain and different domains can be set to run on different versions of php.
  • Add the following line to the top of the phprc file:
display_errors = On


If it didn’t work within a few minutes…

The new settings should come into effect within a few minutes, but if they don’t you can do the following.

To kill off running PHP processes you need to log in via SSH (which my students can’t do) and run

killall -9 php70.cgi

or the appropriate command for the php version used (e.g. php56.cgi instead of php70.cgi).

Alternatively, you can open the ‘Manage Domains’ settings page on Dreamhost’s web interface (something my students can’t do either) and just resave your settings.


Using Docker to localhost PHP and mysql

If we want to run mysql, too, not only php (as shown here), here’s one way of doing it.

It is a bit more complicated. One reason is that the official php apache image doesn’t come with mysql support. Another reason is that you need to find out the IP address of the mysql container.

This is for developing, not for shipping applications.

Running mysql

docker run --name mymysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -e MYSQL_DATABASE=testdb -e MYSQL_USER=testuser -e MYSQL_PASSWORD=testpw -d mysql:8.0

This time I use names, in this case mymysql. It’s easier to set a name so that  we already know the name of the container we want to link to (instead of using a randomly assigned name).

my-secret-pw is the password for the mysql root user, set with MYSQL_ROOT_PASSWORD. In the same way set the following to whatever you like, if needed


You can check at the Docker Hub what mysql versions are available.

Running php

Start php as before, but use

--link mymysql:mysql

in this case mymysql because that’s the name I chose for my mysql.

We can’t use an unmodified image anymore (the official php apache image doesn’t come with mysql support), so we need a Dockerfile or we get a Class ‘mysqli’ not found error.

Create a Dockerfile with the following content

FROM php:7-apache
RUN docker-php-ext-install mysqli

go to folder with Dockerfile, then build, in this case I call is phpwsql

docker build -t phpwsql .

then run

docker run --name myphp70 --link mymysql:mysql -d -p 80:80 -v /pathtofolder/:/var/www/html/ phpwsql

Get the IP address of the mysql container

The mysql and the php containers will have different IP addresses, so localhost won’t work. To get the IP address of the mysql container type

docker inspect mymysql | grep IPAddress

which you can then use in your php code.


At the time of writing this blog post both mysql and php-apache are based on debian:jessie, so there’s not much overhead.