搭建 CentOS 6 服务器(7) - Java(Ant/Maven)、PHP(php-fpm)

(一)Java

(1)JDK

下载安装
# cd /usr/local/src
# wget --no-check-certificate --no-cookies - --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u76-b13/jdk-7u76-linux-x64.rpm -O jdk-7u76-linux-x64.rpm
# rpm -ivh jdk-7u76-linux-x64.rpm
   Preparing...            ########################################### [100%]
       1:jdk                ########################################### [100%]
   Unpacking JAR files...
            rt.jar...


设置默认JDK
# alternatives --install /usr/bin/java java /usr/java/default/bin/java 776
# alternatives --config java
There is 1 program that provides 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/java/default/bin/java

Enter to keep the current selection[+], or type selection number: 1


设置环境变量
# vi /etc/profile.d/java.sh
    #!/bin/bash
    JAVA_HOME=/usr/java/default/
    PATH=$JAVA_HOME/bin:$PATH
    export PATH JAVA_HOME
    export CLASSPATH=.
# chmod +x /etc/profile.d/java.sh
# source /etc/profile.d/java.sh


确认JDK版本
# java -version
    java version "1.7.0_76"
    Java(TM) SE Runtime Environment (build 1.7.0_76-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 24.76-b04, mixed mode)
# echo $JAVA_HOME
    /usr/java/default


(2)Ant

下载安装
# cd /usr/local/src
# wget http://mirrors.cnnic.cn/apache//ant/binaries/apache-ant-1.9.4-bin.zip
# unzip apache-ant-1.9.4-bin.zip
# mv apache-ant-1.9.4/ /opt/ant
# ln -s /opt/ant/bin/ant /usr/bin/ant


设置环境变量
# vi /etc/profile.d/ant.sh
    #!/bin/bash
    ANT_HOME=/opt/ant
    PATH=$ANT_HOME/bin:$PATH
    export PATH ANT_HOME
    export CLASSPATH=.
# chmod +x /etc/profile.d/ant.sh
# source /etc/profile.d/ant.sh


确认Ant版本
# ant -version
    Apache Ant(TM) version 1.9.4 compiled on April 29 2014
# echo $ANT_HOME
    /opt/ant


(3)Maven

下载安装
# cd /usr/local/src
# wget http://mirrors.cnnic.cn/apache/maven/maven-3/3.2.5/binaries/apache-maven-3.2.5-bin.zip
# unzip apache-maven-3.2.5-bin.zip
# mv apache-maven-3.2.5/ /opt/maven
# ln -s /opt/maven/bin/mvn /usr/bin/mvn


设置环境变量
# vi /etc/profile.d/maven.sh
    #!/bin/bash
    MAVEN_HOME=/opt/maven
    PATH=$MAVEN_HOME/bin:$PATH
    export PATH MAVEN_HOME
    export CLASSPATH=.
# chmod +x /etc/profile.d/maven.sh
# source /etc/profile.d/maven.sh


确认Maven版本
# mvn -version
    Apache Maven 3.2.5 .....
# echo $MAVEN_HOME
    /opt/maven


(二)PHP

安装依赖库
# yum -y install bzip2-devel curl-devel libjpeg-devel libpng-devel freetype-devel libc-client-devel.i686 libc-client-devel libmcrypt-devel libxml2-devel krb5-devel 


下载安装
# cd /usr/local/src
# wget -O php-5.6.6.tar.gz http://cn2.php.net/get/php-5.6.6.tar.gz/from/this/mirror
# tar -zxvf php-5.6.6.tar.gz
# cd php-5.6.6
# ./configure --enable-bcmath --with-bz2 --enable-calendar --with-curl --enable-exif --enable-ftp --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --with-imap --with-imap-ssl --with-kerberos --enable-mbstring --with-mcrypt --with-mhash --with-mysql --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-zlib-dir --with-regex --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-soap --enable-sockets --with-xmlrpc --enable-zip --with-zlib --enable-inline-optimization --enable-mbregex --enable-opcache --enable-fpm --with-apxs2=/usr/local/apache2/bin/apxs --prefix=/usr/local/php
# make
# make install


配置PHP
# cd /usr/local/php/lib
# cp /usr/local/src/php-5.6.6/php.ini-development ./php.ini
# vi php.ini
    short_open_tag = On
    disable_functions = exec,passthru,shell_exec,system,proc_open,popen
    expose_php = Off
    display_errors = Off
    display_startup_errors = Off
    log_errors = On


设置环境变量
# vi /etc/profile.d/php.sh
    #!/bin/bash
    PHP_HOME=/usr/local/php
    PATH=$PHP_HOME/bin:$PATH
    export PATH PHP_HOME
    export CLASSPATH=.
# chmod +x /etc/profile.d/php.sh
# source /etc/profile.d/php.sh


确认PHP版本
# php -v
    PHP 5.6.6 (cli) (built: Mar  6 2015 16:57:48)
    Copyright (c) 1997-2015 The PHP Group
    Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies


追加模块(以pgsql为例)
# /usr/local/php/bin/php -m
    [PHP Modules]
    bcmath
    ......
    zlib

    [Zend Modules]
# php -m | grep pgsql
# cd /usr/local/src/php-5.6.6/ext/pgsql/
# phpize
# ./configure --with-pgsql=/usr/local/pgsql
# make
# make install
    Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/
# vi /usr/local/php/lib/php.ini
    extension_dir="/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/"
    extension=pgsql.so
# php -m | grep pgsql


设置php-fpm
# cp /usr/local/src/php-5.6.6/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# cd /usr/local/php/etc
# cp php-fpm.conf.default php-fpm.conf
# chmod +x php-fpm
# service php-fpm start
# service php-fpm status


链接nginx和php-fpm
# vi /usr/local/nginx/conf/nginx.conf
    location ~ \.php$ {
         root /usr/local/nginx/html;
         fastcgi_pass     127.0.0.1:9000;
         fastcgi_index    index.php;
         fastcgi_param    SCRIPT_FILENAME   $document_root$fastcgi_script_name;
         include fastcgi_params;
    }


FastCGI访问量大时易出现502,交给apache处理比较好。
引用
location ~ .(php)?$ {
  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_pass http://127.0.0.1:88;
}


链接apache和php
# vi /usr/local/apache2/conf/httpd.conf
    LoadModule php5_module modules/libphp5.so

    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
    </FilesMatch>

    DirectoryIndex index.php

    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps

你可能感兴趣的:(centos)