Tag Archives: Patches

WordPress multisite in subfolder

If you install wordpress in a subfolder like /home/example/public_html/wordpress instead of the main DocumentRoot ( usually /home/example.com/public_html ) you will not be able to enable multisite functionality but with a few small changes to wordpress code you can make it work.

My goal was to have the main site ( example.com ) with multisite, host blogs on subdomains like dom1.example.com and then use domain mapping so I could map a domain like dom1.com to dom1.example.com.

Here are the steps I took:

  1. Extract wordpress-3.1.3.zip in /home/example.com/public_html/wordpress, go to went to http://example.com/wordpress and install, then login as admin to http://example.com/wordpress/wp-admin
  2. In wp-admin -> Settings both WordPress address (URL) and Site address (URL) were set to http://example.com/wordpress, change Site address (URL) to http://example.com
  3. copy index.php and .htaccess from /home/example.com/public_html/wordpress to /home/example.com/public_html/
  4. open /home/example.com/public_html/index.php in an editor and changed the line:
    require('./wp-blog-header.php'); to require('./wordpress/wp-blog-header.php');
    At this point you have a working wordpress installed in a subfolder accessible at http://example.com
  5. Open wp-config.php and insert the following lines at the top ( can be right after the first line )
    define('WP_ALLOW_MULTISITE', true);
  6. Open the file wordpress/wp-admin/network.php in a text editor, look for the line: "function network_step1" and a few lines bellow there should be a line:
    1. span style="color: #ff0000;">'siteurl''home' ) ) {

    , replace it with

    1. span style="color: #ff0000;">'siteurl''home' ) ) {
  7. Now go to http://example.com/wordpress/wp-admin/network.php and create your network.
  8. After you create the network, WordPress will ask you to add a few lines to wp-config.php but you'll have to modify them a bit. Here's what I added:
    1. span style="color: #ff0000;">'MULTISITE''SUBDOMAIN_INSTALL'// default was false
    2. '/'; // default was /wordpress/
    3. 'DOMAIN_CURRENT_SITE', 'example.com''PATH_CURRENT_SITE', '/wordpress''SITE_ID_CURRENT_SITE''BLOG_ID_CURRENT_SITE', 1 );

    By default SUBDOMAIN_INSTALL was set to false but you want subdomains, and $base was set to "/wordpress" but this needs to be "/"

    Don't forget to also add the required lines to .htaccess ( the one in the wordpress/ directory )

  9. After the network was created, wordpress messed up a bit with the permalink settings for the main domain. Before, the permalink structure was set to: /%year%/%monthnum%/%day%/%postname%/ and wordpress changed it to /blog/%year%/%monthnum%/%day%/%postname%/.
    But after I added the above lines to wp-config.php I was able to change the permalink structure back to what it was from Settings->Permalinks
  10. Adding domains

    Go to Network admin ( http://example.com/wordpress/wp-admin/network/ ) -> Sites -> Add new . I added
    an example domain dom1.example.com. This is what I'll use as an example from now on.

    After I added the domain I went to Sites , clicked the Edit link bellow the domain and changed Path from / to /wordpress ( with the option "Update siteurl and home as well" checked ) then go to the Settings tab and change the Home to http://dom1.example.com/
    At this point you have a working wordpress installed in a subfolder with multisite configured with subdomains.

  11. Install the domain mapping plugin with my changes
    1. span style="color: #ff0000;">'SUNRISE', 'on' );

    right after the first line

  12. got to Network Admin -> Tools -> Domain Mapping to configure the plugin and add the mappings
  13. Come back and let me know how it worked in the comments

Webmin 1.480: Bulk add ip addresses

A few months ago I published a patch for webmin that would allow you to easily add a lot of ip addresses to an interface in webmin. At that time I mentioned that the patch could only be applied on webmin 1.410.

Now I needed this patch again but this time on webmin 1.480 so I adapted it to work with the new version.

For usage instructions please see the original post

You can download the new version here: [download id="11" format="1"]

Notes

This only works for interfaces activated at boot. The code could easily be copied to work with the other interfaces too but I didn't see a use for that.

After you add the ip addresses ( aliases ) you have to go to the list of interfaces, select the newly added interfaces and click the "Apply selected interfaces" button if you want the new aliases to be activated without having to reboot.

realtek 8180 on kernel 2.6.23

To make RealTek 8180 wireless cards work in Linux you need the open source drivers from rtl8180-sa2400. Actually this driver supports more realtek cards not just 8180, you can get the list of supported devices from their homepage.

The only problem with those drivers is that they are a bit outdated. They were initially build sometime in 2005 at a time when the kernel version was 2.6.12 . Since then there were patches released to make those drivers work with newer kernels and the latest patch I found was for kernel 2.6.22.You can download the patch from sourceforge . I downloaded that and it just complied and installed without problems.

I loaded the following kernel modules in the exact order :

  1.  

At this point I got the card working but there was no security. I knew this card supports WEP encryption and I was trying to set up a link between the card and a linksys WRT54G router that can also do WEP. When I tried to set a key (WEP ) I the card told me setting a key was not supported by hardware and I got the following error in dmesg: rtl_ieee80211_crypt_wep: could not allocate crypto API arc4

This was very weird because I knew I already loaded the arc4 crypto module . Then why doesn't it work?
After digging a bit in the code I realize that the ecb module is also needed for kernel versions higher then 2.6.15.

After I loaded the ecb module I was able to set a key with iwconfig and the link was up.

To summarize...
in order get this driver working you have to compile your kernel with the following options:

-> Networking
-> Networking support (NET [=y])
-> Wireless
-> Improved Wireless API

for the wireless tools ( iwconfig ) to work
Device Drivers
-> Wireless LAN
I'm not sure if this one is really needed cause the rtl8180 drivers user their own 802.11 stack but it doesn't hurt to enable it as a module, and if you have other wireless devices or you want to ue your card as a host ap you may need tis anyway.

From the Cryptographic API make sure you select ARC4 and ECB

After you compile the kernel you need to load the modules like this:

  1.  

bring up the interface :

  1.  

and set the ESSID and key with iwconfig in order to connect it with the Access point

  1. span style="color: #ff0000;">"your_Access_poing_ESSID"

If everything went well you should see something like: wlan0 802.11b linked when typing iwconfig
Next i will try to configure this card to be used as a Host AP.
Did any of you try that ? feel free to share your experiences in the comments.

Update:

There is a new project that forked the rtl8180 driver and ported it to the new 802.11 stack in 2.6.23 kernel. This new project was already included in 2.6.23 but at the moment only support for  rtl8185 is available. The project is rtl-wifi and you might want to watch their page for when they add support for 8180

More optimization for comment relish plugin

In my previous post about optimizing the comment relish plugin I managed to lower the load generated by the comment relish plugin on the database server by adding an index on a column in the cr_emailed table and by optimizing a query ( basically removing a "useless?" join ). This improved the load time a lot but some users still reported slow load times on blogs with a lot of comments.

Looking more over the source code I realized that the function that tried to find new commentators was executed on each page. This function was executing a mysql query that joined two tables wp_comments and wp_cr_emailed. I think you can imagine the result of this on blogs with a large number of comments.

The solution was to execute this function only when a new comment was posted. And this comes with two benefits:

  1. because this is called only when a new comment is posted ( or approved ) the rest of the blog will remain as fast as before the plugin was installed.
  2. because of the way we call the function ( as an action/hook associated with the code that processes the comments ) we have more information about the comment so we don't have to do the query where we join two tables. We still do one query to get the whole comment data and one to see if this is a new commentator ( not emailed yet ) but these use indexes and are really fast.

Get the new optimized plugin here and let me know how it works for you.

Update:

the plugin link above contains a plugin that tries to send email even when the blog receives a pingback or trackback as reported by Rhys. I have uploaded another version that corrects this problem here: [download id="9" format="1"]

WordPress optimal title

I'm using Aaron Schaefer's Optimal title wordpress plugin to modify the way wordpress displays the title by default. This plugin provides a function similar to wp_title() but your title will not contain "blog archive" in front of your post's title and this is good for seo.

You will have to modify your header template and replace the call to wp_title with a call to optimal_header().
In a previous post I presented a plugin for integrating Jerome's keywords plugin with google sitemaps, this post will show you how to integrate it with the optimal title plugin.

Continue reading WordPress optimal title

squid outgoing ip patch

Some time ago a client of mine was running squid on a system with multiple interfaces and ips. He wanted a setup where squid would use the same ip on which it received the connection to create the connection to the destination server for fetching the content.

Let's say we have 3 ips 1.1.1.1, 1.1.1.2 and squid listens on both interfaces. Now if a client would connect to the proxy server on ip 1.1.1.1 and request google.com, squid will use 1.1.1.1 to make the connection to google. If the client will connect to 1.1.1.2 squid will use 1.1.1.2 to connect to the destination server.

Continue reading squid outgoing ip patch

PHP pecl freebsd port bug

A bug exists in the pecl cli script on freebsd that will not permit you to install any pecl package.

The problem is that the pecl script needs pcre.so but the script calls php with -n ( don't use php.ini ) so the pcre.so extension is not loaded.

A quick fix is to edit /usr/local/bin/pecl and remove "-n" from the last line so it will look like
exec $PHP -C -q $INCARG -d output_buffering=1 -d safe_mode=0 -d register_argc_argv="On" $INCDIR/peclcmd.php "$@"

I found this bug when I wanted to install the svn extension but it seems the bug is known for some time and there is a patch for it : http://www.freebsd.org/cgi/query-pr.cgi?pr=110209

freebsd 7.0 outperforms linux

The development version of FreeBSD ( 7.0 ) seems to scale a lot better then linux on SMP systems.

A combination of latest freebsd scheduler ULE 2.0 that is built into FreeBSD 7.0, the libthr threading library and a patch (not commited, yet ? ) that addresses poor scalability of file descriptor locking and some other patches is what made a system with 8 core amd64 cpu and 16 GB of ram outperform linux by a factor of 4 in MySQL tests.

The tests were performed using sysbench OLTP benchmark, a tool designed for testing mysql performance.

Brief test results: Linux is actually a little ( ~ 2% ) faster then FreeBSD for less then 9 clients, but when the number of clients grows to 20 linux performance drops a lot and FreeBSD's performance stays the same.

More details about the test here:

http://people.freebsd.org/~kris/scaling/mysql.html

first freebsd 6.2 bugs found

Just one day after the release and we have the first bugs that show up in the FreeBSD errata.

bug #1 Some isolated crashes were reported for arcmsr, the driver for Areca ARC-11xx and ARC-12xx series of SATA II RAID controllers. This problem is still being investigated. Users that have problems are advised to consider backing out the driver update or installing a version of this driver directly from Areca

bug #2 is a kernel bug related to Unix domain sockets. A patch for this problem has been committed to HEAD and RELENG_6, and is a candidate for an errata patch to RELENG_6_2 after further testing.

bug #3 was observer on systems with heavy network activity. the problem seems to be with the kernel memory allocator. A partial workaround for this problem is to add the following line to /boot/loader.conf and reboot:

kern.ipc.nmbclusters="0"

More details about the bugs in this release on Errata

freebsd securelevel setup

FreeBSD securelevel is a security mechanism implemented in the kernel that restricts certain tasks depending on the level that is active. Not even the super user will be able to bypass this mechanism if well setup.

From securelevel man page :

-1 Permanently insecure mode - always run the system in level 0 mode.
This is the default initial value.

0 Insecure mode - immutable and append-only flags may be turned off. All devices may be read or written subject to their permissions.

1 Secure mode - the system immutable and system append-only flags may not be turned off; disks for mounted file systems, /dev/mem, and /dev/kmem may not be opened for writing; kernel modules (see kld(4)) may not be loaded or unloaded.

2 Highly secure mode - same as secure mode, plus disks may not be opened for writing (except by mount(2)) whether mounted or not. This level precludes tampering with file systems by unmounting them, but also inhibits running newfs(8) while the system is multiuser.

In addition, kernel time changes are restricted to less than or equal to one second. Attempts to change the time by more than this will log the message ``Time adjustment clamped to +1 second''.

3 Network secure mode - same as highly secure mode, plus IP packet filter rules (see ipfw(8) and ipfirewall(4)) cannot be changed and dummynet(4) configuration cannot be adjusted.

Continue reading freebsd securelevel setup