Search code examples
phpmysqllinuxapachelamp

LAMP stack with apache and php on one linux server and mysql on a different linux server


I am pretty new to linux and LAMP setup. I want to setup a LAMP environment with AP on one linux server and M on a different linux server. I have a hard time finding a relevant document with such a configuration.

I have done the following steps so far:

server1:

yum install -y httpd
/sbin/service httpd restart
yum install -y php php-mysql
sed -i "s/Listen 80/#Listen 80/g" /etc/httpd/conf/httpd.conf
yum install -y mod_ssl openssl
/sbin/service httpd restart
service iptables stop

I changed the ServerName in /etc/httpd/conf/httpd.conf from

#ServerName www.example.com:80

to

ServerName 172.32.35.14 (ip address of server1)
/sbin/service httpd restart

server2:

yum install -y mysql-libs
yum install -y mysql
yum install -y perl-DBI
yum install -y perl-DBD-MySQL
yum install -y mysql-server
/sbin/chkconfig mysqld on
/sbin/service mysqld start
mysql -u root  -e "CREATE USER 'mysqluser' IDENTIFIED by 'password'" 
mysql -u root  -e "CREATE USER 'mysqluser'@'localhost' IDENTIFIED by 'password'"
mysql -u root  -e "GRANT ALL PRIVILEGES ON *.* TO 'mysqluser'@'localhost' WITH GRANT OPTION"
mysql -u root  -e "GRANT ALL PRIVILEGES ON *.* TO 'mysqluser'@'%' WITH GRANT OPTION"
mysql -u mysqluser -p password -e "CREATE DATABASE mysqldb" 
mysql -u mysqluser -p password mysqldb < /tmp/mysqlinstaller/world.sql
service iptables stop

Then I had these post configuration steps:

On server 2, where my mysql is installed, I did the following:

bind-address = 172.32.35.14 (ip of server 1 where apache/php are installed)
service mysql restart

But I am not able to establish a connection. Can you point out what I am missing and guide me please.


Solution

  • OK, a few things that could probably help you:

    1. I don't think that ServerName is doing what you expect it to be. Please check out the docs. TLDR: I don't think you need to modify it for your needs.
    2. The bind-address is actually the address that the MySQL server will bind itself to listen to on so you don't want it to listen on the IP of server1 but on the IP address of server 2. That's most likely the reason why your MySQL can't start. If you're using an older MySQL version make also sure that you have the skip_networking option commented out.
    3. Don't forget to FLUSH PRIVILEGES after creating the user.

    And now a couple of questions:

    1. Can you confirm that you have working apache and PHP on server 1?
    2. After completing step 2 of my suggestions can you confirm you have a mysql server up and running on server 2?

    Since this will probably require some communication I'll update the answer as we go.

    EDIT

    So far we've got MySQL up and running on server2 and apache and PHP up and running on server1. There's an issue trying to reach server1 from a host machine but we'll deal with this later on. Now let's make sure that we can connect from PHP to the MySQL on server2.

    Can you please create a table inside the mysqldb, insert several rows in it and then try to retrieve those rows from a PHP script on server1? For now keep accessing the page from server1 via lynx.