I make websites.

Welcome to Alastair Mucklow's website. Browse my portfolio of web design and development projects - then hire me!

Increase PHP memory limit on Slicehost

The simultaneously daunting and great thing about Slicehost is the control it gives developers over their server setup. I’m very much a novice at server admin, but today I learned something new.

I needed to increase the memory limit for PHP because my WordPress Next Gen gallery plugin was throwing failure errors when attempting to batch-resize thumbnails. Why 33MB of memory is required to resize a 100KB image is anyone’s guess – but there was no way around it.

To change files situated above the /www level in your server tree, or to change folder permissions, you need to access your server via ssh, then switch to the root user. It’s really easy, but it’s incredible how long it’s taken me to learn this. Thanks to Sam Oliver for helping the penny drop.

For info the server I’m using is Apache on Ubuntu.

Gaining root access

Typically, when using Terminal, you will not be able to do:

$ ssh root@your-domain.com

You have to start by going in as another user with non-root privileges, e.g.

$ ssh joe@your-domain.com

I guess it depends what users you have created on the server in the first place – I don’t know, I didn’t set mine up.

Once you’ve logged in as joe with joe’s password, you can then type:

# su

then [ENTER], then your root password. You should then see something like:

root@your-domain:/home/dir#

Modifying php.ini

If you have sftp access to your server, then you can find out where php lives on your server. Or, again, you can use Terminal. First of all, type:

# cd

to return to the topmost root level. Now type:

# cd /etc/php5/apache2
# ls

This list command should bring up a list of files in the apache2 folder: conf.d and php.ini. Now type:

# sudo pico php.ini

The php.ini file will now be displayed inside Terminal. You can key down and edit the line:

memory_limit = 16M      ; Maximum amount of memory a script may consume (16MB)

Increase it to 48M. Finally, you need to restart Apache by typing:

# /etc/init.d/apache2 restart

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">