贴出最新的php,mysql安装脚本
2013-07-29 tech

省的以后自己一路改别人的安装脚本,蛋疼死,参考已经跑路的Administrator写的脚本,剥离无用的地方,剩下必须的命令,留作参考
CENTOS 6.4 32Bit适用

先安装依赖库

1
2
yum install -y -q gcc gcc-c++ cmake make libtool-ltdl libtool-ltdl-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel bison zlib zlib-devel libtool file libevent libevent-devel
yum install -y -q sendmail libxml2 libxml2-devel openssl openssl-devel curl curl-devel bzip2 bzip2-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel pcre pcre-devel libmcrypt libmcrypt-devel mhash mhash-devel ImageMagick ImageMagick-devel tcp_wrappers-devel tcp_wrappers redhat-lsb readline readline-devel unzip

解除cp,rm命令的参数绑定

1
2
unalias cp
unalias rm

解除内核安全限制

1
2
3
4
5
6
7
8
setenforce 0 >  /dev/null  2>>/root/error.log
sed -i 's/SELINUX=enforcing/#SELINUX=enforcing/' /etc/selinux/config
echo 'SELINUX=disabled' >> /etc/selinux/config
echo /lib >> /etc/ld.so.conf
echo /usr/lib >> /etc/ld.so.conf
echo /usr/lib64 >> /etc/ld.so.conf
echo /usr/local/lib >> /etc/ld.so.conf
ldconfig

下文件,解压…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
mkdir /tmp/file_down
cd /tmp/file_down
wget http://www.percona.com/redir/downloads/Percona-Server-5.6/LATEST/source/tarball/percona-server-5.6.21-70.1.tar.gz
tar zxf percona-server-5.6.21-70.1.tar.gz
wget http://www.nih.at/libzip/libzip-0.11.2.tar.gz
tar zxf libzip-0.11.2.tar.gz
wget http://nginx.org/download/nginx-1.7.8.tar.gz
tar zxf nginx-1.7.8.tar.gz
wget http://jp1.php.net/distributions/php-5.6.3.tar.gz
tar zxf php-5.6.3.tar.gz
wget http://pecl.php.net/get/imagick-3.2.0RC1.tgz
tar zxf imagick-3.2.0RC1.tgz
wget http://pecl.php.net/get/memcache-3.0.8.tgz
tar zxf memcache-3.0.8.tgz
wget http://www.memcached.org/files/memcached-1.4.21.tar.gz
tar zxf memcached-1.4.21.tar.gz
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar zxf libiconv-1.14.tar.gz
wget http://downloads.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar zxf libmcrypt-2.5.8.tar.gz

编译mysql

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
groupadd mysql
useradd -s /sbin/nologin -M -g mysql mysql
cd percona-server-5.6.21-70.1
cmake . -LAH -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DMYSQL_DATADIR=/var/lib/mysql -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DCURSES_LIBRARY=/usr/lib/libcurses.so -DCURSES_INCLUDE_PATH=/usr/include -DMYSQL_TCP_PORT=3306 -DEXTRA_CHARSETS=all -DSYSCONFDIR=/etc/ -DWITH_ZLIB=system -DWITH_READLINE=TRUE
make
make install
ln -s /usr/local/mysql/lib/* /usr/lib/
chown -R mysql:mysql /usr/local/mysql
cp -f support-files/my-default.cnf /etc/my.cnf
sed -i 's#log-bin=mysql-bin# #' /etc/my.cnf
sed -i 's#binlog_format=mixed# #' /etc/my.cnf
sh scripts/mysql_install_db.sh --basedir=/usr/local/mysql --datadir=/var/lib/mysql --user=mysql
cp -f support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
service mysqld start
chkconfig --level 345 mysqld on
ln -s /usr/local/mysql/bin/myisamchk /usr/bin/
ln -s /usr/local/mysql/bin/mysql /usr/bin/
ln -s /usr/local/mysql/bin/mysqldump /usr/bin/
ln -s /usr/local/mysql/lib/libperconaserverclient.so.18.1.0 /usr/local/mysql/lib/libmysqlclient.so
/usr/local/mysql/bin/mysqladmin -h 127.0.0.1 -u root password 你的MYSQL密码
mysql -u root -p你的MYSQL密码 -h 127.0.0.1 <<QUERY_INPUT
use mysql;
delete from user where not (user='root') ;
delete from user where user='root' and password='';
drop database test;
DROP USER ''@'%';
flush privileges;
QUERY_INPUT
service mysqld stop

装PHP环境

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
cd ..
cd libiconv-1.14/
./configure --prefix=/usr/local
make
make install
cd ..
cd libmcrypt-2.5.8/
./configure --prefix=/usr
make
make install
cd libltdl/
./configure --enable-ltdl-install
make
make install
service sendmail restart
chkconfig --level 345 sendmail on
cd ..
cd ..
cd libzip-0.11.2
./configure
make
make install
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/
ldconfig
cd php-5.6.3
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql/bin/mysql_config --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-fpm --with-mcrypt=/usr/local/libmcrypt --with-zlib --enable-mbstring --with-openssl --with-gd --with-jpeg-dir=/usr/lib --enable-gd-native-ttf --with-gettext --with-curl --enable-sockets --enable-bcmath --enable-xml --with-bz2 --with-gettext --enable-zip --with-libzip --enable-mbregex --with-config-file-path=/etc --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --disable-rpath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbstring --enable-gd-native-ttf --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --with-pear=/usr/local/php/pear --without-pear --with-iconv=/usr/local/ --enable-exif --enable-ftp --with-readline
make
make install
cp -f ./php.ini-production /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf
mv ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
ln -s /usr/local/php/bin/php /usr/bin/php
ln -s /usr/local/php/bin/phpize /usr/bin/phpize
sed -i 's#;pid = run/php-fpm.pid#pid = run/php-fpm.pid#' /usr/local/php/etc/php-fpm.conf
sed -i 's#user = nobody#user = www#' /usr/local/php/etc/php-fpm.conf
sed -i 's#group = nobody#group = www#' /usr/local/php/etc/php-fpm.conf
sed -i 's#;pm.min_spare_servers = 5#pm.min_spare_servers = 5#' /usr/local/php/etc/php-fpm.conf
sed -i 's#;pm.max_spare_servers = 35#pm.max_spare_servers = 35#' /usr/local/php/etc/php-fpm.conf
sed -i 's#;pm.start_servers = 20#pm.start_servers = 20#' /usr/local/php/etc/php-fpm.conf
sed -i 's#;listen.mode = 0660#listen.mode = 0660#' /usr/local/php/etc/php-fpm.conf
sed -i 's#;listen.owner = nobody#listen.owner = www#' /usr/local/php/etc/php-fpm.conf
sed -i 's#;listen.group = www#listen.group = www#' /usr/local/php/etc/php-fpm.conf
sed -i 's#listen = 127.0.0.1:9000#listen = "/tmp/php-cgi.sock"#' /usr/local/php/etc/php-fpm.conf
cd ..
cd imagick-3.2.0RC1
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-imagick=/usr/local/imagemagick
make
make install
cd ..
cd memcached-1.4.21
./configure
make
make install
cd ..
cd memcache-3.0.8
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ..
chown www:www /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/*
sed -i 's#; extension_dir = "./"#extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/"\
extension = imagick.so\
extension = memcache.so#' /etc/php.ini
sed -i 's#short_open_tag = Off#short_open_tag = On#' /etc/php.ini
sed -i 's#;cgi.fix_pathinfo=1#cgi.fix_pathinfo=0#g' /etc/php.ini
sed -i 's#;cgi.fix_pathinfo=0#cgi.fix_pathinfo=0#g' /etc/php.ini
sed -i 's#upload_max_filesize = 2M#upload_max_filesize = 64M#g' /etc/php.ini
sed -i 's#post_max_size = 8M#post_max_size = 64M#g' /etc/php.ini
sed -i 's#;sendmail_path =#sendmail_path = sendmail -t -i#g' /etc/php.ini
chkconfig --level 345 php-fpm on
cd nginx-1.7.8
NPS_VERSION=1.9.32.2
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-${NPS_VERSION}-beta.zip
unzip release-${NPS_VERSION}-beta.zip
cd ngx_pagespeed-release-${NPS_VERSION}-beta/
wget https://dl.google.com/dl/page-speed/psol/${NPS_VERSION}.tar.gz
tar -xzvf ${NPS_VERSION}.tar.gz
cd ..
wget -O ngx_http_substitutions_filter_module.zip https://github.com/yaoweibin/ngx_http_substitutions_filter_module/archive/master.zip
unzip ngx_http_substitutions_filter_module.zip
wget http://wiki.nginx.org/images/5/51/Nginx-accesskey-2.0.3.tar.gz
tar zxvf Nginx-accesskey-2.0.3.tar.gz
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_spdy_module --add-module=/tmp/file_down/nginx-1.7.8/ngx_pagespeed-release-${NPS_VERSION}-beta --add-module=/tmp/file_down/nginx-1.7.8/ngx_http_substitutions_filter_module-master --add-module=/tmp/file_down/nginx-1.7.8/nginx-accesskey-2.0.3
make
make install

把下列内容保存在/etc/init.d/nginx中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

lockfile=/var/lock/subsys/nginx

start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}

stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}

restart() {
configtest || return $?
stop
start
}

reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}

force_reload() {
restart
}

configtest() {
$nginx -t -c $NGINX_CONF_FILE
}

rh_status() {
status $prog
}

rh_status_q() {
rh_status >/dev/null 2>&1
}

case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac

然后

1
2
3
4
5
chmod 755 /etc/init.d/nginx
cd ..
chown -R www:www /home/www/
mkdir /usr/local/nginx/conf/vhost/
ln -s /usr/local/nginx/conf/vhost/ /root/vhost

再保存下列内容到/usr/local/nginx/conf/nginx.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
user  www www;
worker_processes 1;
#worker_processes 8;
#worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;

worker_rlimit_nofile 51200;

events{
use epoll;
worker_connections 51200;
}

http{
include mime.types;
default_type application/octet-stream;

#charse gb2312;

server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 20m;
add_header X-Frame-Options SAMEORIGIN;

sendfile on;
server_tokens off;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;

fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
fastcgi_intercept_errors on;
fastcgi_hide_header X-Powered-By;

gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;

#limit_zone crawler $binary_remote_addr 10m;
server{
listen 80 default;
server_name _ "";
index error.html;
root /usr/local/nginx/conf/error;

location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
return 301 http://127.0.0.1;
}
include vhost/*.conf;
}

然后

1
2
3
4
5
service nginx start
chkconfig --level 345 nginx on
echo '/usr/local/bin/memcached -d -m 128 -p 11211 -u www -c 1024' >> /etc/rc.local
cd ..
rm -rf /tmp/file_down