My blog has moved!

You should be automatically redirected. If not, visit
http://benohead.com
and update your bookmarks.

Showing posts with label Wordpress. Show all posts
Showing posts with label Wordpress. Show all posts

Sunday, April 22, 2012

Wordpress: ALERT - script tried to increase memory_limit to 268435456 bytes which is above the allowed value

Today I found the following in /var/log/user.log:

xxx xx xx:xx:xx xxxxxx suhosin[21100]: ALERT - script tried to increase memory_limit to 268435456 bytes which is above the allowed value (attacker 'xxx.xxx.xxx.xxx', file '/var/www/vhosts/xxxxxx/httpdocs/wp-admin/admin.php', line 109)

Line 109 in admin.php contains the following:

@ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );

I am the "attacker" (it's my IP address shown in the alert). The error seems to occur regularly when I'm open the Dashboard.

My memory limit in PHP is set to 128MB:

# grep memory_limit /etc/php5/apache2/php.ini
memory_limit = 128M

The memory limit set by Wordpress (WP_MAX_MEMORY_LIMIT) is define in wp-includes/default-constants.php:

# grep -R WP_MAX_MEMORY_LIMIT *
...
wp-includes/default-constants.php: define( 'WP_MAX_MEMORY_LIMIT', '256M' );
...

And it is too high since the limit set in PHP is only half this.

Since default-constants.php, only sets WP_MAX_MEMORY_LIMIT is not set in wp-config.php:



        if ( ! defined( 'WP_MAX_MEMORY_LIMIT' ) ) {
                define( 'WP_MAX_MEMORY_LIMIT', '128M' );
        }

You can just add the following to your wp-config.php:

define('WP_MAX_MEMORY_LIMIT', '128M');


And now I do not see this error message in user.log when opening the Dashboard.



If you cannot see your Dashboard anymore, it probably means the value you've set for WP_MAX_MEMORY_LIMIT is too low (this happened when I first set it to 32M).


Note: Of course you could also increase the PHP limit to 256M instead of 128M. But I didn't want to do it since we have many things running with PHP and I wanted to use the fix with the least impact on our server.

Wednesday, April 11, 2012

Wordpress: qtranslate: Clicking on the home link resets to the default language

I have a wordpress-based web site which is both in French and English. In order to be able to handle the two version easily I'm using the qtranslate plugin (a great plugin by the way !).

Almost everything worked fine. The only issue I found was that if I clicked on my logo I was going to the appropriate home page but if I clicked on "Home" in the navigation menu, I was going to the home page in the default language.

I've setup qTranslate to have such URLs:
  • xxxx.com/fr/contact/ for the French contact page.
  • xxxx.com/en/contact/ for the English contact page.
  • Since French is the default language on this site, xxxx.com/contact is also taking you to the French contact page.

So basically you start on the French home page, click around and keep seeing the French version of the pages. Then change the language to English, click around and keep seeing the English version of the pages. But when you click on "Home", instead of going to xxxx.com/en/, you go to xxxx.com/fr/ which then switches you back to the French site.

After a lot of googling, code reading and trying various stuff, I finally figured out a solution:

qTranslates installs a filter for all wordpress hooks related to displaying posts/pages or navigating to make sure that you see the right page. But it looks like no filter is installed for 'home_url'. Just adding it solved the problem.

In order to fix it, go to Plugins > Editor. Choose qTranslate. Then open the file qtranslate/qtranslate_hooks.php. Scroll down. At the end of the file, you'll see a bunch of add_filter(...); calls. Add there the following:

add_filter('home_url', 'qtrans_convertURL');

Save the file and enjoy clicking on the Home menu item without having the language reset to default !

Sunday, January 2, 2011

Install Wordpress on Mac OS X

In this post, I'll explain how to install Wordpress locally on a Mac OS X machine.

First you'll need to download the following:



XAMPP is an Apache distribution containing MySQL, PHP and Perl. It makes it much easier to install them. The Mac OS X package can be downloaded from here.

After downloading it, open the dmg archive and just drag the XAMPP folder to the Application folder to install it.



XAMPP will host our web folder and using the XAMPP console, we'll be able to start/stop Apache HTTPd and MySQL.

First let's start Apache HTTPd and MySQL:

Go to the Application folder, open the XAMPP folder and start "XAMPP Control":


Now start both Apache and MySQL.
When starting Apache, you might be asked to authenticate. This will be required everytime you start or stop Apache.
If starting Apache fails, you'll need to open the system preferences (Apple-Menu / System Preferences...) and choose Sharing (in Internet & Wireless) and disable Web sharing:


You should then be able to start the Apache web server.

If you get a message stating it wasn't possible to start MySQL because it's already running, you will need to either uninstall existing installations of MySQL or not have them start automatically. Here's what I did on my system in order to do it:

ps -Af | grep sql | grep -v grep | awk '{ print $2; }' | xargs sudo kill -9
This will kill all running instances of MySQL.
Then I've edited /etc/hostconfig and removed the line MYSQLCOM=-YES-
Then the following:
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
After that I was able to start MySQL from the XAMPP console.

Wordpress

Open phpMyAdmin which is part of XAMPP: http://localhost/phpmyadmin
 

There you need to create a database in MySQL for Wordpress using the following settings:


After clicking Create, the database you need for wordpress will be created.

Now you need to deploy Wordpress in XAMPP:
Download Wordpress from http://wordpress.org/latest.zip
Extract the file (double-click) and copy the wordpress directory to /Applications/XAMPP/htdocs:


Now you need to update the configuration of Wordpress to connect to our MySQL database. Open /Applications/XAMPP/htdocs/wordpress/wp-config.php and make the following changes:


Now you just need to open the installation of Wordpress by going to the following URL: http://localhost/wordpress/wp-admin/install.php