简体   繁体   English

在PHP调用中使用Lampp mysqldump作为默认值

[英]Use Lampp mysqldump as default in php call

tricky question and I don't know if SO is the good space (maybe AskUbuntu ? or SuperUser ?) 棘手的问题,我不知道SO是不是很好的空间(也许AskUbuntu?或SuperUser?)

I've set my Lampp on my ubuntu in /opt/lampp/ 我已将我的Lampp放在/opt/lampp/ ubuntu上

Problem, when I need to call direct bin as mysqldump , I end up calling the default installed one on my ubuntu, not the one linked to my lampp : 问题,当我需要将直接bin称为mysqldump ,我最终在ubuntu上调用了默认安装的一个,而不是链接到lampp的一个:

$ mysqldump --user=root test $ mysqldump --user = root测试

mysqldump: Got error: 2002: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) when trying to connect mysqldump:得到错误:2002:尝试连接时无法通过套接字'/var/run/mysqld/mysqld.sock'(2)连接到本地MySQL服务器

As you can see, it check for /var/run . 如您所见,它检查/var/run If I want to use the good one, I should specify the path : 如果我想使用好的,我应该指定路径:

$ /opt/lampp/bin/mysqldump --user=root test $ / opt / lampp / bin / mysqldump --user = root测试

-- MySQL dump 10.13 Distrib 5.6.21, for Linux (x86_64) -适用于Linux(x86_64)的MySQL dump 10.13 Distrib 5.6.21

I could use the full path in my PHP call, but my PHP prod server will then not work. 我可以在PHP调用中使用完整路径,但是我的PHP产品服务器将无法工作。

How can I set the Lampp bin as default to be used by php with exec('mysqldump') ? 我如何将lampp bin设置为默认值,以供exec('mysqldump')

You really have several choices to do what you want. 您确实有几种选择可以做自己想做的。

  • You could create a configuration file that depends on your environement (local, dev, preprod, prod ...). 您可以创建一个取决于您的环境的配置文件(本地,dev,preprod,prod ...)。 This file may declare an array of configurations, one of which is the path of the executable you need. 该文件可以声明一个配置数组,其中之一是您所需的可执行文件的路径。 Your php code will know the environment by checking a global variable, for instance $_SERVER , which can be set in your web server's vhost file. 您的php代码将通过检查全局变量(例如$_SERVER来了解环境,该变量可以在Web服务器的vhost文件中设置。 I think that's the clean way of doing. 我认为这是干净的做法。

  • You could hardcode a path for you executable (let's say /home/www/mysqldump ) and create a symbolic link with ln -s (if I remember right, or check the man page) between your environment's executable /opt/lampp/bin/mysqldump and /home/www/mysqldump . 您可以为可执行文件(例如/home/www/mysqldump )硬编码一个路径,并在环境的可执行文件/opt/lampp/bin/mysqldump之间使用ln -s创建符号链接(如果我没记错的话,或者查看手册页)。 /opt/lampp/bin/mysqldump/home/www/mysqldump You have to prepare all your environments that way. 您必须以这种方式准备所有环境。 I think it's a bit ugly but it's quick. 我认为这有点丑陋,但速度很快。

I am sure there are tons of other solutions. 我相信还有很多其他解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM