Postfixadmin is not working with Postgres - php

I am new to both postgres and postfix, I decided to use to postfixadmin with Postgres to gain so hands on, I have ran through detailed steps mentioned in different websites, and I have checked another working installation of Postgres (but without postfixadmin), but whenever I accessing the setup.php for postfixadmin from http://mydomain.com:8080 I am getting:
Error: Can't connect to database
Please edit the $CONF['database_*'] parameters in config.inc.php.
DEBUG INFORMATION:
Connect: failed to connect to database.
I configured the postfixadmin to use initially postfix user, but as the postfix is created by default as no login user, so I created another user called admin and changed this in config.inc.php as well, but I am still getting the same error
Here are the user created on the system related to this stuff:
# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
postgres:x:26:26:PostgreSQL Server:/var/lib/pgsql:/bin/bash
admin:x:500:500::/home/admin:/bin/bash
Here am I configuring the user admin in Postgres:
# su - postgres
-bash-4.1$ template1
-bash: template1: command not found
-bash-4.1$ template1#
-bash: template1#: command not found
-bash-4.1$ psql template1
psql (8.4.18)
Type "help" for help.
template1=# CREATE USER admin WITH PASSWORD 'complexpassword';
CREATE ROLE
template1=# GRANT ALL PRIVILEGES ON DATABASE postfix to admin;
GRANT
template1=# \q
-bash-4.1$ logout
Here are the configuration of the Postgres:
-bash-4.1$ psql
psql (8.4.18)
Type "help" for help.
postgres=# \list
List of databases
Name | Owner | Encoding | Collation | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postfix | postfix | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/postfix
: postfix=CTc/postfix
: admin=CTc/postfix
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postgres
(4 rows)
Here is postgresql.conf:
#cat postgresql.conf
listen_addresses = 'localhost' # what IP address(es) to listen on;
port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
shared_buffers = 32MB # min 128kB
synchronous_commit = off # optimization
log_destination = 'stderr' # Valid values are combinations of
logging_collector = on # Enable capturing of stderr and csvlog
log_directory = 'pg_log' # directory where log files are written,
log_filename = 'postgresql-%a.log' # log file name pattern,
log_truncate_on_rotation = on # If on, an existing log file of the
log_rotation_age = 1d # Automatic rotation of logfiles will
log_rotation_size = 0 # Automatic rotation of logfiles will
datestyle = 'iso, mdy'
lc_messages = 'en_US.UTF-8' # locale for system error message
lc_monetary = 'en_US.UTF-8' # locale for monetary formatting
lc_numeric = 'en_US.UTF-8' # locale for number formatting
lc_time = 'en_US.UTF-8' # locale for time formatting
default_text_search_config = 'pg_catalog.english'
Here I am testing user admin:
# su - admin
$ psql -d postfix -U admin
psql (8.4.18)
Type "help" for help.
postfix=> exit
postfix-> \q
Here I am testing postfix user (nologin):
# su - postfix
This account is currently not available.
Here is the config.inc.php for postfixadmin:
<?php
$CONF['configured'] = true;
$CONF['setup_password'] = 'complexpassword';
$CONF['postfix_admin_path'] = dirname(__FILE__);
$CONF['default_language'] = 'en';
$CONF['database_type'] = 'pgsql';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'admin';
$CONF['database_password'] = 'complexpassword';
$CONF['database_name'] = 'postfix';
$CONF['database_port'] = '5432';
$CONF['database_prefix'] = '';
$CONF['database_tables'] = array (
'admin' => 'admin',
'alias' => 'alias',
'alias_domain' => 'alias_domain',
'config' => 'config',
'domain' => 'domain',
'domain_admins' => 'domain_admins',
'fetchmail' => 'fetchmail',
'log' => 'log',
'mailbox' => 'mailbox',
'vacation' => 'vacation',
'vacation_notification' => 'vacation_notification',
'quota' => 'quota',
'quota2' => 'quota2',
);
$CONF['admin_email'] = 'postmaster#mydomain.com';
$CONF['smtp_server'] = 'localhost';
$CONF['smtp_port'] = '25';
$CONF['encrypt'] = 'md5crypt';
$CONF['authlib_default_flavor'] = 'md5raw';
$CONF['min_password_length'] = 5;
$CONF['generate_password'] = 'NO';
$CONF['show_password'] = 'NO';
$CONF['page_size'] = '10';
$CONF['default_aliases'] = array (
'abuse' => 'abuse#mydomain.com',
'hostmaster' => 'hostmaster#mydomain.com',
'postmaster' => 'postmaster#mydomain.com',
'webmaster' => 'webmaster#mydomain.com'
);
$CONF['domain_path'] = 'NO';
$CONF['domain_in_mailbox'] = 'YES';
$CONF['maildir_name_hook'] = 'NO';
maildir_name_hook example function
Called by create-mailbox.php if $CONF['maildir_name_hook'] == '<name_of_the_function>'
- allows for customized maildir paths determined by a custom function
- the example below will prepend a single-character directory to the
beginning of the maildir, splitting domains more or less evenly over
36 directories for improved filesystem performance with large numbers
of domains.
Returns: maildir path
function maildir_name_hook($domain, $user) {
$chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$dir_index = hexdec(substr(md5($domain), 28)) % strlen($chars);
$dir = substr($chars, $dir_index, 1);
}
$CONF['aliases'] = '10';
$CONF['mailboxes'] = '10';
$CONF['maxquota'] = '10';
$CONF['quota'] = 'NO';
$CONF['quota_multiplier'] = '1024000';
$CONF['transport'] = 'NO';
$CONF['transport_options'] = array (
);
$CONF['transport_default'] = 'virtual';
$CONF['vacation'] = 'NO';
$CONF['vacation_domain'] = 'autoreply.hassans.nl';
$CONF['vacation_control'] ='YES';
$CONF['vacation_control_admin'] = 'YES';
$CONF['alias_control'] = 'NO';
$CONF['alias_control_admin'] = 'NO';
$CONF['special_alias_control'] = 'NO';
$CONF['alias_goto_limit'] = '0';
$CONF['alias_domain'] = 'YES';
$CONF['backup'] = 'YES';
$CONF['sendmail'] = 'YES';
$CONF['logging'] = 'YES';
$CONF['fetchmail'] = 'YES';
$CONF['fetchmail_extra_options'] = 'NO';
$CONF['show_header_text'] = 'NO';
$CONF['header_text'] = ':: Postfix Admin ::';
$CONF['show_footer_text'] = 'YES';
$CONF['footer_text'] = 'Return to mail.mydomain.com';
$CONF['welcome_text'] = <<<EOM
Hi,
Welcome to your new account.
EOM;
$CONF['emailcheck_resolve_domain']='YES';
$CONF['show_status']='NO';
$CONF['show_status_key']='NO';
$CONF['show_status_text']=' ';
$CONF['show_undeliverable']='NO';
$CONF['show_undeliverable_color']='tomato';
$CONF['show_undeliverable_exceptions']=array("unixmail.domain.ext","exchangeserver.domain.ext","gmail.com");
$CONF['show_popimap']='NO';
$CONF['show_popimap_color']='darkgrey';
$CONF['show_custom_domains']=array("subdomain.domain.ext","domain2.ext");
$CONF['show_custom_colors']=array("lightgreen","lightblue");
$CONF['recipient_delimiter'] = "";
$CONF['create_mailbox_subdirs_prefix']='INBOX.';
$CONF['used_quotas'] = 'NO';
$CONF['new_quota_table'] = 'NO';
$CONF['xmlrpc_enabled'] = false;
}
Here are the php packages installed:
#rpm -qa| grep php
php-common-5.3.3-26.el6.x86_64
php-pgsql-5.3.3-26.el6.x86_64
php-xmlrpc-5.3.3-26.el6.x86_64
php-cli-5.3.3-26.el6.x86_64
php-5.3.3-26.el6.x86_64
php-gd-5.3.3-26.el6.x86_64
php-pear-1.9.4-4.el6.noarch
php-imap-5.3.3-26.el6.x86_64
php-xml-5.3.3-26.el6.x86_64
php-pdo-5.3.3-26.el6.x86_64
php-mbstring-5.3.3-26.el6.x86_64
Here are the checks showing that the Postgres is listening to posrt 5432:
#netstat -an|grep 5432
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN
unix 2 [ ACC ] STREAM LISTENING 12136 /tmp/.s.PGSQL.5432
# telnet localhost 5432
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
^]
telnet> quit
Connection closed.
But What is really strange as well when I try to run the setup.php page I can see the following:
# netstat -an| grep 5432
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:45445 127.0.0.1:5432 TIME_WAIT
unix 2 [ ACC ] STREAM LISTENING 12136 /tmp/.s.PGSQL.5432
The Postgres' log contains:
LOG: could not connect to Ident server at address "127.0.0.1", port 113: Connection refused
FATAL: Ident authentication failed for user "postfix"
LOG: could not connect to Ident server at address "127.0.0.1", port 113: Connection refused
FATAL: Ident authentication failed for user "postfix"
LOG: could not connect to Ident server at address "127.0.0.1", port 113: Connection refused
FATAL: Ident authentication failed for user "postfix"
LOG: could not connect to Ident server at address "127.0.0.1", port 113: Connection refused FATAL:
Ident authentication failed for user "admin"
And the pg_hba.conf is:
local all all ident
host all all 127.0.0.1/32 ident
host all all ::1/128 ident
Can someone guide me what is wrong?

Find in the pg_hba.conf(this file is in the same directory as the postgresql.conf) a line starting with "host", containing "127.0.0.1/32" in it and ending with "ident" and change the "ident" to "md5". Reload/restart Postgres.

Related

PHP PDO, Ubuntu, MDBTools Problems connecting to Access Database

I am having trouble debugging a connection to an MSAccess 2010 .accdb file.
I'm running a Scotch Box Vagrant vm (v3.5) and have installed the MDBTools odbc driver via sudo apt-get install mdbtools.
My /etc/odbcinst.ini file looks like this:
# To enable unixODBC tracing, add this section to odbcinst.ini.
# Include the [ODBC] section heading.
[ODBC]
Trace = yes
TraceFile = /var/www/unixODBC.log
[MDBTools]
Description=MDBTools Driver
Driver=/usr/lib/x86_64-linux-gnu/odbc/libmdbodbc.so
Setup=/usr/lib/x86_64-linux-gnu/odbc/libmdbodbc.so
FileUsage=1
UsageCount=1
I've also created a datasource in /etc/odbc.ini
[CONTACTS]
Driver = MDBTools
Description = Contacts Database
Database = /data/contacts-db.accdb
Server = localhost
The test php file I'm using to attempt a connection is called testMSACCESS.php and looks like this:
<?php
try {
$dbFile = '/data/contacts-db.accdb';
echo 'Does file exist at ' . $dbFile . '? ';
var_dump(file_exists($dbFile));
var_dump(file_exists($dbFile));
echo 'Is the file readable ? ';
var_dump(is_readable($dbFile));
echo 'Is the file writable ? ';
var_dump(is_writable($dbFile));
$dbh = new PDO("odbc:Driver=MDBTools;DBQ={$dbFile};");
// or $dbh = new PDO("odbc:Driver=MDBTools;DSN=CONTACTS;");
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if ($dbh){
echo "success <br/>";
}
$dbh = null;
}catch (Exception $e){
echo '<pre>';
echo 'Exception caught: could not connect to database.' . PHP_EOL;
echo (string) $e;
echo '</pre>';
}
The db file, contacts-db.accdb, is in a dir at the root of the machine /data.
When I try to connect by loading the script in a browser, the Exception thrown looks like this:
Does file exist at /data/contacts-db.accdb? bool(true)
Is the file readable ? bool(true)
Is the file writable ? bool(true)
Exception caught: could not connect to database.
PDOException: SQLSTATE[00000] SQLDriverConnect: 0 in /var/www/public/testMSACCESS.php:6
Stack trace:
#0 /var/www/public/testMSACCESS.php(6): PDO->__construct('odbc:Driver=MDB...')
#1 {main}
When running the script via the cmd line, I get a bit more info:
vagrant#scotchbox:~$ php /var/www/public/testMSACCESS.php
Does file exist at /data/contacts-db.accdb? bool(true)
Is the file readable ? bool(true)
Is the file writable ? bool(true)
Unknown Jet version.
File not found
Unable to locate database /data/contacts-db.accdb
<pre>Exception caught: could not connect to database.
PDOException: SQLSTATE[00000] SQLDriverConnect: 0 in /var/www/public/testMSACCESS.php:6
Stack trace:
#0 /var/www/public/testMSACCESS.php(6): PDO->__construct('odbc:Driver=MDB...')
#1 {main}</pre>
And this is what the unixODBC trace log looks like:
[ODBC][1515][1536073973.983218][__handles.c][460]
Exit:[SQL_SUCCESS]
Environment = 0x5591139d5d60
[ODBC][1515][1536073973.985108][SQLSetEnvAttr.c][189]
Entry:
Environment = 0x5591139d5d60
Attribute = SQL_ATTR_ODBC_VERSION
Value = 0x3
StrLen = 0
[ODBC][1515][1536073973.985588][SQLSetEnvAttr.c][363]
Exit:[SQL_SUCCESS]
[ODBC][1515][1536073973.990811][SQLSetEnvAttr.c][189]
Entry:
Environment = 0x5591139d5d60
Attribute = SQL_ATTR_CP_MATCH
Value = (nil)
StrLen = 0
[ODBC][1515][1536073973.991928][SQLSetEnvAttr.c][363]
Exit:[SQL_SUCCESS]
[ODBC][1515][1536073973.992707][SQLAllocHandle.c][375]
Entry:
Handle Type = 2
Input Handle = 0x5591139d5d60
[ODBC][1515][1536073973.993173][SQLAllocHandle.c][493]
Exit:[SQL_SUCCESS]
Output Handle = 0x5591139d6400
[ODBC][1515][1536073973.993682][SQLSetConnectAttr.c][396]
Entry:
Connection = 0x5591139d6400
Attribute = SQL_ATTR_AUTOCOMMIT
Value = 0x1
StrLen = -6
[ODBC][1515][1536073973.994129][SQLSetConnectAttr.c][681]
Exit:[SQL_SUCCESS]
[ODBC][1515][1536073973.994892][SQLSetConnectAttr.c][396]
Entry:
Connection = 0x5591139d6400
Attribute = SQL_ATTR_ODBC_CURSORS
Value = (nil)
StrLen = -6
[ODBC][1515][1536073973.995351][SQLSetConnectAttr.c][681]
Exit:[SQL_SUCCESS]
[ODBC][1515][1536073973.995872][SQLDriverConnect.c][726]
Entry:
Connection = 0x5591139d6400
Window Hdl = (nil)
Str In = [Driver=MDBTools;DBQ=/var/www/public/contacts-db.accdb;][length = 54]
Str Out = 0x7ffdb1be6d00
Str Out Max = 1023
Str Out Ptr = 0x7ffdb1be6cf8
Completion = 0
UNICODE Using encoding ASCII 'ISO8859-1' and UNICODE 'UCS-2LE'
[ODBC][1515][1536073974.001199][SQLDriverConnect.c][1353]
Exit:[SQL_ERROR]
[ODBC][1515][1536073974.001731][SQLGetDiagRec.c][680]
Entry:
Connection = 0x5591139d6400
Rec Number = 1
SQLState = 0x7f11dce6c010
Native = 0x7f11dce6c218
Message Text = 0x7f11dce6c016
Buffer Length = 511
Text Len Ptr = 0x7ffdb1be688a
[ODBC][1515][1536073974.002167][SQLGetDiagRec.c][717]
Exit:[SQL_NO_DATA]
[ODBC][1515][1536073974.002707][SQLEndTran.c][421]
Entry:
Connection = 0x5591139d6400
Completion Type = 1
[ODBC][1515][1536073974.003125][SQLEndTran.c][433]Error: 08003
[ODBC][1515][1536073974.003551][SQLDisconnect.c][208]
Entry:
Connection = 0x5591139d6400
[ODBC][1515][1536073974.004006][SQLDisconnect.c][237]Error: 08003
[ODBC][1515][1536073974.004462][SQLFreeHandle.c][284]
Entry:
Handle Type = 2
Input Handle = 0x5591139d6400
[ODBC][1515][1536073974.004999][SQLFreeHandle.c][333]
Exit:[SQL_SUCCESS]
[ODBC][1515][1536073974.005544][SQLFreeHandle.c][219]
Entry:
Handle Type = 1
Input Handle = 0x5591139d5d60
I can see where the failure is happening in the trace, [SQLDriverConnect.c][726] and [SQLDriverConnect.c][1353]. It appears to be a connection error, but I cannot make sense of the information contained in the following block in the trace log, [SQLGetDiagRec.c][680].
Also, I don't understand why the database can't be found if PHP can find it or why it would say it doesn't know the Jet Engine version since the file was created with an 8 year old version of MS Access (2010).
If anyone has any ideas as to how to debug the error I would greatly appreciate it.

How do I use sphinx search with PHP?

I am still a programming newbie, please keep that in mind.
I installed SphinxSearch on Linux Mint. I followed instructions from a Digital Ocean tutorial. I created a configuration file (sphinx.conf) as follows:
source mySource{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = mypass
sql_db = test
sql_query = SELECT id, uname FROM users
sql_attr_uint = id
sql_attr_string = uname
sql_port = 3306
}
index test{
source = mySource
path = /var/lib/sphinxsearch/data
docinfo = extern
}
searchd{
listen = 9306:mysql41
log = /var/log/sphinxsearch/searchd.log
query_log = /var/log/sphinxsearch/query.log
read_timeout = 5
pid_file = /var/run/sphinxsearch/searchd.pid
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
binlog_path = /var/lib/sphinxsearch/data
}
My PHP File
<?php
$conn = new mysqli('localhost','root','mypass','test',9306);
if($conn->connect_error){
die("Could not connect");
}else{
echo "You are connected!";
}
$query = $conn->query("SELECT * FROM test WHERE MATCH('hsmith')");
echo $query->error;
?>
PHP is throwing an error stating I am using a "Non-Object"
Any solution? Am I doing somethin entirely wrong?
Most likely the problem is in
$conn = new mysqli('localhost','root','mypass','test',9306);
As per http://php.net/manual/en/mysqli.construct.php when you pass 'localhost' in the 1st param mysqli tries to use unix socket, not a TCP socket and the port number therefore gets just ignored, i.e. you probably connect to your mysql instance instead of sphinx which then causes the problem you get.
Try:
$conn = new mysqli('127.0.0.1','','','test',9306);
instead.
Please also be aware that
echo $query->error;
is wrong since mysqli_result (http://php.net/manual/ru/class.mysqli-result.php) returned by query() does not have property 'error', you probably meant
echo $conn->error;

php - PDO with wrong host uses localhost

I have a WAMP installation with Windows Server 2012 R2 Datacenter Edition, Apache 2.4.23, PHP 7.0.10 (mysqlnd 5.0.12-dev - 20150407), MySQL 5.7.14.
I configured a connection with:
$host = 'wrong-server';
$dbase = 'db_name';
$user = 'my_user';
$pwd = 'my_pwd';
$connection='mysql: host='.$host.'; dbname='.$dbase;
$link = new PDO($connection , $user, $pwd);
where wrong-server doesn't exsist (it is for a test for catching errors).
When I execute the code the connection works using localhost as host (I know it because a query to db_name retrive datas).
I searched for some default behaviour or configuration without succes.
Some ideas?
Code update:
<?php
$host = '192.168.123.123'; //'localhost';
$dbase = 'db_name';
$user = 'my_user';
$pwd = 'my_pwd';
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT;
$connection='mysql: host='.$host.'; dbname='.$dbase;
try {
$link = new PDO($connection, $user, $pwd, $pdo_options);
$_SESSION['DB_INFO']=array( 'db'=>$link->getAttribute(PDO::ATTR_DRIVER_NAME),
'ver'=>$link->getAttribute(PDO::ATTR_SERVER_VERSION),
'cli'=>$link->getAttribute(PDO::ATTR_CLIENT_VERSION ),
'srv'=>$link->getAttribute(PDO::ATTR_SERVER_INFO ),
);
print_r($_SESSION['DB_INFO']);
}
catch(\PDOException $err) {
echo 'Error: '.$err->getMessage();
};
Server 192.168.123.123 doesn't exsist but I have these response:
Array ( [db] => mysql [ver] => 5.7.14 [cli] => mysqlnd 5.0.12-dev - 20150407 - $Id: 241ae00989d1995ffcbbf63d579943635faf9972 $ [srv] => Uptime: 20111 Threads: 1 Questions: 354 Slow queries: 0 Opens: 125 Flush tables: 1 Open tables: 118 Queries per second avg: 0.017 )
But if I set $pwd='wrong_pwd' the answer is:
Error: SQLSTATE[HY000] [1045] Access denied for user 'my_user'#'localhost' (using password: YES)
SOLUTION
As #MichaelBerkowski states, eliminating spaces in the DSN
mysql:host='.$host.';dbname='.$dbase.'
instead of
mysql: host='.$host.'; dbname='.$dbase.'
solves the problem, so an error came out.

DVWA database connection is not working

I'm having trouble connecting to a dataase with the following error:
Could not connect to the database.
Please check the config file.
I have tried changing the $_DVWA[ 'db_server' ] to 'localhost' but that didn't work and I tried chainging $_DVWA[ 'db_port '] to 3306, but that didn't work either. The password is empty.
The config file looks like this:
<?php
# If you are having problems connecting to the MySQL database and all of the variables below are correct
# try changing the 'db_server' variable from localhost to 127.0.0.1. Fixes a problem due to sockets.
# Thanks to #digininja for the fix.
# Database management system to use
$DBMS = 'MySQL';
#$DBMS = 'PGSQL'; // Currently disabled
# Database variables
# WARNING: The database specified under db_database WILL BE ENTIRELY DELETED during setup.
# Please use a database dedicated to DVWA.
$_DVWA = array();
$_DVWA[ 'db_server' ] = '127.0.0.1';
$_DVWA[ 'db_database' ] = 'dvwa';
$_DVWA[ 'db_user' ] = 'root';
$_DVWA[ 'db_password' ] = '';
# Only used with PostgreSQL/PGSQL database selection.
$_DVWA[ 'db_port '] = '5432';
#this can be 3306 or 5432
# ReCAPTCHA settings
# Used for the 'Insecure CAPTCHA' module
# You'll need to generate your own keys at: https://www.google.com/recaptcha/admin/create
$_DVWA[ 'recaptcha_public_key' ] = '(did not want to disclose this)';
$_DVWA[ 'recaptcha_private_key' ] = '(did not want to disclose this)';
# Default security level
# Default value for the secuirty level with each session.
# The default is 'impossible'. You may wish to set this to either 'low', 'medium', 'high' or impossible'.
$_DVWA[ 'default_security_level' ] = 'impossible';
# Default PHPIDS status
# PHPIDS status with each session.
# The default is 'disabled'. You can set this to be either 'enabled' or 'disabled'.
$_DVWA[ 'default_phpids_level' ] = 'disabled';
# Verbose PHPIDS messages
# Enabling this will show why the WAF blocked the request on the blocked request.
# The default is 'disabled'. You can set this to be either 'true' or 'false'.
$_DVWA[ 'default_phpids_verbose' ] = 'false';
?>
Any suggestions?
$_DVWA['db_server'] = '127.0.0.1:3306'; (Or the port that you use)

Windows - Sphinx configuration

I've got a problem with sphinx configuration and php api use (on Windows 7).
I've configured the indexer : indexer --config sphinx.conf test1
And launch the service : searchd --install --config sphinx.conf
When I made a search with the cmd console, I found results, but... not with the php api.
Here the error : Query failed: failed to read searchd response (status=2613, ver=11830, len=774976045, read=70).
Here my conf file :
#
# Minimal Sphinx configuration sample (clean, simple, functional)
#
source src1
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass =
sql_db = test
sql_port = 3306 # optional, default is 3306
sql_query = \
SELECT id, UNIX_TIMESTAMP(addTime) AS addTime, title, brand, material, size, description, c.name as categoryName \
FROM test \
JOIN category c ON c.id = advert.categoryId
sql_attr_uint = id
sql_attr_timestamp = addTime
sql_query_info = SELECT * FROM test WHERE id=$id
}
index catalog
{
source = src1
path = C:\wamp\www\sphinx\catalog
docinfo = extern
charset_type = utf-8
min_word_len = 3
min_prefix_len = 0
min_infix_len = 3
}
indexer
{
mem_limit = 32M
}
searchd
{
listen = 9312
listen = 9306:mysql41
log = C:\wamp\www\sphinx\log\searchd.log
query_log = C:\wamp\www\sphinx\log\query.log
read_timeout = 5
max_children = 30
pid_file = C:\wamp\www\sphinx\log\searchd.pid
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
workers = threads # for RT to work
binlog_path = C:\wamp\www\sphinx\data
}
The php file :
<?php
include('sphinxapi.php');
//Sphinx
$s = new SphinxClient;
$s->setServer("localhost", 3306);
$s->setMatchMode(SPH_MATCH_EXTENDED2);
$result = $s->query("#title jean");
if ($result['total'] > 0) {
foreach ($result['matches'] as $id => $otherStuff) {
echo $id;
}
} else {
echo "Query failed: " . $s->GetLastError() . ".\n";
}
?>
You are pointed in php script 3306 - it's port of mysql server in line:
$s->setServer("localhost", 3306);
try to point port 9312
Also try do following steps:
Remove installed windows service.
searchd --delete
Install windows service with full path to the configuration file
searchd --install --config fullPathToSphinx.conf
You need to run service manually or restart PC. To start manually service: run from command line program services.msc and find in the services list searchd and start it.
don't use "localhost" on Windows.
$s->setServer("127.0.0.1", 9312);

Categories