开发者

How to hook up mysql to my website?

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 m开发者_StackOverflowyqlconnect 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!


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.


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


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.


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.


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"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜