Linux+Nginx+Mysql+PHP

1. mkdir –p /data0/software

2. cd /data0/software

3. yum install gcc gcc-c++ autoconf automake make libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses  ncurses-devel curl curl-devel e2fsprogse 2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl  openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers kernel-headers kernel-devel pcre pcre-devel openssl openssl-devel cmake ncurses-devel bison libtool-ltdl libtool-ltdl-devel  libevent-devel unixODBC unixODBC-devel libmcrypt-devel mhash-devel libxslt-devel libidn libidn-devel pcre pcre-devel krb5-libs krb5-devel

4. 为安装PHP做准备:

1.安装libiconv1.4

libiconv库为需要做转换的应用提供了iconv() 函数,以实现字符编码间的转换。

tar zxvf libiconv-1.14.tar.gz

cd libiconv-1.14/

./configure --prefix=/usr/local

make && make install

cd ../

2.安装libmcrypt

libmcrypt是加密算法扩展库,支持DES, 3DES, RIJNDAEL, Twofish, IDEA, GOST, CAST-256, ARCFOUR, SERPENT, SAFER+等算法。

tar -zxvf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8

./configure

make && make install

/sbin/ldconfig

cd libltdl

./configure -enable-ltdl-install

make && make install

cd ../../

3.安装支持库mhash

tar –zxvf mhash-0.9.9.9.tar.gz

cd mhash-0.9.9.9

./configure

make && make install

cd ../

4.建立链接文件:

ln -s /usr/local/lib/libmcrypt.la  /usr/lib/libmcrypt.la

ln -s /usr/local/lib/libmcrypt.so  /usr/lib/libmcrypt.so

ln -s /usr/local/lib/libmcrypt.so.4  /usr/lib/libmcrypt.so.4

ln -s/usr/local/lib/libmcrypt.so.4.4.8  /usr/lib/libmcrypt.so.4.4.8

ln -s/usr/local/lib/libmhash.a  /usr/lib/libmhash.a

   ln -s /usr/local/lib/libmhash.la  /usr/lib/libmhash.la

   ln -s/usr/local/lib/libmhash.so  /usr/lib/libmhash.so

   ln -s/usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2

   ln -s/usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1

   ln -s/usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

5.安装mcrypt-2.6.8

   tar -zxvfmcrypt-2.6.8.tar.gz

   cd  mcrypt-2.6.8

  /sbin/ldconfig

   ./configure

make&& make install

cd ../

5. 安装MySQL:

useradd mysql

tar -zxvf  mysql-5.1.38.tar.gz

cd mysql-5.1.38

./configure --prefix=/usr/local/mysql/  --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client  --with-big-tables --with-readline --with-ssl --with-embedded-server  --enable-local-infile  --with-plugins=innobase

  make && make install

chmod +w/usr/local/mysql

  chown -R mysql:mysql /usr/local/mysql

  mkdir –p /data0/mysql/3306/data/

  chown –R mysql:mysql /data0/mysql

  su – mysql

  /usr/local/mysql/bin/mysql_install_db –basedir=/usr/local/mysql –datadir=/data0/mysql/3306/data  –user=mysql

cd/usr/local/mysql/share/mysql

cp my-huge.cnf  /data0/mysql/3306/my.cnf

cd  /data0/mysql/3306/

cp my.cnf my.cnf.bak

vim my.cnf,修改文件,内容如下:

more  /data0/mysql/3306/my.cnf|grep -v ‘^$‘|grep -v ‘#‘

[client]

default-character-set= utf8

port            = 3306

socket          = /tmp/mysql.sock

[mysqld]

user = mysql

port            = 3306

socket          = /tmp/mysql.sock

basedir =/usr/local/mysql

datadir =/data0/mysql/3306/data

skip-locking

key_buffer_size =384M

max_allowed_packet =1M

table_open_cache =512

sort_buffer_size =2M

read_buffer_size =2M

read_rnd_buffer_size= 8M

myisam_sort_buffer_size= 64M

thread_cache_size =8

query_cache_size =32M

thread_concurrency =8

log-bin=/data0/mysql/3306/binlog

server-id       = 1

[mysqldump]

quick

max_allowed_packet =16M

[mysql]

no-auto-rehash

prompt="(\u:linxi.com:)[\d]>"

[myisamchk]

key_buffer_size =256M

sort_buffer_size =256M

read_buffer = 2M

write_buffer = 2M

[mysqlhotcopy]

interactive-timeout

   编辑mysql的启动文件:

   vim  /data0/mysql/3306/mysql,文件内容如下:

   more  /data0/mysql/3306/mysql |grep -v ‘^$‘|grep -v ‘#‘

mysql_port=3306

mysql_username="admin"

mysql_password="12345678"

function_start_mysql()

{

        printf  "Starting MySQL...\n"

 /bin/sh/usr/local/mysql/bin/mysqld_safe  --defaults-file=/data0/mysql/${mysql_port}/my.cnf 2>&1 > /dev/null&

}

function_stop_mysql()

{

        printf "Stoping MySQL...\n"

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

}

function_restart_mysql()

{

        printf  "Restarting MySQL...\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: /data0/mysql/${mysql_port}/mysql {start|stop|restart|kill

}\n"

fi

chmod +x /data0/mysql/3306/mysql

/data0/mysql/3306/mysql  start

/usr/local/mysql/bin/mysql –uroot –p –S/tmp/mysql.sock

grant all privileges on *.* to ‘admin’@’localhost’identified by ‘12345678’;

grant all privileges on *.* to ‘admin’@’127.0.0.1’identified by ‘12345678’;

grant all privileges on *.* to ‘admin’@’%’ identifiedby ‘12345678’;

flush privileges;

use mysql;

select host,user,password from user;

lsof –n –i:3306

ps –ef|grep mysqld|grep –v grep

/data0/mysql/3306/mysql  stop

6. 编译安装PHP(FastCGI模式):

tar -zxvf  php-5.4.22.tar.gz

cd php-5.4.22

cp -frp /usr/lib64/libldap* /usr/lib/

./configure--prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc  --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config  --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib  --with-libxml-dir=/usr --enable-xml --disable-rpath  --enable-bcmath --enable-shmop  --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers  --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf  --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap--with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-pear

make ZEND_EXTRA_LIBS=‘-liconv‘

make install

cp php.ini-production /usr/local/php/etc/php.ini

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

vim /etc/profile,添加:

PATH=/usr/local/php/bin:$PATH

PATH=/usr/local/php/sbin:$PATH

chmod 755/etc/init.d/php-fpm

chkconfig --addphp-fpm

/usr/local/php/sbin/php-fpm

ps -ef|grep php

7. 编译安装PHP的扩展:

tar -zxvf  memcache-2.2.5.tgz

cd  memcache-2.2.5

/usr/local/php/bin/phpize

./configure--with-php-config=/usr/local/php/bin/php-config

make  && make install

cd ../

tar –zxvf  eaccelerator-eaccelerator-42067ac.tar.gz

cd  eaccelerator-eaccelerator-42067ac

/usr/local/php/bin/phpize

./configure--enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config

  make

  make install

  cd ../

 tar –zxvf  PDO_MYSQL-1.0.2.tgz

cd PDO_MYSQL-1.0.2

/usr/local/php/bin/phpize

 ln -s/usr/local/mysql/include/mysql/* /usr/local/include/

./configure  --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql

make&& make install

cd ../

 tar -zxvf  ImageMagick-6.8.7-10.tar.gz

cd   ImageMagick-6.8.7-10

./configure

 make && make install

 cd ../

 tar -zxvf  imagick-3.1.2.tgz

  cd imagick-3.1.2

 /usr/local/php/bin/phpize

  ./configure--with-php-config=/usr/local/php/bin/php-config

  make

  make install

  cd ../

8.修改php.ini文件:

cp php.ini php.ini.bak

手工修改,查找php.ini中的extension_dir=”./”修改为:

extension_dir=”/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/”

并在此行后增加几行:

extension=”memcache.so”

extension=”pdo_mysql.so”

extension=”imagick.so”

查找output_buffering= Off改为:

output_buffering= On

修改php.ini时区:

date.timezone= Asia/Shanghai

9.配置eAccelerator加速PHP:

mkdir -p /usr/local/eaccelerator_cache

vim php.ini:

按shift+g,跳转到配置文件的最末尾,加上配置信息:

[eaccelerator]

zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/eaccelerator.so"

eaccelerator.shm_size="64"

eaccelerator.cache_dir="/usr/local/eaccelerator_cache"

eaccelerator.enable="1"

eaccelerator.optimizer="1"

eaccelerator.check_mtime="1"

eaccelerator.debug="0"

eaccelerator.filter=""

eaccelerator.shm_max="0"

eaccelerator.shm_ttl="3600"

eaccelerator.shm_prune_period="3600"

eaccelerator.shm_only="0"

eaccelerator.compress="1"

eaccelerator.compress_level="9"

10.创建www用户和组,创建虚拟机的目录:

useradd www

mkdir -p /data0/htdocs/blog

chmod +w /data0/htdocs/blog/

chown -R www:www /data0/htdocs/blog/

mkdir -p /data0/htdocs/www

chmod +w /data0/htdocs/www

chown -R www:www /data0/htdocs/www

11.创建php-fpm配置文件:

cp /usr/local/php/etc/php-fpm.conf  /usr/local/php/etc/php-fpm.conf.bak

vim /usr/local/php/etc/php-fpm.conf:

修改成下面的结果:

more php-fpm.conf|grep -v ‘^$‘|grep -v ‘;‘

[global]

pid = run/php-fpm.pid

error_log = log/php-fpm.log

log_level = notice

emergency_restart_threshold = 10

emergency_restart_interval = 1m

process_control_timeout = 5s

daemonize = yes

events.mechanism = epoll

[www]

user = www

group = www

listen = 127.0.0.1:9000

listen.mode = 0666

listen.allowed_clients = 127.0.0.1

pm = static

pm.max_children = 128

pm.start_servers = 20

pm.min_spare_servers = 5

pm.max_spare_servers = 35

pm.max_requests = 102400

slowlog = log/$pool.log.slow

request_slowlog_timeout = 0s

request_terminate_timeout = 0

rlimit_files = 65535

rlimit_core = 0

chroot =

catch_workers_output = yes

env[HOSTNAME] = $HOSTNAME

env[PATH] = /usr/local/bin:/usr/bin:/bin

env[TMP] = /tmp

env[TMPDIR] = /tmp

env[TEMP] = /tmp

env[OSTYPE] = $OSTYPE

env[MACHTYPE] = $MACHTYPE

env[MALLOC_CHECK_] = 2

php_admin_value[sendmail_path] = /usr/sbin/sendmail-t -i -f www@my.domain.com

php_flag[display_errors] = on

启动php-fpm:

/usr/local/php/sbin/php-fpm

ps –ef|grep php-fpm|grep –v ‘grep’


本文出自 “林夕” 博客,请务必保留此出处http://lutaoxu.blog.51cto.com/4224602/1548506

Linux+Nginx+Mysql+PHP

上一篇:sqlserver自定义函数与存储过程的区别 实例详解


下一篇:atitit.sql server2008导出导入数据库大的表格文件... oracle mysql