William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

Tag Archives: centOS

How to determinate if a given linux is 32 or 64 bits?

How to determinate if a given linux is 32 or 64 bits?

When I use install Oracle Virtualbox (CentOS, Ubuntu) in windows, sometimes I am confused the installed linux is
32- or 64-bits when installed relative package such as various rpm, mongodb source etc. the command ‘uname -a‘ display:

  $ uname -a
Linux hostname 2.6.32-358.14.1.el6.i686 #1 SMP 
  ... i686 i686 i386 GNU/Linux 

Make no sense to me. In stackoverflow.com I found the answer:

  $ uname -m
  x86_64 ==> 64-bit kernel
  i686   ==> 32-bit kernel

so if return i686, it means 32-bit, while X86_64 means 64-bits. This saves me a lot when install rpm packages.
By the way, the command ‘lscpu‘ also works.


CentOS: add a 3rd open-source application into PHP extension

CentOS: add a 3rd open-source into PHP extension

In a Linux CentOS 64-Bit server, I have 2 sets of web environment:(web-server, database-server, tools, commands etc)

  • 1 is default by CentOS itself;
  • 1 is from xampp (apachefriends.org) package.

Sometimes they are conflicts with each other: php commands, mysql commands, httpd, conf files, log, lock files etc.
if missing path, they will point to wrong path, so I have to use:
$ whereis, which, type
to find the right location.

This is not the worst. While I tried to add a 3rd-module as a php extension, the Ambiguous environments prevent it from working. I encountered some problems and when googled, I found the solutions are scattered and incomplete, so here I summarized what I did to make it successfully work from a very basic installed CentOS 6.2 server.

Get CentOS version

Because 3rd application needs Linux version supports, so first we need to find out CentOS server version, using the following commands:

$ cat /etc/redhat-release
$ cat /etc/issue
CentOS release 6.2 (Final)
$ rpm -q centos-release

Some potential issues

problems: xampp’s application are 32-bit LSB environments, which CentOS are 64-bits. It doesn’t matter 32-bit xampp can work in 64-bit CentOS. But 64-bit 3rd pacakge can not work in 32-bit xmp PHP environment.

$ file /opt/lampp/bin/php
php: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.2.0, stripped

$ file /usr/bin/php
php: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

So do for other commands. 32-bit and 64-bit shared dynamic objects are not Compatible, so the package runned by /opt/lampp/bin/php *CAN NOT* compatible with /usr/sbin/php environment. By default CentOS doesn’t include development tools; if need, I have to install by myself.

Since the server has very basic installation, I had to install the development tools before the php-extension.

The following development tools are needed to build the development environment:
1) g++/c++ enivronment(include autoconf, automake, m4, gnulib, libtool etc) which 3rd source codes are need to compile and build.
2) php development environment(include phpize, php-config etc) which extends 3rd library into PHP extension.

CentOS has wonderful yum for the package management, while Unbuntu has apt-get. Here we use yum to install system development environment:

 $ yum grouplist
//1. for ./configure, make, automake, autoconf.
$ sudo yum groupinstall 'Development tools'

//2. forphpize, php-chkconfig.
$ sudo yum install php-devel

Follow the prompt to install. That’s it.

General steps for 3rd open sources installation

After setup the environment, it’s time to install 3rd open-source PHP-extension. Suppose the library is called demo, Here I list the common steps to do so:

//1. download sources:
$ wget demo.tar.bz2
$ tar xvjf demo.tar.bz2
$ cd demo

//2. compile and make install
$ ./configure --prefix=...; make; sudo make install

//3. Here we generate .so, .la files. Then add the libaray as php extension:
$ cd php-extension

//4. make sure the path of phpize and php-config are correct, not confusion
$ whereis phpize; which php-config

//5. make sure 'phpize', 'php-config' are in the right path.
$ phpize
$./configure --with-demo=... --with-php-config=`which php-config`
$ make; make test; sudo make install

Configure the PHP extension

After demo module’s (demo.so) installation, the next step is to add it as a PHP extension in php.ini.

;extension = demo.so
;scws.default.charset = utf-8
;scws.default.fpath = /usr/local/demo/etc

Restart the http server to make it activate:
$ sudo /etc/init.d/httpd restart
Now there is a new item added into php core: the <demo> section will display correctly when view by phpinfo().

The key is to distinguish different pacakges in a single server, not to confuse with each other:
Which php, phpize, php-config are you using? You can do some extra work in $HOME/.bash_profile, .bashrc to set PATH, and also make sure what files are in what directory.

Also, the following file are common used for checking:


CentOS: network configuration files

We can use centos’ commands like chkconfig, service, hostname, uname to access system config and resource; Here I list 4 files regarding on networking configuration.

1. /etc/hosts

The main purpose of this file is to resolve hostnames that cannot be resolved any other way. It can also be used to resolve hostnames on small networks with no DNS server. Regardless of the type of network the computer is on, this file should contain a line specifying the IP address of the loopback device ( as localhost.localdomain. For example: localhost.localdomain localhost localhost.cloud.com example.com other_virtual_machine.com

2. /etc/resolv.conf

This file specifies the IP addresses of DNS servers and the search domain. Unless configured to do otherwise, the network initialization scripts populate this file. For more information, refer to the resolv.conf man page (man resolv.conf).

3. /etc/sysconfig/network

This file specifies routing and host information for all network interfaces. For example:

4. /etc/sysconfig/network-scripts/ifcfg-<interface-name>

For each network interface, there is a corresponding interface configuration script. Each of these files provide information specific to a particular network interface.

[root@localhost network-scripts]# cat ifcfg-eth0

Interface Configuration Files are usually named ifcfg-<name>, where <name> refers to the name of the device that the configuration file controls.

One of the most common interface files is ifcfg-eth0, which controls the first Ethernet network interface card or NIC in the system. In a system with multiple NICs, there are multiple ifcfg-eth<X> files (where <X> is a unique number corresponding to a specific interface). Because each device has its own configuration file, an administrator can control how each interface functions individually.

Install CentOS 5.8

Install CentOS 5.8

Recently I installed CentOS 5.8 in a virtual host by using VMware vSphere Client tool. CentOS is a community Enterprise-class Linux Distribution(CentOS stands for Community ENTerprise Operating System). Currently latest version is 6.2; for back-compatible reason, I download version 5 (release 5.8).

1. For Linux, I ever used several OS systems, from RedHat, Fedora(community-supported Project, sponsored by Red Hat), Ubuntu (a GUI + Sudo system) to current CentOS, and find CentOS and RedHat are alike traditional UNIX system, thus much easily to use and control, much better than Fedora and Ubuntu. Besides, CentOS is free of charge, so it should be the first choice for experience LAMP professionals.

2. The install media are generally ISO images. The CentOS ISO images installation modes are various, can be from Internet (netinstall), remote computer (connect repository directory to remote installation virtual host), DVS/CD-RW (LiveCD), Floppy Disk, etc.

Burn DVD/CD-RW is not necessary. This time I directly use the ISO images located in remote computer to finish the installation. Steps:

  • Download all CentOS ISO images to locally in C:\centOS\ directory. I download the CD version, total 8 ISO files; It would be better to download DVD version which only 2 ISO files. It took time to do so since each of them is greater than 600MB;
  • Open vSphere Client, in tool bar, connect C:\centOS\centOSimage1.iso to remote virtual host server.
  • Install can start right away from the immediate connection. It is just like install from a local media.
  • Active the control terminal, when boot: promoter occurs, click to start installation.
  • The installation process is pretty easy, just follow the steps, the 2 difficult points might be: network configuration and email setup.

Reference: here is a CentOS Installation Guide. Not latest version, but helpful for installation.