LAMP setup with remote MySQL - php

I am new to linux and I want to set up my network with one centralized MySQL server. I want my Web server to have Apache, PHP, and Wordpress installed with all MySQL references pointing to the database server.
I am having a hard time finding documentation on how to configure this. How do I set up a LAMP configuration across two servers with MySql as a stand alone dbms?
How do I congigure Apache, PHP and Wordpress in this setup?

If you wanna have your mysql on a remote server and let your local applications to connect to it , follow this steps :
run your mysql on your server (with a specific ip/computer name)
find my.conf in your mysql directory
edit my.conf and find the line : bind-address = 127.0.0.1
comment the line bind-address = 127.0.0.1 by adding # before it
restart your lamp by running this command /opt/lampp/lampp restart
in your local application set the mysql host from localhost to server ip or server name
DO NOT Forget before apply any changes create a backup from you my.conf, And grant all access to a user in your mysql on your server.

Related

Forwarding MySQL localhost to remote server

I am in the process of moving from PHP 5.6 to PHP 7.
I have a virtual machine running PHP 5.6 (PHP5) with MySQL running on it. The code is mounted from my host.
I have a second virtual machine running PHP 7 (PHP7). The code is also mounted from my host. All of my projects are configured with "localhost" as the database host.
As the first step, I want to have the MySQL "localhost" on PHP7 go directly to the PHP5 MySQL instance.
I have setup an ssh tunnel such that port 3306 on PHP7 goes directly to 3306 on PHP5, but this doesn't seem to help (EDIT: although if I change the config in a project to have a 127.0.0.1:3306 host it does work, but the host change is what I'm wondering whether I can avoid :) ).
Is there a way to setup the forwarding so that the projects will just work (or not), or do I need to go through each project and update it to cope with both servers?

How to connect to SQLYog localhost or otherwise

I am new to working with servers, and am not able to use SQLYog because it is not able to connect to any server. When I try to use the default values to connect to MySQL (localhost, root, port 3306), I get "Error No. 2003: Can't connect to MySQL server on 'localhost' (0).
Is there something I am missing or that I have to correct? I am just trying to create a database.
SQLyog is just one way to connect to a MySQL database and interact with it. Other popular methods include MySQL Workbench, Navicat, phpMyAdmin, and others.
Before you can use any of these, you have to first make sure your MySQL server is running and accepting connections. You didn't mention (or tag) whether you are running MySQL on your local machine, or what operating system you are using.
A couple of the most common development environments are LAMP or WAMP, for "Linux, Apache, MySQL, php" or "Windows, Apache, MySQL, php" respectively. Since you tagged your question php, I'll assume one of these is appropriate. (For example you're using SQLyog on Windows but your MySQL server is on Linux.) (I'll presume Ubuntu for Linux examples.)
On the machine you've installed MySQL (along with any other components), you should be able to determine its running state by looking at your process list (ps aux in Ubuntu, tasklist or Task Manager (GUI) in Windows).
You're looking for mysqld (Linux) or mysqld.exe (Windows). If the process isn't running, you need to start it (Linux/Windows). If you're using WampServer (a popular Windows all-in-one package), for example, you can also look in your Windows Services for "wampmysqld" or "wampmysqld64" and start the service there.
If you can't get the process to start, you may have a configuration error. If the process is running, you may need to check the configuration any way to determine what port it is running on, if it's not the standard 3306.
The configuration file name and location can vary by system and package, but generally it will be called "my.cnf" (Linux) or "my.ini" (Windows). Check your documentation for help on the specific path.
Once you've got the service running, you should be able to connect!
This is the default SQLyog connection dialog (at least in my slightly older version). The defaults assume you are running your MySQL server on your local machine (localhost), that you have a user "root" with no password, and the default port 3306 is used.
You'll need to change any of this information that differs on your particular installation.
Be aware that if you're trying to connect to an instance of MySQL on another machine, a firewall may be blocking a port.
These steps should hopefully get you on the right track.

ADO and msqli connections very slow

I am experiencing a very slow ADO and mysqli connection for my production web server. The current software setup is windows 2008 server R2 Standard Edition SP1, Apache 2.4, PHP 5.3.10, MySql 5.5.24, Pear 1.94, Zend Engine version 2.30.
I've profiled the code using XDEBUG and it shows the initial connections taking around 1200ms each (regardless of page being visited), whereas on my local development machine and another test server the connections only takes around 8ms. The code for the website is all in sync through SVN except for the php, pear, mysql, and apache ini and conf files. I've done diffs on these to check for differences and there aren't any. The DB contents are a complete copy as well. Everything for the production server is hosted on the same machine so there aren't any firewall or internet issues.
The first connection profile has the following call stack:
ADOConnecton->Connect
ADODB_mysql->_connect
php::mysql_connect
The second one:
php::mysqli->mysqli
Any suggestions?
Usually the slowness in (first) connection depend on DNS resolution.
May be:
client to resolve the server name
server to resolve the client name to match an access rule
let the client/server let know the server/client address using the host file:
http://en.wikipedia.org/wiki/Hosts_(file)
I edited the Mysql my.ini to change the mysql service to only bind to the IPV4 loopback adapter.
[mysqld]
...
bind=127.0.0.1
I also changed the \public_html\conf\face.ini to use the IPV4 loopback address instead of local host. (Changed "localhost" to "127.0.0.1")
After that all issues went away. I'm not sure if it is because the machine has a half dozen IP addresses or its trying to decide whether to use IPV6 or IPV4.

Is it possible to use the same MySQL database on Windows (XAMPP) and Linux (LAMP)?

I have dual boot mode with Windows 7 and Ubuntu 10.
On Windows 7 I have XAMPP installed, on Linux I have LAMP installed.
Is it possible to force the MySQL DB servers installed onto different operating systems (even though they would be of identical versions, they are different) to use the same physical files?
So in dual boot mode, independently from the fact that I ran another operating system, I would be able to use the same physical data. Sometimes I'd like to switch OS but it would be great to be able to use the same databases.
in your my.ini (in Windows it's located somewhere like C:\Program Files\MySQL\MySQL Server 5.1. It's the main configuration file for MySQL) file, you should have this line:
datadir="C:/ProgramData/MySQL/MySQL Server 5.1/Data/" for example
change it in both Windows and Linux Ubuntu to point to one single physical folder (on a partition with a file system which Windows could recognize). It will work. File formats are identical.
Whether you boot from Ubuntu, or Windows 7, it won't matter, 2 different builds of MySQL will be looking for data in the same place. Once data is modified in Windows environment, you boot up from Ubuntu and the data is there, modified.
Whilst not ideal, this should be fine as long as:
You're using identical versions of MySQL on both operating systems.
You shutdown mysqld before you copy the data files across. (If you're going to be copying the data files between partitions rather than keeping them on a shared fat32 partition).
In essence, as long as MySQL is running on an architecture of the same "endianness", then the file formats should be transferable.
As a suggestion, you could just close ICQ, etc. and use the free memory to run Ubuntu within a VirtualBox virtual machine on top of Windows 7 - hence ensuring you can trivially access your development environment without having to restart, etc.
This is actually quite a nice set up as it means you can use a Windows development environment if you want and simply host the site web site data on a Samba mount on the Ubuntu virtual machine.
As long as the data is sharedable/reable/writeable on both OS, and both file format are identical on both OS, it should be doable
The first problem I can imagine is the case insensitivity in windows.
so, convert your database/table ti camel_case (or camelcase) if you are always using CamelCase.
More information to read up - http://dev.mysql.com/doc/refman/5.0/en/limits-windows.html
Of course you can.
But I dont think, it is possible for your dual boot system.
Lets assume, your MySQL server is installed under Win7 machine. You can perfectly access it from Win7 enviroment, and even from Linux enviroment (if you do not deny access in your MySQL server settings).
The system, which is your MySQL installed under, has to be running! Then you can access it from multiple systems if allowed ;-)
I goggled a lot of time and found that running a Linux kernel is a solvable way and feasible solution.
Vagrant
It is a tool for building and managing virtual machine environments in a single workflow. The main reason why I argue you using vagrant is that it is not too heavy and does not swallow much of your computer resources. I believe you get through Vagrant documentation that will allow you to launch a Linux based machine on your physical machine.
Let's assume that the host machine is assigned IP 192.168.1.2 and the virtual machine has the IP address as 192.168.1.10, and make sure that the host and guest machine could see each other. Please read thoroughly Networking section to customise the network configuration.
Verifying connection between host and guest machine
Install MySQL Server
MySQL is a database management system. Basically, it will organise and provide access to databases where our site can store information.
Open a terminal in the machine has been set up from the above step. Run the following command:
sudo apt-get install mysql-server-5.6
Notes: It's up to the version of Linux distribution installed, the above command would be adjustable to suit your need. For install, I used the core of Ubuntu 14.04, see the link.
During the installation, your server will ask you to select and confirm a password for the MySQL root user. This is an administrative account in MySQL that has increased privileges.
Verifying the installation
From a terminal in the guest machine (i.e. the virtual machine), run the following command:
mysql -u root -p
will ask the MySQL password, then provide the one you have set up during MySQL Server installation. The following is the screenshot if you feed correct information to MySQL server.
Turn MySQL Server remotely accessible
Because we need a centralised database server where other computers could access and connect to the database of interest. Again, open a terminal and run the following MySQL commands:
GRANT ALL PRIVILEGES ON *.* TO 'root'#'192.168.1.2' IDENTIFIED BY PASSWORD '*4ACFE3202A5FF5CF467898FC58AAB1D615029441' WITH GRANT OPTION;
GRANT PROXY ON ''#'' TO 'root'#'192.168.1.2' WITH GRANT OPTION;
FLUSH PRIVILEGES;
which 192.168.1.2 is the IP address of the host machine and hashed string of password gets from user table in mysql database.
Okay. You might take a rest and enjoy your drink if there is no issue so far.
Verifying the remote access
From a terminal on the host machine, fire up the following command:
mysql -h192.168.1.2 -uroot -p
which is asking you to enter the password. If the root credential is correct, you would see a screenshot like the above one. One thing needs to be paid attention is to add -h192.168.1.2 following mysql command because we are not in the machine where MySQL server is installed.
All in all, we have set up a MySQL server used for both host and guest machine. In reality, if I have another machine assigned 192.168.1.3 can also connect to the database server and exchange data between server and client.

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 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!
In order to make connection to MySQL database from in PHP script, you need:
Correctly configured MySQL server, with user, which has corresponding permissions
Correctly specified parameters in mysql_connect() function
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"

Categories