views:

37

answers:

5

I am runing linux mint. I have a mysql db called Test. Do i need apache or something to hook it up to my db?

When i try to do my php myqlconnect i get this: Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

Any ideas? thanks!

A: 

First of all, you need Apache to run PHP even if you are not making any connections to your database. Usually Apache runs PHP as a DLL and you need to enter some commands in the httpd.conf (configuration) file of your Apache installation. Are you familiar with these?

Second, you have to have the MySQL server already up and running, in order to make a connection to your database through mysql_connect. I am not a Linux user, but in Windows, I have registered MySQL as a service to be started at startup. However, they may well be a way of doing this in Linux as well.

knightofmathematics
i am not familiar with those
willl
A: 

Again, these are for Windows - sorry! You should replace the paths with the ones you have in your Linux Apache installation and the name of the DLL. And these are for version 5 of PHP (if that is what you are using)

PHPIniDir "C:/Program Files/PHP/" LoadModule php5_module "C:/Program Files/PHP/php5apache2_2.dll"

knightofmathematics
A: 

What you are trying to do is set up what's called a "LAMP" server (Linux, Apache, MySQL, PHP). There are plenty of guides on how to set these up, such as http://www.ubuntugeek.com/step-by-step-ubuntu-810-intrepid-ibex-lamp-server-setup.html

Paul Tomblin
thanks man, i needed this
willl
A: 

This is not Apache related; it's related to the configuration of the MYSQL server and PHP. The database can be reached via the network or local UNIX domain sockets(depending on configuration). In your case, PHP (via the MySQL client lib) is configured find a socket in /var/lib/mysql.sock.

Check the configuration. Ensure the database is running. Check for the socket in /var/lib/mysql.

BTW on my system, the socket is in /var/run/mysqld/mysqld.sock. That was configured from /etc/mysql/my.cnf.

Frayser
Also check all the php.ini files in /etc/php on my system. Check the parameters `mysql.default_socket`, `mysqli.default_socket`, `pdo_mysql.default_socket`. They are blank (set to nothing) to use some "built-in mysql default" If not blank, then these must be set the the correct value.
Frayser
+1  A: 

In order to make connection to MySQL database from in PHP script, you need:

  1. Correctly configured MySQL server, with user, which has corresponding permissions

  2. Correctly specified parameters in mysql_connect() function

  3. Network connection from host where PHP script is started to host where MySQL database is running

PHP script may be executed either in command-line, or as web application. Obviously, Apache web server is necessary only for the second case.

For your specific error, you may take a look at corresponding questions at ServerFault, for example, at this one.

Kel