1. 程式人生 > >centos6安裝nginx1.7.9+php5.6.4+mysql5.6

centos6安裝nginx1.7.9+php5.6.4+mysql5.6

centos6 下安裝nginx1.7.9+php5.6.4+mysql5.6.2

1. 安裝關聯庫

# mkdir -p /data/tgz

# cd /data/tgz

# yum install wget

# yum install pcre

# yum install openssl*

# yum install tar

# yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devellibpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-develglibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curlcurl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel opensslopenssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-serversmake gd gd2 gd-devel gd2-devel

# ulimit -SHn 65535

# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz

# tar zxvf pcre-8.36.tar.gz

# cd pcre-8.36

# ./configure --prefix=/data/apps/pcre

# make && make install

# cd ../

2. 安裝nginx

# /usr/sbin/groupadd nginx

# /usr/sbin/useradd -g nginx nginx

# wget http://nginx.org/download/nginx-1.7.9.tar.gz

# tar zxvf nginx-1.7.9.tar.gz

# cd nginx-1.7.9

# ./configure --user=nginx --group=nginx --prefix=/data/apps/nginx--with-http_stub_status_module --with-http_ssl_module --with-pcre=/data/tgz/pcre-8.36--with-http_realip_module --with-http_image_filter_module

# make && make install

# cd ../

3. 安裝MySQL

# /usr/sbin/groupadd mysql

# /usr/sbin/useradd -g mysql mysql

# wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.25-linux-glibc2.5-x86_64.tar.gz

# tar zxvf mysql-5.6.22-linux-glibc2.5-x86_64.tar.gz

# mv mysql-5.6.22-linux-glibc2.5-x86_64 /data/apps/mysql

    配置執行MySQL

    1)建立資料庫存放目錄

# mkdir -p /data/data/mysql/data

# mkdir -p /data/data/mysql/binlog/

# mkdir -p /data/data/mysql/relaylog/

# chown -R mysql:mysql /data/data/mysql/

# yum install libaio

    2)建立mysql配置檔案

# vi /etc/my.cnf

        輸入以下內容

[client]

port    = 3306

socket  = /tmp/mysql.sock

[mysqld]

character-set-server = utf8

replicate-ignore-db = mysql

replicate-ignore-db = test

replicate-ignore-db = information_schema

user    = mysql

port    = 3306

socket  = /tmp/mysql.sock

basedir = /data/apps/mysql

datadir = /data/data/mysql/data

log-error = /data/data/mysql/mysql_error.log

pid-file = /data/data/mysql/mysql.pid

open_files_limit   = 10240

back_log = 600

max_connections = 5000

max_connect_errors = 6000

external-locking = FALSE

max_allowed_packet = 32M

sort_buffer_size = 1M

join_buffer_size = 1M

thread_cache_size = 300

#thread_concurrency = 8

query_cache_size = 512M

query_cache_limit = 2M

query_cache_min_res_unit = 2k

default-storage-engine = MyISAM

thread_stack = 192K

transaction_isolation = READ-COMMITTED

tmp_table_size = 246M

max_heap_table_size = 246M

long_query_time = 3

log-slave-updates

log-bin = /data/data/mysql/binlog/binlog

binlog_cache_size = 4M

binlog_format = MIXED

max_binlog_cache_size = 8M

max_binlog_size = 1G

relay-log-index = /data/data/mysql/relaylog/relaylog

relay-log-info-file = /data/data/mysql/relaylog/relaylog

relay-log = /data/data/mysql/relaylog/relaylog

expire_logs_days = 30

key_buffer_size = 256M

read_buffer_size = 1M

read_rnd_buffer_size = 16M

bulk_insert_buffer_size = 64M

myisam_sort_buffer_size = 128M

myisam_max_sort_file_size = 10G

myisam_repair_threads = 1

myisam_recover

interactive_timeout = 120

wait_timeout = 120

skip-name-resolve

#master-connect-retry = 10

slave-skip-errors = 1032,1062,126,1114,1146,1048,1396

server-id = 1

innodb_additional_mem_pool_size = 16M

innodb_buffer_pool_size = 512M

innodb_data_file_path = ibdata1:256M:autoextend

innodb_file_io_threads = 4

innodb_thread_concurrency = 8

innodb_flush_log_at_trx_commit = 2

innodb_log_buffer_size = 16M

innodb_log_file_size = 128M

innodb_log_files_in_group = 3

innodb_max_dirty_pages_pct = 90

innodb_lock_wait_timeout = 120

innodb_file_per_table = 0

slow-query-log-file = /data/data/mysql/slow.log

long_query_time = 10

[mysqldump]

quick

max_allowed_packet = 32M

    3)以mysql使用者帳號的身份建立資料表

# /data/apps/mysql/scripts/mysql_install_db --basedir=/data/apps/mysql--datadir=/data/data/mysql/data --user=mysql

# sed -i "s#/usr/local/mysql#/data/apps/mysql#g"/data/apps/mysql/bin/mysqld_safe

    4)建立mysql啟動,重啟,停止shell指令碼

# vi /data/apps/mysql/mysql

        輸入以下內容(這裡的使用者名稱admin和密碼12345678接下來的步驟會建立)

#!/bin/sh

mysql_port=3306

mysql_username="admin"

mysql_password="12345678"

function_start_mysql()

{

    printf "StartingMySQL...\n"

    /bin/sh /data/apps/mysql/bin/mysqld_safe--defaults-file=/etc/my.cnf 2>&1 > /dev/null &

}

function_stop_mysql()

{

    printf "StopingMySQL...\n"

    /data/apps/mysql/bin/mysqladmin-u ${mysql_username} -p${mysql_password} -S /tmp/mysql.sock shutdown

}

function_restart_mysql()

{

    printf "RestartingMySQL...\n"

    function_stop_mysql

    sleep 5

    function_start_mysql

}

function_kill_mysql()

{

    kill -9 $(ps -ef| grep 'bin/mysqld_safe' | grep ${mysql_port} | awk '{printf $2}')

    kill -9 $(ps -ef| grep 'libexec/mysqld' | grep ${mysql_port} | awk '{printf $2}')

}

if [ "$1" = "start" ]; then

    function_start_mysql

elif [ "$1" = "stop" ]; then

    function_stop_mysql

elif [ "$1" = "restart" ]; then

function_restart_mysql

elif [ "$1" = "kill" ]; then

function_kill_mysql

else

    printf "Usage:/data/data/mysql/mysql {start|stop|restart|kill}\n"

fi

    5)賦予shell指令碼可執行許可權

# chmod +x /data/apps/mysql/mysql

    6)啟動MySQL

# /data/apps/mysql/mysql start

    7)通過命令列登入管理MySQL伺服器(提示輸入密碼時直接回車)

# /data/apps/mysql/bin/mysql -uroot -p -S /tmp/mysql.sock

    8)輸入以下SQL語句,建立一個具有root許可權的使用者(admin)和密碼(12345678)

> GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' IDENTIFIEDBY '12345678';

> GRANT ALL PRIVILEGES ON *.* TO 'admin'@'127.0.0.1' IDENTIFIEDBY '12345678';

> quit

    9)(可選)重啟/停止MySQL

# /data/apps/mysql/mysql restart

# /data/apps/mysql/mysql stop

4. 編譯安裝PHP依賴庫

# mkdir -p /data/apps/libs/

# wget http://www.ijg.org/files/jpegsrc.v9.tar.gz  

# tar zxvf jpegsrc.v9.tar.gz

# cd jpeg-9/

# ./configure --prefix=/data/apps/libs --enable-shared --enable-static

# make && make install

# cd ../

# wget http://prdownloads.sourceforge.net/libpng/libpng-1.6.2.tar.gz

# tar zxvf libpng-1.6.2.tar.gz

# cd libpng-1.6.2/

# ./configure --prefix=/data/apps/libs

# make && make install

# cd ../

# wget http://download.savannah.gnu.org/releases/freetype/freetype-2.4.12.tar.gz

# tar zxvf freetype-2.4.12.tar.gz

# cd freetype-2.4.12/

# ./configure --prefix=/data/apps/libs

# make && make install

# cd ../

# wget --content-disposition "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?big_mirror=0"

# wget --content-disposition "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?big_mirror=0"

# wget --content-disposition "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?big_mirror=0"

# tar zxvf libmcrypt-2.5.8.tar.gz

# cd libmcrypt-2.5.8/

# ./configure --prefix=/data/apps/libs

# make && make install

# cd libltdl/

# ./configure --prefix=/data/apps/libs --enable-ltdl-install

# make && make install

# cd ../../

# tar zxvf mhash-0.9.9.9.tar.gz

# cd mhash-0.9.9.9/

# ./configure --prefix=/data/apps/libs

# make && make install

# cd ../

# vi /etc/ld.so.conf

        在檔案末尾新增以下內容

/data/apps/libs/lib

        重新載入該檔案,使其即刻生效

# ldconfig

# tar zxvf mcrypt-2.6.8.tar.gz

# cd mcrypt-2.6.8/

# export LDFLAGS="-L/data/apps/libs/lib -L/usr/lib"

# export CFLAGS="-I/data/apps/libs/include -I/usr/include"

# touch malloc.h

# ./configure --prefix=/data/apps/libs --with-libmcrypt-prefix=/data/apps/libs

# make && make install

# cd ../

5. 安裝PHP

# wget --content-disposition http://cn2.php.net/get/php-5.6.4.tar.gz/from/this/mirror

# tar zxvf php-5.6.4.tar.gz

# cd php-5.6.4/

# export LIBS="-lm -ltermcap -lresolv"

# export DYLD_LIBRARY_PATH="/data/apps/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64"

# export LD_LIBRARY_PATH="/data/apps/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64"

# ./configure --prefix=/data/apps/php --with-config-file-path=/data/apps/php/etc--with-mysql=/data/apps/mysql --with-mysqli=/data/apps/mysql/bin/mysql_config --with-iconv-dir--with-freetype-dir=/data/apps/libs --with-jpeg-dir=/data/apps/libs --with-png-dir=/data/apps/libs--with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath--enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex--enable-fpm --enable-mbstring --with-mcrypt=/data/apps/libs --with-gd --enable-gd-native-ttf--with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip--enable-soap --enable-opcache --with-pdo-mysql --enable-maintainer-zts

# make && make install

# cp php.ini-development /data/apps/php/etc/php.ini

# cd ../

6. 安裝PHP擴充套件

# wget http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz

# tar zxvf autoconf-latest.tar.gz

# cd autoconf-2.69/

# ./configure --prefix=/data/apps/libs

# make && make install

# cd ../

# wget http://pecl.php.net/get/memcache-2.2.7.tgz

# tar zxvf memcache-2.2.7.tgz

# cd memcache-2.2.7/

# export PHP_AUTOCONF="/data/apps/libs/bin/autoconf"

# export PHP_AUTOHEADER="/data/apps/libs/bin/autoheader"

# /data/apps/php/bin/phpize

# ./configure --with-php-config=/data/apps/php/bin/php-config

# make && make install

# cd ../

    1)php.ini配置檔案中新增memcache擴充套件

# vi /data/apps/php/etc/php.ini

  在檔案末尾新增以下內容

extension_dir="/data/apps/php/lib/php/extensions/no-debug-zts-20131226/"

extension=memcache.so

7. 啟動nginx+php

    mysql的啟動就不在這裡多說,可參考上面。

    1)調整nginx配置檔案(這裡只是最簡單的可執行php的nginx的配置,詳細的自行)

# mv /data/apps/nginx/conf/nginx.conf /data/apps/nginx/conf/nginx.conf.default

# vi /data/apps/nginx/conf/nginx.conf

        輸入以下內容

user  nginx;

worker_processes  1;

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {

        listen       80;

        server_name  localhost;

        root /data/www;

        location / {

            index  index.html index.htm index.php;

        }

        location ~ \.php${

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            include        fastcgi.conf;

        }

    }

}

    2)建立web目錄

# mkdir -p /data/www

# chown -R nginx:nginx /data/www

    3)啟動nginx

# /data/apps/nginx/sbin/nginx

    4)啟動php-fpm

# /data/apps/php/sbin/php-fpm

現在已經安裝完成了,可以在瀏覽器中輸入http://localhost訪問網站了.

如果訪問不了,需要在容器中配置開機啟動,以至/sbin/init初始化的時候把nginx+php+mysql啟動起來,在/etc/rc.local檔案中新增nginx、php和mysql的啟動執行。