Allowing Remote Connections to MySQL Instance

You do not need to specially create a user and allow remote connections to a MySQL Instance. While adding a MySQL Instance to the Policy, you can use the credentials of any MySQL user with full access to the MySQL server from localhost. For example, you can use a MySQL 'root@localhost' account typically created during the MySQL server installation. See Adding MySQL Instance to the Policy.
Customers with both 3.14 Server and Agent can use localhost for their MySQL instance hostname. The CDP Server does not connect directly to MySQL and insteadconnects to MySQL through the agent connection.
Notice
There is no relationship between a MySQL user and a CDP user.
Notice
Admin access to the server and MySQL installation is required.
Tip
In CDP, end-user level MySQL backup is not supported. Only super-users can conduct MySQL backup. Sub-users are limited by agent user permission.
3.14 Version Limitation
Prerequisites:
  • Multiple databases per MySQL Instance
  • MySQL user with full access to one of the databases
The MySQL user can backup only databases that belong to him and cannot backup databases that do not belong to him.
Use the following command to allow the user to backup all databases:
GRANT ALL PRIVILEGES ON *.* to 'user1'@'localhost' IDENTIFIED by 'some-pass';
Notice
The command will allow you to backup databases, but not restore.

Allowing Remote Connections to MySQL Instance (Version 3.12 or Earlier)

By default, remote access to the MySQL database server is disabled for security reasons. Follow the instructions below to provide remote access to the database server.
Important Notice
For the MySQL Add-on to work, both the CDP Server and the Agent should have administrative permissions for the entire server. The CDP Server will backup the database data, while the Agent will lock and flush tables. Also, the CDP Server needs administrative permissions for restoring data. You can create a special user for backups in MySQL and limit access to MySQL from the CDP Server IP address. Also, you should provide access to this user from localhost and the 127.0.0.1 address for the Agent.


Using Command Line Interface

1. First, log in over ssh to the remote MySQL database server. To do this, on Linux or Mac, open the terminal and execute the command:
ssh user@mysql.server.com
Then you will be asked about an untrusted key. Enter "yes" and press <Enter>. Then enter the password.
On Windows, you can use the PuTTy utility. Download it from this page - http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html - launch it, enter "mysql.server.com" in the "Host name (or IP address)" input field, and click on the "Open" button.
When you are asked about an untrusted key, click on the "Yes" button.
Then enter the login and password.
2. When the connection is established, you have to open the MySQL server configuration file my.cnf in a text editor such as vim.
Tip
  • If you are using Debian GNU/Linux, or installed MySQL using yum on Fedora/CentOS, the full path to the my.cnf file is /etc/mysql/my.cnf.
  • If you are using Red Hat Linux/Fedora/Centos Linux and installed MySQL from rpms downloaded from dev.mysql.com, the full path to the my.cnf file is/etc/my.cnf.
# vim /etc/my.cnf
3. Open the file in a text editor and find the section starting with the line:
[mysqld]
Make sure the line skip-networking is commented (or remove the line) and add the following line:
bind-address = *
The entire section should look like this:
[mysqld] character-set-server=utf8 collation_server=utf8_general_ci skip-character-set-client-handshake #skip-innodb innodb_data_file_path=INNODBDATA1:4096M innodb_log_file_size=512M datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock bind-address = * #skip-networking skip-external-locking skip-name-resolve.... .. ....
Where,
  • bind-address - Contains an asterisk, meaning that the service should bind to all available IP addresses.
  • skip-networking - Do not listen for the TCP port at all. All interactions with mysqld must be made via the Unix domain socket. This option is highly recommended for systems where only local requests are allowed because it provides more security. Since you need to allow a remote connection, this line should be removed from my.cnfor commented out.
4. Restart the mysql service.
# /etc/init.d/mysql restart
5. Grant access to the MySQL server from the IP address of the CDP Server. You should also grant access from IP address 127.0.0.1 and localhost, since the lock and flush operations during the snapshot will be performed by the agent running on the same host as MySQL service. The CDP Server will connect to MySQL as "r1soft" user.
Connect to the MySQL server by executing the following command:
$ mysql -u root -p mysql
Enter the MySQL root password when prompted.
CDP should be able to backup all databases, so you should grant global privileges to the "r1soft" user.
Notice
There is no relationship between a MySQL user and a CDP sub-user.
Notice
Admin access to the server and MySQL installation is required.
Tip
In CDP, end-user level MySQL backup is not supported. Only super-users can conduct MySQL backup. Sub-users are limited by agent user permission.
In the following example, it is assumed that the IP address of the CDP Server is 202.202.200.20 and that the CDP Server will connect with username "r1soft" and password "r1soft" without quotes.
GRANT ALL PRIVILEGES ON *.* TO r1soft@'202.202.200.20' IDENTIFIED BY 'r1soft'; GRANT ALL PRIVILEGES ON *.* TO r1soft@'127.0.0.1' IDENTIFIED BY 'r1soft'; GRANT ALL PRIVILEGES ON *.* TO r1soft@'localhost' IDENTIFIED BY 'r1soft';
6. Log out of MySQL by typing the following command:
exit
7. Make sure that there is no firewall that blocks connections to TCP port 3306 of the MySQL server from the CDP Server. It is not always possible to check all the firewalls between one server and the other. But you can always check local iptables firewall on the MySQL server. To add the rule that permits connections to TCP port 3306 from CDP Server with IP address 202.202.200.20, execute the following command:
iptables -A INPUT -s 202.202.200.20 -m tcp -p tcp --dport 3306 -j ACCEPT
If you have several CDP Servers that reside on IP subnet 202.202.200.0/24 and the MySQL server can be backed up by any of them, you can allow access to TCP port 3306 from the entire subnet in one command:
iptables -A INPUT -s 202.202.200.0/24 -m tcp -p tcp --dport 3306 -j ACCEPT
Finally, save firewall rules so they will be automatically reloaded when the server reboots:
# /etc/init.d/iptables save
8. Test that your firewall settings and MySQL security settings allow you to connect to the MySQL server from the CDP Server. Execute the following command:
$ mysql -h mysql.server.com -u r1soft -p
Where,
  • -h IP or hostname - mysql.server.com is the hostname (FQDN) of MySQL server.
  • -u r1soft - Log in as MySQL user r1soft.
  • -p - Prompt for password.
You can also test if port 3306 is reachable through the firewall using telnet:
$ telnet mysql.server.com 3306
If the port is reachable, you will see the following message:
Connected to mysql.server.com Escape character is ^]
Then some garbage characters along with the MySQL version string (here MySQL version is 5.1.51-community). To close the telnet, press the <Ctrl> + <]> keys or just wait until the connection is closed on timeout.

Using GUI Tools

Notice
Using GUI tools described in this document only allows you to grant permissions on the MySQL server level. You still have to make sure that the MySQL server listens for network connections and that the firewall does not block its port. There are web applications that allow you to do this in GUI. For example, the popular hosting management panel Webmin allows you to edit firewall rules and text files as well as restart services. Another popular hosting management panel - Parallels Plesk - also allows you to edit firewall rules. Covering all available tools goes far beyond the scope of this documentation.

Granting Permissions Using phpMyAdmin

PhpMyAdmin (http://www.phpmyadmin.net/) is an open source web application written in PHP. It is very popular among web developers because of its intuitive interface and ease of use. A lot of web hosting management panels include phpMyAdmin in their interface. 
In the following example, it is assumed that the IP address of the CDP Server is 202.202.200.20 and that the CDP Server will connect with username "r1soft" and password"r1soft" without quotes.
1. First, open phpMyAdmin in your browser and log in.
2. Click the "Privileges" link. Depending on the version of phpMyAdmin, this link can be found in different parts of the window.
3. Click the "Add a new User" link.
4. On the "Add a New User" window, do the following:
  • Enter "r1soft" in the "User name" field.
  • Select the "Use text field" option from the drop-down menu next to "Host" and enter 202.202.200.20 in the field next to the option list.
  • Enter "r1soft" in the "Password" and "Re-type" fields.
  • Click "Check all" next to "Global privileges."
Scroll down and click on the "Go" button.
You will be notified that the user has been successfully created.
5. Repeat steps 2-4. This time, type "127.0.0.1" instead of "202.202.200.20" in the "Host" field.
6. Repeat steps 2-4 again. This time select "Local" in the option list next to the "Host" field. You will not have to type "localhost" in the input field as it will appear there automatically.

Granting Permissions Using HeidiSQL

HeidiSQL(http://www.heidisql.com/) is a freeware Windows application written in Delphi. It is popular among web developers because of its intuitive interface and ease of use. It can be installed on a laptop and can be used for managing MySQL servers that do not have phpMyAdmin installed.
In the following example, it is assumed that the IP address of the CDP Server is 202.202.200.20 and that the CDP Server will connect with the username "r1soft" and password"r1soft" without quotes.
1. First, launch HeidiSQL and press the "New" button to enter MySQL server credentials.
2. Enter the session name in the list on the left, the Hostname or IP address of the MySQL server, the username, and the password, and press "Save."
Then press "Open."
You will see the main window of the application.
3. Select Tools > User manager from the application menu.
You will see the User manager window.
4. Click on the "Add" button.
5. Then do the following:
  • Enter "r1soft" in the "User name" field.
  • Leave the default value "localhost" in the "From host" field.
  • Enter "r1soft" in the "Password" and "Repeat password" fields.
  • Check the box next to "Global privileges."
6. Click on the "Save" button.
7. Repeat step 4. This time enter 127.0.0.1 in the "From host" field.
8. Repeat step 4. This time enter 202.202.200.20 in the "From host" field.
9. Click on the "Close" button to close the "User manager" window.

Connect from PHP to Oracle DB ( using OCI8 on Ubuntu with Oracle Instant Client and SDK )

I will be doing this on VirtualBox with Ubuntu 12.04 installed on it and up to date.
Before we begin, make sure you have the following
  1. A working instance of LAMP ( Linux, Apache, php and MySQL ) - at least Apache and PHP
  2. Root privileges
  3. A file called phpinfo.php( in your webroot which has phpinfo() ) to verify OCI8 after installation
You can install LAMP very easily with tasksel : sudo apt-get install tasksel -> tasksel ->choose LAMP server
We will need 2 packages from Oracle ( 32 or 64 bit according to your machine )  - current Version 11.2.0.3.0 – zip versions
  1. You can get the 2 downloads ( 32-bit ) from here http://www.oracle.com/technetwork/topics/linuxsoft-082809.html
  2. Instant Client Package – Basic: All files required to run OCI, OCCI, and JDBC-OCI applications
  3. Unzip all files in this to a directory called /opt/oracle_instantclient ( of-course you can put it anywhere you like )
  4. Instant Client Package – SDK: Additional header files and an example makefile for developing Oracle applications with Instant Client
  5. Unzip this into the same directory /opt/oracle_instantclient
  6. Your /opt/oracle_instantclient directory must now contain all files from Instant Client Package – Basic and an SDK directory from Instant Client Package – SDK
  7. Next we need to create some symbolic links to “.so” files – you will see a file called libclntsh.so.version in /opt/oracle_instantclient  directory. In my case the file name is libclntsh.so.11.1. We will create a symbolic link named libclntsh.so  to the file  libclntsh.so.11.1  in the same directory using the command ln -s libclntsh.so.11.1 libclntsh.so
  8. Next we will install the php5-dev package command sudo apt-get install php5-dev
  9. Next we will install the package libaio using the command sudo apt-get install libaio-dev
  10. Then we install pear package using sudo apt-get install php-pear 
  11. Next, we will install the oci8 extension using sudo pecl install oci8 
  12. This will ask for Oracle Home Directory – give the path of the instant client instantclient,/opt/oracle_instantclient 
  13. In the above, we are telling pecl that its an instantclient and then giving the path to the instantclient directory
  14. If the installation is successful, you should see messages like “Build Process completed successfully”
  15. Add the oracle oci8.so to php.ini using
  16. sudo echo “extension=oci8.so” >> /etc/php5/apache2/php.ini 
  17. sudo echo “extension=oci8.so” >> /etc/php5/cli/php.ini 
  18. ( Tip from Omar ) An alternative is to add this to the oci8.ini file using the command sudo echo “extension=oci8.so” > /etc/php5/conf.d/oci8.ini
  19. Restart apache using service apache2 restart 
  20. Open a web browser and navigate to the phpinfo file ( in my case it is localhost/phpinfo.php )
  21. Search for oci8 and you should find oci8 block with variables ( this means you have successfully compiled PHP with the oci8 extension )
  22. Next step is to test connecting to an oracle instance using oci_connect();
  23. Contact your Oracle DBA and get the following information hostname, port, service name, service type, username, password and then try out an example from http://www.php.net/manual/en/function.oci-connect.php
  24. If you get the error, oci_connect() is not defined, then something went wrong. Try looking at apache error logs or use php -v 

How Do I Enable Remote Access To MySQL Database Server?


By default remote access to the MySQL database server is disabled for security reasons. However, some time you need to provide remote access to database server from home or a web server. This post will explain how to setup a user account and access mysql server remotely.

Task: MySQL Server Remote Access

You need type the following commands which will allow remote connections.

Step # 1: Login Using SSH (if server is outside your data center)

First, login over ssh to remote MySQL database server. You may need to login to your MySQL server as the root user:
ssh user@server1.cyberciti.biz
### login as the root using su or sudo ##
su
#sudo -s
 
OR directly login as root user:
ssh root@server1.cyberciti.biz

Step # 2: Edit the my.cnf file

Once connected you need to edit the MySQL server configuration file my.cnf using a text editor such as vi:
  • If you are using Debian Linux file is located at /etc/mysql/my.cnf location.
  • If you are using Red Hat Linux/Fedora/Centos Linux file is located at /etc/my.cnflocation.
  • If you are using FreeBSD you need to create a file /var/db/mysql/my.cnf location.
Edit the /etc/my.cnf, run:
# vi /etc/my.cnf

Step # 3: Once file opened, locate line that read as follows

[mysqld] 
Make sure line skip-networking is commented (or remove line) and add following line
bind-address=YOUR-SERVER-IP
For example, if your MySQL server IP is 65.55.55.2 then entire block should be look like as follows:
[mysqld]
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
language        = /usr/share/mysql/English
bind-address    = 65.55.55.2
# skip-networking
....
..
....
Where,
  • bind-address: IP address to bind to.
  • skip-networking : Don’t listen for TCP/IP connections at all. All interaction with mysqld must be made via Unix sockets. This option is highly recommended for systems where only local requests are allowed. Since you need to allow remote connection this line should be removed from my.cnf or put it in comment state.

Step# 4 Save and Close the file

If you are using Debian / Ubuntu Linux, type the following command to restart the mysql server:
# /etc/init.d/mysql restart
If you are using RHEL / CentOS / Fedora / Scientific Linux, type the following command to restart the mysql server:
# /etc/init.d/mysqld restart
If you are using FreeBSD, type the following command to restart the mysql server:
# /usr/local/etc/rc.d/mysql-server stop
# /usr/local/etc/rc.d/mysql-server start

OR
# /usr/local/etc/rc.d/mysql-server restart

Step # 5 Grant access to remote IP address

Connect to mysql server:
$ mysql -u root -p mysql

Grant access to a new database

If you want to add a new database called foo for user bar and remote IP 202.54.10.20 then you need to type the following commands at mysql> prompt:mysql> CREATE DATABASE foo;
mysql> GRANT ALL ON foo.* TO bar@'202.54.10.20' IDENTIFIED BY 'PASSWORD';

How Do I Grant Access To An Existing Database?

Let us assume that you are always making connection from remote IP called 202.54.10.20 for database called webdb for user webadmin, To grant access to this IP address type the following command At mysql> prompt for existing database, enter:
mysql> update db set Host='202.54.10.20' where Db='webdb';
mysql> update user set Host='202.54.10.20' where user='webadmin';

Step # 6: Logout of MySQL

Type exit command to logout mysql:mysql> exit

Step # 7: Open port 3306

You need to open TCP port 3306 using iptables or BSD pf firewall.

A sample iptables rule to open Linux iptables firewall

/sbin/iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT
OR only allow remote connection from your web server located at 10.5.1.3:
/sbin/iptables -A INPUT -i eth0 -s 10.5.1.3 -p tcp --destination-port 3306 -j ACCEPT
OR only allow remote connection from your lan subnet 192.168.1.0/24:
/sbin/iptables -A INPUT -i eth0 -s 192.168.1.0/24 -p tcp --destination-port 3306 -j ACCEPT
Finally save all rules (RHEL / CentOS specific command):
# service iptables save

A sample FreeBSD / OpenBSD pf rule ( /etc/pf.conf)

pass in on $ext_if proto tcp from any to any port 3306
OR allow only access from your web server located at 10.5.1.3:
pass in on $ext_if proto tcp from 10.5.1.3 to any port 3306  flags S/SA synproxy state

Step # 8: Test it

From your remote system or your desktop type the following command:
$ mysql -u webadmin –h 65.55.55.2 –p
Where,
  • -u webadmin: webadmin is MySQL username
  • -h IP or hostname: 65.55.55.2 is MySQL server IP address or hostname (FQDN)
  • -p : Prompt for password
You can also use the telnet or nc command to connect to port 3306 for testing purpose:
$ echo X | telnet -e X 65.55.55.2 3306
OR
$ nc -z -w1 65.55.55.2 3306
Sample outputs:
Connection to 65.55.55.2 3306 port [tcp/mysql] succeeded!
Source

Installing PDO_OCI and OCI8 PHP extensions on CentOS 6.4 64bit

I am currently working on a PHP project that requires using an Oracle server as the database. I tried setting up the Oracle PHP extensions directly on my development machine (MacOSX) but failed after a few tries. I also managed to ruin my Homebrew-PHP setup which brought me more joy.
So I ended up using Vagrant which is what I should have done in the first place. So I booted up a Vagrant box with CentOS 6.4 64bit.
This tutorial assumes that you have already installed php and other packages (e.g. php-pdo) you normally need. This was also tested with an installation of Oracle 11g Express. I’m not sure if this will work for higher versions.

Dependencies

Oracle

Installing Oracle is easy. You can follow this tutorial by David Ghedini in installing Oracle 11g Express.

Development packages

$ sudo yum install php-pear php-devel zlib zlib-devel bc libaio glibc
$ sudo yum groupinstall "Development Tools"

InstantClient

Download Oracle InstantClient RPM files here. Put these files in your server. Download the basic and devel packages.
  • Basic: oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm
  • Devel: oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm
Install the downloaded rpm files:
$ sudo rpm -ivh oracle-instantclient11.2-basic-11.2.0.3.0-1.x86_64.rpm
$ sudo rpm -ivh oracle-instantclient11.2-devel-11.2.0.3.0-1.x86_64.rpm
$ sudo ln -s /usr/include/oracle/11.2/client64 /usr/include/oracle/11 .2/client
-s /usr/lib/oracle/11.2/client64 /usr/lib/oracle/11.2/client
$ sudo ln
Create a file inside /etc/profile.d named oracle.sh and put this as the content:
export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib
And run it so we’ll have LD_LIBRARY_PATH as an environment variable.
source /etc/profile.d/oracle.sh

PDO_OCI

Download the PDO_OCI source using pecl.
$ pecl download PDO_OCI
$ tar -xvf PDO_OCI-1.0.tgz
$ cd PDO_OCI-1.0
Inside the PDO_OCI-1.0 folder, edit the file named config.m4.
Find a pattern like this near line 10 and add these 2 lines:
elif test -f $PDO_OCI_DIR/lib/libclntsh.$SHLIB_SUFFIX_NAME.11.2; then
PDO_OCI_VERSION=11.2
Find a pattern like this near line 101 and add these lines:
11.2)
PHP_ADD_LIBRARY(clntsh, 1, PDO_OCI_SHARED_LIBADD)
;;
Build and install the extension.
$ phpize
$ ./configure --with-pdo-oci=instantclient,/usr,11.2
$ make
make install
$ sudo
To enable the extension, add a file named pdo_oci.ini under /etc/php.d and put this as the content:
extension=pdo_oci.so
Validate that it was successfully installed.
$ php -i | grep oci
You should see something like this in the output:
/etc/php.d/pdo_oci.ini,
PDO drivers => oci, odbc, sqlite

OCI8

Download the OCI8 source using pear
$ pear download pecl/oci8
$ tar -xvf oci8-1.4.9.tgz
$ cd oci8-1.4.9
Build and install the extension.
$ phpize
$ ./configure --with-oci8=shared,instantclient,/usr/lib/oracle/11.2/client64/lib
$ make
make install
$ sudo
To enable the extension, add a file named oci8.ini in /etc/php.d with this content:
extension=oci8.so
Validate that it was successfully installed.
$ php -i | grep oci8
You should see something like this:
/etc/php.d/oci8.ini,
oci8
connection_class => no value => no value oci8
oci8 ..default_prefetch => 100 => 100
x_persistent => -1 => -1
oci8.events => Off => Off oci8.m aoci8.old_oci_close_semantics => Off => Off
g_interval => 60 => 60 oci8.privile
oci8.persistent_timeout => -1 => -1 oci8.pi nged_connect => Off => Off
> 20 => 20
oci8.statement_cache_size =

Finishing up

Do not forget to restart your web server (e.g. Apache). You can double check with phpinfo() if the extensions were successfully installed.
This tutorial wouldn’t have been possible without these references:
Source :http://shiki.me/blog/installing-pdo_oci-and-oci8-php-extensions-on-centos-6-4-64bit/

Why do I see Apache Test page? Centos 6.4

Despite this, many of our new clients/customer and new admin/user does not understand why would a website show an Apache Test page ?

Apache test page means...

The Apache test page, means your server is configured properly and ready to use. Technically speaking this page is the default index page when you install Apache web server first time.

So how can I make the Apache test page go away?

Simple open your /var/www/index.html file and modify it or delete file (though it might trigger new error). Under Red Hat Enterprise Linux/CentOS/Fedora Core, rename or delete a file/etc/httpd/conf.d/welcome.conf to make sure you do not see Apache test page.
You may now add content to the directory /var/www/html/. Note that until you do so, people visiting your website will see default page and not your content. To prevent this page from ever being used, follow the instructions in the file /etc/httpd/conf.d/welcome.conf.
If you do not know much about Apache web server, configuration it is better to take help of seasoned Linux/Unix administrator, IMHO.

How can I create an SSH user who only has permission to access specific folders

This is simple. Just create a new user with it's home directory set to the one you need him to have access to (this command must be run under sudo or in root shell):
adduser --home /restricted/directory restricted_user
This will create an user restricted_user, the directory /restricted/directory and then permissions on the directory will be set so the user can write to it. It won't have an ability to write to any other directory by default.
If you have the directory already, you can run adduser command with a --no-create-home option appended and set permissions manually (also with root privileges), like:
chown restricted_user:restricted_user /restricted/directory
chmod 755 /restricted/directory
If you need to make even world-writable directories unaccessible for this user, there are two variants.
1) If you want to provide an interactive shell session to the user, then consider following this manual on creating a chroot jail (in your /restricted/directory).
After that add following to your sshd_config:
Match user restricted_user
  ChrootDirectory /restricted/directory
2) If you only need him to copy files between his endpoint of connection and your host, everything is much easier. Add these lines in end of your sshd_config:
Match user restricted_user
  ForceCommand internal-sftp
  ChrootDirectory /restricted/directory

Subsystem       sftp    internal-sftp
Then comment out the Subsystem sftp /usr/lib/openssh/sftp-server by placing a hash (#) sign in the start.
After restarting your SSH server (it does not kill interactive sessions on restart, so it is safe even if you misconfigured something; also, does not close your running session before you have checked that you are still able to log in), everything should work as intended.

How to Install PHP 5.4 and MySQL 5.5 in CentOS 6.4 via Yum

How about default?

For example, look at PHP version.
CentOS
$ yum info php

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.sin3.sg.voxel.net
 * extras: mirrors.sin3.sg.voxel.net
 * updates: mirror.neu.edu.cn
Available Packages
Name        : php
Arch        : x86_64
Version     : 5.3.3
Release     : 23.el6_4
Size        : 1.1 M
Repo        : updates
Summary     : PHP scripting language for creating dynamic web sites
URL         : http://www.php.net/
License     : PHP
Description : PHP is an HTML-embedded scripting language. PHP attempts to make it
            : easy for developers to write dynamically generated webpages. PHP also
            : offers built-in database integration for several commercial and
            : non-commercial database management systems, so writing a
            : database-enabled webpage with PHP is fairly simple. The most common
            : use of PHP coding is probably as a replacement for CGI scripts.
            :
            : The php package contains the module which adds support for the PHP
            : language to Apache HTTP Server.
It’s 5.3 you know.

Add repository

There are a few popular repository for CentOS like bellow.
  • epel
  • remi
  • rpmforge
Let’s install them.
you need to do it with root privilege so use sudo or su - and get privilege.

epel

CentOS
# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

remi

CentOS
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

rpmforge

CentOS
# rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm

Check repository

CentOS
# yum repolist
you can find the repository names you installed.

Enable repository and Install

These repository is not supported by CentOS, so for dependancy enable them only when you want to get special package.

CentOS
# vi /etc/yum.repos.d/epel.repo
/etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=0 # 1 -> 0 disable
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
CentOS
# vim /etc/yum.repos.d/rpmforge.repo
/etc/yum.repos.d/rpmforge.repo
[rpmforge]
name = RHEL $releasever - RPMforge.net - dag
baseurl = http://apt.sw.be/redhat/el6/en/$basearch/rpmforge
mirrorlist = http://mirrorlist.repoforge.org/el6/mirrors-rpmforge
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge
enabled = 0 # 1 -> 0
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1
setting them explicitly with option, you can use.
try to get information about php
CentOS
# yum --enablerepo=epel,remi,rpmforge info php

Name        : php
Arch        : x86_64
Version     : 5.4.22
Release     : 1.el6.remi
Size        : 2.7 M
Repo        : remi
Summary     : PHP scripting language for creating dynamic web sites
URL         : http://www.php.net/
License     : PHP and Zend and BSD
Description : PHP is an HTML-embedded scripting language. PHP attempts to make it
            : easy for developers to write dynamically generated web pages. PHP also
            : offers built-in database integration for several commercial and
            : non-commercial database management systems, so writing a
            : database-enabled webpage with PHP is fairly simple. The most common
            : use of PHP coding is probably as a replacement for CGI scripts.
            :
            : The php package contains the module (often referred to as mod_php)
            : which adds support for the PHP language to Apache HTTP Server.
OK, Let’s go on.
CentOS
# yum --enablerepo=epel,remi,rpmforge install php php-mysql php-devel
and install MySQL.
CentOS
# yum --enablerepo=epel,remi,rpmforge install mysql-server mysql-devel

Initialise

along with php, apache web server is installed automatically.if you type php -v, you can confirm it is installed but start web server and check it. because it’s very easy.
CentOS
# service httpd start
CentOS
# echo '<?php phpinfo(); ?>' > /var/www/html/phpinfo.php
Open a browser in host and type IP address you set. (ex, 192.168.56.10/phpinfo.php or centos that I set before)
Can you see this screen in your browser?
phpinfo
OK next setup MySQL
CentOS
# service mysqld start
CentOS
$ mysql_secure_installation
configure charcter set to UTF-8
CentOS
# vim /etc/my.cnf
/etc/my.cnf
[mysqld]
.
.
#add bellow
character-set-server = utf8
skip-character-set-client-handshake
After change config file, do restart.
CentOS
# service mysqld restart
Login and confirm setting.
CentOS
$ mysql -u root -p
Enter password: # while mysql_secure_installation you set password you know
MySQL
mysql> staus
.
.
# check them like this
Server characterset: utf8
Db     characterset: utf8
Client characterset: utf8
Conn.  characterset: utf8

Done