Views
Setting up Centos for PostgreSQL or Microsoft SQL Server
From Shadowfax
Contents |
Getting started
I recently had to install a Centos server which needed local MySQL and PostgreSQL databases as well as access to a remote Microsoft SQL Server.
- To get the centos version cat /etc/redhat-release
- To change the IP Address edit /etc/sysconfig/network-scripts/ifcfg-eth0
- To change default gateway edit /etc/sysconfig/network
- To restart the network service network restart
- To check the IP Address ifconfig
- To install software on Centos use yum (eg yum install httpd installs apache)
Apache
- yum install httpd
- service httpd start
- service httpd restart
- Web root is /var/www/html
- Log files are in /var/log/httpd
- Config file is in /etc/httpd/conf
The apache config file can be used to set up multiple virtual hosts on a single IP address
NameVirtualHost *:80 <VirtualHost *:80> ServerName yourserver.yourdomain DocumentRoot /home/websites/mysource_matrix/core/web [...] </VirtualHost> <VirtualHost *:80> ServerName yourserver.yourdomain DocumentRoot /var/www/html </VirtualHost>
PHP
- yum install php php-mbstring php-xml (need to restart apache)
Customising development for MSSQL
- yum install 'Development Tools'
- yum install freetds freetds-devel
- yum install php-devel
- yum install php-mssql
Configuring FreeTDS
FreeTDS is an ODBC driver. It is needed to access MS-SQL from PHP. freetds.conf file is found under /etc of the install directory. This is listed as being /usr/local in all the documentation - but seems to actually be / so on centos the config file is /etc/freetds.conf
It is worth uncommenting (or adding) the line
dump file = /'path'/freetds.log
where 'path' is the directory where you want the log file to be written to.
You will also need to register the server with freetds
[sqlserver]
host = sqlserver.yourdomain
port = 1433
tds version = 7.0
You can test the install by typing tsql -S servername -U 'DOMAINNAME/username' this will prompt for a password. (Note the quotes are important!). If successful it will give a command line interface into MS SQL. Note that commands must be run using go. eg
1> use MyDatabase 2> go 1> select top 10 * from MyTable 2> go
Install MySQL
- yum install mysql mysql-server mysql-devel
- yum install php-mysql
- /etc/rc.d/init.d/mysqld start
- Change the root password type mysqladmin -u root password NEWPASSWORD
- Run a command line interface into MySQL by typing mysql -u root -p
To install PHPMyAdmin (NB this gets a version compatible with PHP5.1 as centos is not currently at 5.2
- in /var/www/html wget -c http://prdownloads.sourceforge.net/phpmyadmin/phpMyAdmin-2.11.9.4-english.tar.gz?download
- tar xvfz phpMyAdmin-2.11.9.4-english.tar.gz
- mv phpMyAdmin-2.11.9.4-english admin
- rm phpMyAdmin-2.11.9.4-english.tar.gz
- full instructions!
Install PostgreSQL
- yum install postgresql postgresql-server postgresql-devel
- service postgresql start
- PostgreSQL does not install root as a user by default - so before you can log on you will need to become the postgres user (su postgres)
- And then log on psql -U postgres.
PostgreSQL command line is rather arcane - but once you get the hang of it it works reasonably well. The main things you need to know are
- \c databasename to change database
- \q to quit
- \h for SQL help
- \? for command line help
SQL commands are not processed until you enter semi-colon. At this point it will process all previously unprocessed commands. Beware!
PostgreSQL is controlled by a configuration file called pg_hba.conf located in /var/lib/pgsql/data. In order to connect to the database you may need to change the way the security method setup in this file. (See Posgres Authentication).
# TYPE DATABASE USER CIDR-ADDRESS METHOD # "local" is for Unix domain socket connections only #local all all ident sameuser local all all trust all # IPv4 local connections: #Commented out host file is the default line. ident sameuser means that the #calling user and the postgresql user must match (ie apache needs to be logged on #as a postgresql user. I never got this working #host all all 127.0.0.1/32 ident sameuser #md5 all sets Postgres to use MD5 encrypted passwords for all users host all all 127.0.0.1/32 md5 all # IPv6 local connections: host all all ::1/128 ident sameuser
Pear
In order to use PostgreSQL from MySource Matrix I also needed Pear. To Install Pear yum install php-pear
Install the following Pear Modules (pear install modulename). You can list installed packages by typing "pear list". Note that the module names are all lower case (eg pear install db)
- DB
- Archive_Tar
- Mail_Mime
- XML_HTMLSax
- XML_Parser
Note: Mail_Mime failed to install first time with an error stating it required a later installer version. This can be fixed by upgrading pear (pear upgrade-all). Also you may get a warning about the channel needing updating. To fix this use pear channel-update pear.php.net.
External Resources
- Forum post with example freetds.conf
- setting up MSSQL on centos (slightly out of date - compile should not be required if you install php-mssql as above)
- PostgreSQL reference
- PHPMyAdmin Installation Guide (Note I used an earlier version of PHPMyAdmin)
Leave your comment