The uploaded file exceeds the upload_max_filesize directive in php.ini

KB ID 0001125 

Problem

When attempting to upload a file to your website, (in my case from within WordPress). You see this error.

Solution

If you are on ‘shared hosting‘ then you may not have access to your php.ini file, if that is the case you should add the following to your .htaccess file, (this will be a hidden file in the root folder of your website).

[box]

#########
php_value upload_max_filesize 50M
php_value post_max_size 50M
php_value max_execution_time 500
php_value max_input_time 500
#########

[/box]

If , (like me), you have your own server, then you will need to edit the php.ini file directly, but where is it? Executing a ‘whereis php.ini‘ command  in my case showed me a few copies in various locations, but which one was live?

I’m assuming your website is installed in /var/www/html, so change the commands if yours is in a different location. I’m going to create a .php file in the root of my website, then browse to this file, it will show me all my .php settings, and tell me where the live copy of php.ini is located.

I use nano, if you don’t have it installed, enter the hell that is the ‘vi editor’ and use that instead 🙂

[box]

nano /var/www/html/info.php

[/box]

Then paste in the following text;

[box]

<?php phpinfo(); ?>

[/box]

Then browse to the info.php file on your website with a web browser, i.e. http://www.your-website.com/info.php. You should see something like this.

You can see that the ‘Loaded Configuration File’ is in /etc/php.ini

WARNING: Now it’s a little bit of a security hole having this sat there, so let’s delete this file on the server with the following command;

[box]

rm /var/www/html/info.php
THEN Enter 'y' to confirm.

[/box]

How To Edit The php.ini File

Execute the following command;

[box]

nano /etc/php.ini

[/box]

Locate Upload_max_filesize and change its setting accordingly, by default it’s only 2MB.

Also change your post size setting, as the default is only 8MB.

Save and exit the file, then restart Apache.

[box]

/sbin/service httpd restart

[/box]

Try to upload your file again.

 

Related Articles, References, Credits, or External Links

NA

Linux – Enable PHP Short Tags

KB ID 0000886 

Problem

I have a particular web page that uses PHP short tags. Post migration from my old hosting company to a dedicated VPS, this stopped working.

As I know little about Linux, and even less about PHP, I asked the question at Experts Exchange about why It was no longer working. I took no time at all, for someone who knew what they were doing to say, “Your code uses ‘Short tags’, but you do not have short tags enabled”

Solution

How To Enable PHP Short Tags From .htaccess

This would be your approach if you were on a hosted web server, and could not access the servers PHP configuration. In the ‘Root’ of your website should be a file called .htaccess you can simply edit this with any text editor (but make sure it does not save with a file extension!).

Add the following lines to the end;

[box]php_value short_open_tag 1
php_value asp_tags 1[/box]

How to Enable Short Tags in PHP

1. Connect to the server via SSH, (or open a terminal session). The file you need to edit is called php.ini. This server is running CentOS, so you should find that file in the /etc/ folder.

2. By default the line you are looking for is 229 (press CTRL+C to show position). Locate the short_open_tag = Off line.

3. Change the entry to ‘On’, and save the changes (CTRL+X and ‘Y’ to save).

4. Restart the web server.

[box]
service httpd restart[/box]

Related Articles, References, Credits, or External Links

NA