标签:white restart free insecure idf 环境变量 space func require
参考文档:
Server:CentOS-7-x86_64-1511
Client:Win7 x86_64, Chrome/Firefox浏览器
CentOS7默认自带firewall,无iptables。
[root@localhost ~]# systemctl stop firewalld.service
#停止firewall
[root@localhost ~]# systemctl disable firewalld.service
#禁止firewall开机启动
[root@localhost ~]# yum install iptables-services -y
[root@localhost ~]# vim /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
#参照开放22号端口的规则,添加两行规则开放80/3306两个端口
[root@localhost ~]# systemctl restart iptables.service
#重启iptables,使配置生效
[root@localhost ~]# systemctl enable iptables.service
#设置iptables开机启动
[root@localhost ~]# vim /etc/sysconfig/selinux
#SELINUX=enforcing #注释掉
SELINUX=disabled #新增
#SELINUXTYPE=targeted #注释掉
[root@localhost ~]# setenforce 0
#使用配置生效
源代码包存放位置:/usr/local/src
源代码编译安装位置:/usr/local/soft_name
当前最新主线版:wget http://nginx.org/download/nginx-1.9.12.tar.gz
当前最新稳定版:wget http://nginx.org/download/nginx-1.8.1.tar.gz
wget http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.11.tar.gz
当前7.0稳定版:wget http://cn2.php.net/distributions/php-7.0.4.tar.gz
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.bz2
当前稳定版:wget http://www.openssl.org/source/openssl-1.0.2g.tar.gz
wget http://zlib.net/zlib-1.2.8.tar.gz
wget https://cmake.org/files/v3.5/cmake-3.5.0.tar.gz
wget http://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
#Boost库是C++库,mysql 5.7.5开始编译必须使用boost库,
语法:-DDOWNLOAD_BOOST=1 -DWITH_BOOST=../boost _1_59_0,boost _1_60_0对mysql 5.7.11不可用
wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
wget
http://storage.googleapis.com/downloads.webmproject.org/releases/webm/libvpx-v1.3.0.tar.bz2
wget http://download.osgeo.org/libtiff/tiff-4.0.3.tar.gz
wget http://pkgs.fedoraproject.org/repo/pkgs/libpng/libpng-1.6.12.tar.gz/297388a6746a65a2127ecdeb1c6e5c82/libpng-1.6.12.tar.gz
wget http://ring.u-toyama.ac.jp/archives/graphics/freetype/freetype2/freetype-2.5.3.tar.gz
wget http://www.ijg.org/files/jpegsrc.v9a.tar.gz
wget https://bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.0.tar.gz
wget http://pkgs.fedoraproject.org/repo/pkgs/t1lib/t1lib-5.1.2.tar.gz/a5629b56b93134377718009df1435f3c/t1lib-5.1.2.tar.gz
# http://www.t1lib.org/提供的官方下载链接无法打开
yum -y install make autoconf automake gcc gcc-c++ bison bison-devel ncurses ncurses-devel
#部分依赖包已经在系统中,这里只是个人之前安装使用的依赖关系
cmake也可以通过yum安装。
cd /usr/local/src/
tar -zxvf cmake-3.5.0.tar.gz
cd cmake-3.5.0
./configure
make
make install
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql
#创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统
mkdir -p /mysql
#创建MySQL数据库存放目录
chown -R mysql:mysql /mysql
#设置MySQL数据库存放目录权限
mkdir -p /usr/local/mysql
#创建MySQL安装目录basedir
cd /usr/local/src
tar -zxvf boost_1_59_0.tar.gz
#重要!
tar -zxvf mysql-5.7.11.tar.gz
cd mysql-5.7.11
详细的编译项目可以参考:http://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
#MySQL安装的根目录basedir
-DMYSQL_DATADIR=/mysql
#MySQL数据库文件存放目录datadir
-DSYSCONFDIR=/etc
#MySQL配置文件所在目录
#-DMYSQL_USER=mysql
#MySQL用户名,可以不用编译,后续初始化定义
-DWITH_MYISAM_STORAGE_ENGINE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_MEMORY_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_PARTITION_STORAGE_ENGINE=1
-DWITH_FEDERATED_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
#MySQL的数据库引擎,后面4个可以不用编译
-DWITH_READLINE=1
#MySQL的readline library,批量导入数据
#-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock
#MySQL的通讯目录,如果不编译,默认MySQL启动后在/tmp目录,可以在后续使用软链接指定到/var/lib/mysql/,如果已编译到/var/lib/mysql/,请注意目录是否具有mysql用户读写的权限
-DMYSQL_TCP_PORT=3306
-DENABLED_LOCAL_INFILE=1
-DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8
#设置默认字符集为utf8
-DDEFAULT_COLLATION=utf8_general_ci
#设置默认排序字符集规则
-DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/src/boost_1_59_0
#重要!从MySQL 5.7.5开始,boost库是必需的,否则报error 81,预编译终止。编译时允许自主下载相关文件,下载目录-DWITH_BOOST给出
make -j `grep processor /proc/cpuinfo | wc -l`
#使make命令在多个cpu上并行执行
#此版本编译非常耗系统资源,小内存可能编译通不过,2核2G内存大概用了40分钟
make install
chown -R mysql:mysql /usr/local/mysql
cd /usr/local/mysql/
rm -rf /etc/my.cnf
#删除系统默认的配置文件 (如果默认没有就不用删除)
cp support-files/my-default.cnf /usr/local/mysql/my.cnf
#复制配置样例文件并修改文件名
ln -s /usr/local/mysql/my.cnf /etc/my.cnf
#添加到/etc目录的软连接
#根据MySQL规则,它的配置文件必须以my.cnf命名,读取的顺序是先尝试读取/etc/my.cnf,如果不存在再读取basedir目录下的my.cnf,如果系统环境变量没有basedir,则尝试读取服务启动所在当前目录下的my.cnf,如果还是不存在,则读取当前用户家目录下的.mysql/my.cnf。所以可以在/etc目录下建1个my.cnf的软链接
cd /usr/local/mysql/bin/
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/mysql
#初始化生成系统数据库,在MySQL 5.7.6版本以前是basedir目录下的scripts/mysql_install_db命令,这里可以在后面跟上"--socket=/tmp/mysql.sock"指定mysql启动后的通讯录
#"--initialize"会生成一个随机密码,并在屏幕标准输出最后一行显示出来,请记住,重要!如果使用"--initialize-insecure"不会生成密码
#初始化时datadir下不能有数据文件
cd /usr/local/mysql/
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
#复制启动脚本并改名
chown mysql:mysql /etc/rc.d/init.d/mysqld
chmod 755 /etc/rc.d/init.d/mysqld
chkconfig --level 35 mysqld on
#加入开机启动
vim /etc/rc.d/init.d/mysqld
46 basedir=/usr/local/mysql
47 datadir=/mysql
#在第46/47行将basedir/datadir完善,保存退出
vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
#把mysql的多种服务加入系统环境变量,保存退出
source /etc/profile
#使配置立刻生效
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
#这两行把myslq的库文件链接到系统默认的位置,这样在编译类似PHP等软件时可以不用指定mysql的库文件地址
mkdir /var/lib/mysql
service mysqld start
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
#添加软链接,可以在预编译或初始化时指定路径,默认在/tmp目录下
mysql -uroot -p 初始密码
set password=password(‘new password‘);
#进入数据库后,必须修改初始密码
#顺便注意如果系统中安装有mysql,运行"mysql" 命令时调用的是"/usr/bin/mysql",而不是编译安装的"/usr/local/mysql/bin/mysql",可使用"which"命令查看,如是需要先卸载系统自带的mysql
yum -y install pcre-devel openssl-devel zlib-devel
#部分依赖包已经在系统中
cd /usr/local/src
mkdir -p /usr/local/pcre
tar -jxvf pcre-8.38.tar.bz2
cd pcre-8.38
./configure --prefix=/usr/local/pcre
make
make install
cd /usr/local/src
mkdir -p /usr/local/zlib
tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure --prefix=/usr/local/zlib
make
make install
cd /usr/local/src
mkdir /usr/local/openssl
tar -zxvf openssl-1.0.2g.tar.gz
cd openssl-1.0.2g
./config --prefix=/usr/local/openssl
make
make install
vim /etc/profile
export PATH=$PATH:/usr/local/openssl/bin
#把openssl的多种服务加入系统环境变量,可以在上方mysql添加的1行后面继续添加,保存退出
source /etc/profile
groupadd www
useradd -g www -s /sbin/nologin www
cd /usr/local/src
mkdir -p /usr/local/nginx
tar -zxvf nginx-1.9.12.tar.gz
cd nginx-1.9.12
./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/usr/local/src/openssl-1.0.2g --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.38
#--with-openssl=/usr/local/src/openssl-1.0.2g --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.38 重要!指向的是源码包解压所在的路径,非安装的路径,否则会报错
make
make install
chown -R www:www /usr/local/nginx
vim /etc/rc.d/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# 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"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:" | sed ‘s/[^*]*--user=\([^ ]*\).*/\1/g‘ -`
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V 2>&1 | grep ‘configure arguments:‘`
for opt in $options; do
if [ `echo $opt | grep ‘.*-temp-path‘` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
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
sleep 1
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
#复制以上内容到开机启动脚本,保存退出
chown www:www /etc/rc.d/init.d/nginx
chmod 775 /etc/rc.d/init.d/nginx
chkconfig --level 35 nginx on
service nginx start
在浏览器中打开服务器ip地址,看到以下界面说明安装成功。
写在前面:
yum -y install apr* cloog-ppl compat* cpp curl curl-devel fontconfig fontconfig-devel libXpm* libltdl* bcmath gtk+-devel gd php-gd libiconv gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng-devel libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel t1lib t1lib* mpfr ncurses* patch perl php-common policycoreutils nasm nasm*
#其余部分依赖包通过后面编译安装
cd /usr/local/src
tar -zxvf yasm-1.2.0.tar.gz
cd yasm-1.2.0
./configure
make
make install
cd /usr/local/src
tar -zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
make install
cd /usr/local/src
tar -jxvf libvpx-v1.3.0.tar.bz2
cd libvpx-v1.3.0
./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9
make
make install
cd /usr/local/src
tar -zxvf tiff-4.0.3.tar.gz
cd tiff-4.0.3
./configure --prefix=/usr/local/tiff --enable-shared
make
make install
cd /usr/local/src
tar -zxvf libpng-1.6.12.tar.gz
cd libpng-1.6.12
./configure --prefix=/usr/local/libpng --enable-shared
make
make install
cd /usr/local/src
tar -zxvf freetype-2.5.3.tar.gz
cd freetype-2.5.3
./configure --prefix=/usr/local/freetype --enable-shared
make
make install
cd /usr/local/src
tar -zxvf jpegsrc.v9a.tar.gz
cd jpeg-9a
./configure --prefix=/usr/local/jpeg --enable-shared
make
make install
cd /usr/local/src
tar -zxvf libgd-2.1.0.tar.gz
cd libgd-2.1.0
./configure --prefix=/usr/local/libgd --enable-shared --with-jpeg=/usr/local/jpeg --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --with-fontconfig=/usr/local/freetype --with-xpm=/usr/ --with-tiff=/usr/local/tiff --with-vpx=/usr/local/libvpx
make
make install
#编译需要上面列出的几个依赖包支持
cd /usr/local/src
tar -zxvf t1lib-5.1.2.tar.gz
cd t1lib-5.1.2
./configure --prefix=/usr/local/t1lib --enable-shared
make without_doc
make install
\cp -frp /usr/lib64/libltdl.so* /usr/lib/
\cp -frp /usr/lib64/libXpm.so* /usr/lib/
#重要!如系统是64位,请执行以上两条命令,否则安装php会出错 (32位系统不需要执行)
cd /usr/local/src
tar -jxvf php-7.0.4.tar.bz2
cd php-7.0.4
export LD_LIBRARY_PATH=/usr/local/libgd/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-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-xpm-dir=/usr/ --with-vpx-dir=/usr/local/libvpx/ --with-zlib-dir=/usr/local/zlib --with-t1lib=/usr/local/t1lib --with-iconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --enable-ctype
make
make install
cd /usr/local/src/php-7.0.4
cp php.ini-production /usr/local/php/etc/php.ini
#在解压包中复制php配置文件到安装目录并改名
rm -rf /etc/php.ini
#删除系统自带配置文件
ln -s /usr/local/php/etc/php.ini /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
#拷贝模板文件为php-fpm配置文件
ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf
#添加软连接到 /etc目录
vim /usr/local/php/etc/php-fpm.conf
pid = run/php-fpm.pid
#取消前面的分号,保存退出
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
vim /usr/local/php/etc/php-fpm.d/www.conf
user = www
group = www
# php-fpm.conf最后一行调用php-fpm.d目录中的".conf"文件,使用模板文件复制出1个www.conf文件,修改运行user/group
vim /usr/local/php/etc/php.ini
找到:disable_functions =
修改为:disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以取消禁用
找到:;date.timezone =
修改为:date.timezone = PRC
#设置时区
找到:expose_php = On
修改为:expose_php = Off
#禁止显示php版本的信息
找到:short_open_tag = Off
修改为:short_open_tag = ON
#支持php短标签
找到opcache.enable=0
修改为opcache.enable=1
#php支持opcode缓存
找到:opcache.enable_cli=1
修改为:opcache.enable_cli=0
#禁止支持opcode缓存
在最后一行添加:zend_extension=opcache.so
#开启opcode缓存功能
cp /usr/local/src/php-7.0.4/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
#从解压目录拷贝php-fpm到启动目录
chown www:www /etc/rc.d/init.d/php-fpm
#非必须
chmod 755 /etc/rc.d/init.d/php-fpm
chkconfig --level 35 php-fpm on
vim /usr/local/nginx/conf/nginx.conf
user www www;
#第2行,去除user注释,修改nginx运行组为www www;必须与/usr/local/php/etc/php-fpm.d/www.conf中的user/group配置相同,否则php运行出错
index index.html index.htm index.php;
#第45行,添加index.php
#pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#第65~71行,取消FastCGI server部分location的注释,注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径
cd /usr/local/nginx/html/
#进入nginx默认网站根目录
vim index.php
#新建index.php文件
<?php
phpinfo();
?>
chown -R www:www /usr/local/nginx/html/
chmod -R 700 /usr/local/nginx/html/
/etc/init.d/nginx restart
service php-fpm start
在浏览器中打开服务器:http://ip/index.php,会看到下面的界面:
标签:white restart free insecure idf 环境变量 space func require
原文地址:http://www.cnblogs.com/netonline/p/7327409.html