• Resolved rgilman

    (@rgilman)


    I’m setting up a mirror to my main WP site. Sphinx works on the main site but fails to start on the mirror site. Both sites are on Debian/Linux servers.

    When I attempt to start searchd from the command line I get:

    ERROR: error executing '/usr/bin/php -q' in /home/.../wp-content/uploads/sphinx/etc/sphinx.conf line 1 col 1.
    FATAL: failed to parse config file '/home/.../wp-content/uploads/sphinx/etc/sphinx.conf'

    (The … is to obscure the path in this post. The actual error message has the right path.)

    This is with the exact same ‘sphinx.conf’ file that works fine on the main site.

    I have tested whereis php and it is at /usr/bin/php.
    I have run this with /usr/bin/php5 -q and get the same result.
    I have installed sphinx 2.0.4 separately, and also can not start it with either the above config file or with the supplied test config file.
    I have executed sphinx.conf. I get no output from the standard file, but get a test output when I insert an echo line into sphinx.conf for test purposes, so php-cli appears to be working fine.

    This seems to be an recurring issue for this plugin. I have read all of the previous related topics and done a lot of google searching and have yet to find a solution. I am hoping that one of the Ivinco guys has some ideas beyond those already in the previous topics since I have already run through those.

    Looking forward to some help.
    Thanks

    http://wordpress.org/extend/plugins/wordpress-sphinx-plugin/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter rgilman

    (@rgilman)

    Good news. I have Sphinx working on the mirror site. I had put wp-config.php one level up (for security reasons) on the mirror but not on the main site. My WP install is at the site root, so that meant that wp-config.php was above/outside the site root and it seems that apache/php wouldn’t read the file (at least not through sphinx.conf).

    With wp-config.php back down at the site root with 640 permissions and the apache user as part of the group, it works.

    The fact that the error cites line 1 col 1 wasn’t helpful in my case. I had no problem with the path to php or the form of the #!/usr/bin/php -q. These are certainly worth checking, but from my experience you also need to check that apache/php can actually read wp-config.php.

    I would love to know a modification that could be made to sphinx.conf (or whatever the solutions) that would allow wp-config.php to be placed above the site root. WordPress manages to read the file when it is above the site root, so there must be a way.

    Hope my experience can be helpful to others.

    Thread Starter rgilman

    (@rgilman)

    I have done some more debugging and think I now have the core problem that was causing Sphinx to fail when wp-config.php was one level up from the site root.

    There is a problem in the php in sphinx.conf. This code is modeled on the code in wp-load.php where it looks like this:

    /** Define ABSPATH as this file's directory */
    define( 'ABSPATH', dirname(__FILE__) . '/' );
    
    error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR );
    
    if ( file_exists( ABSPATH . 'wp-config.php') ) {
    
    	/** The config file resides in ABSPATH */
    	require_once( ABSPATH . 'wp-config.php' );
    
    } elseif ( file_exists( dirname(ABSPATH) . '/wp-config.php' ) && ! file_exists( dirname(ABSPATH) . '/wp-settings.php' ) ) {
    
    	/** The config file resides one level above ABSPATH but is not part of another install */
    	require_once( dirname(ABSPATH) . '/wp-config.php' );
    
    }

    In the sphinx.conf template (in wordpress-sphinx-plugin/rep/) the start of the corresponding code looks like this:

    #!{path_to_php} -q
    <?php
    error_reporting(0);
    $path_to_config = "{path_to_wp_config_php}";
    if ( file_exists( $path_to_config . '/wp-config.php') ) {
    ...

    So ABSPATH gets replaced by $path_to_config. Unfortunately, wp-config.php needs ABSPATH once it is loaded in because at the end of wp-config.php is:

    /** Absolute path to the WordPress directory. */
    if ( !defined('ABSPATH') )
    	define('ABSPATH', dirname(__FILE__) . '/');
    
    /** Sets up WordPress vars and included files. */
    require_once(ABSPATH . 'wp-settings.php');

    If wp-config.php is one level up and ABSPATH hasn’t been defined, then the ‘IF’ defines ABSPATH based on where wp-config.php is. There is no wp-settings.php one level up so the ‘require_once’ fails.

    A simple solution that works for me is to add “define(‘ABSPATH’…” to sphinx.conf:

    #!{path_to_php} -q
    <?php
    error_reporting(0);
    $path_to_config = "{path_to_wp_config_php}";
    define('ABSPATH', $path_to_config . '/');
    if ( file_exists( $path_to_config . '/wp-config.php') ) {
    ...

    You could likely make the code tighter by eliminating $path_to_config and using ABSPATH in its place (and adjusting for the trailing ‘/’).

    You only need to make this change if you want to put wp-config.php one level up, or want to have the flexibility to do so in the future. It would be good to make the change in the template (wordpress-sphinx-plugin/rep/). If you have already activated the plugin and run the wizard, you should also find sphinx.conf in your sphinx directory (likely in uploads) and make the change there.

    BTW, for debugging this issue it was a great help to turn on the error_reporting used in wp-load.php. I then ran a sphinx command from the command line and got a lot more helpful information than just ‘error executing ‘/usr/bin/php -q’ status = 255 in /home/…/sphinx/sphinx.conf line 1 col 1′.

    Hope this helps

    Plugin Author Ivinco

    (@ivinco)

    Hello, rgilman

    You wrote: “Sphinx works on the main site but fails to start on the mirror site.”

    So, as we understood: 1) – you want to have the main site and its mirror and they are placed on different servers and the both use Sphinx Search Plugin 2) – you tried to run Sphinx on the both servers (this failed on the mirror host with the config from the main site) and 3) – you put the sphinx configuration file one level higher than ‘htdocs’ (apache document root) on the mirror 4) – you fixed 3) by changing the code of sphinx.conf

    For point 1):

    In this case it’s not necessary to run indexing separately on the both servers. You can work with the same searchd instance both on the main site and on its mirror host. This allows you to have fully synchronized content on the both servers because the

    same set of indexes will be used on the main site and on the mirror.

    To make WP Sphinx Search Plugin use a remote connection from the mirror host do as follows:

    a) Run “Start” and go to the “Set sphinx connection” section. b) If your main site’s host is for example 20.20.20.20 and the port where sphinx is listening for queries is 15555 fill the form fields with the following values:

    Host name or IP address: 20.20.20.20 Port: 15555

    press “Save&continue”, then proceed to the other steps and press “OK” in the end.

    c) You don’t need to start Sphinx daemon on the mirror host if you configure the WP plugin there to work with a remote connection to the main host.

    For point 3),4) You can use the option “Set up path to sphinx indexes” to set up the directory higher than ‘htdocs’. That will be the place your sphinx.conf and indexes will be saved to.

    If you still have questions, please ask.
    You’re welcome.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: WordPress Sphinx Search Plugin] ERROR: error executing '/usr/bin/php -q'’ is closed to new replies.