编译安装centos6.9 php7.0 mysql5.6 nginx1.8

2018年3月15日 11:41:40 注意文章时效! 此文章不是给新用户参考的,没有每一步的操作,请注意!

yum -y groupinstall "Development Tools" "Server Platform Development"

yum install
-y gcc gcc-c++ make cmake automake autoconf gd file bison patch mlocate flex diffutils zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel libcurl libcurl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers openldap-devellibxslt-devel kernel-devel libtool-libs readline-devel gettext-devel libcap-devel php-mcrypt libmcrypt libmcrypt-devel recode-devel yum install -y libxml2 libxml2* openssl-dev libcurl3-openssl-dev openssl-devel.i686 openssl-perl.i686 libcurl-devel.i686 libjpeg-turbo-devel.i686 libpng.i686 libpng-devel.i686l freetype-devel php-gd

依赖包

如果是测试或者学习可以一步一步的快照,弄完一个一步快照,如果弄坏了好恢复

下载包和地址

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.21.tar.gz   可能获取不到 去官网下载,如果不会百度

wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.39.tar.gz wget http://cn2.php.net/distributions/php-7.0.28.tar.gz http://nginx.org/download/ wget http://nginx.org/download/nginx-1.8.0.tar.gz

安装mysql

#创建群组
groupadd mysql
#创建一个用户,不允许登陆和不创主目录
useradd -s /sbin/nologin -g mysql -M mysql

cmake 
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql 
-DMYSQL_DATADIR=/usr/local/mysql/data 
-DSYSCONFDIR=/etc 
-DWITH_MYISAM_STORAGE_ENGINE=1 
-DWITH_INNOBASE_STORAGE_ENGINE=1 
-DWITH_MEMORY_STORAGE_ENGINE=1 
-DWITH_READLINE=1 
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock 
-DMYSQL_TCP_PORT=3306 
-DENABLED_LOCAL_INFILE=1 
-DWITH_PARTITION_STORAGE_ENGINE=1 
-DEXTRA_CHARSETS=all 
-DDEFAULT_CHARSET=utf8 
-DDEFAULT_COLLATION=utf8_general_ci 
-DMYSQL_USER=mysql 
-DWITH_DEBUG=0 
-DWITH_SSL=system
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock  注意,mysql本地访问sock速度更好 ,没有权限问题,更不容易出问题

mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists 如果不是公用目录可能出现权限问题


#进入support-files目录
cd support-files/
#如果还有my.cnf请备份
mv /etc/my.cnf /etc/my.cnf.bak
#如果愿意也可以复制配置文件到etc下
cp my-default.cnf /etc/my.cnf
#执行初始化配置脚本,创建系统自带的数据库和表,注意配置文件的路径
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
#拷贝mysql安装目录下support-files服务脚本到init.d目录
cp support-files/mysql.server /etc/init.d/mysqld
#赋予权限
chmod +x /etc/init.d/mysqld
#设置开机启动
chkconfig mysqld on
#启动MySQL
service mysqld start
#修改/etc/profile文件
vi /etc/profile
#在文件末尾添加
PATH=/usr/local/mysql/bin:$PATH
export PATH
#让配置立即生效
 
source /etc/profile
#登陆测试,默认是没有密码,直接回车就可进入
 
mysql -uroot -p
 
#设置mysql密码
/usr/local/mysql/bin/mysqladmin -uroot -p password '你的密码'
#登陆进命令行模式


[client]
#password   = your_password
port        = 3306
socket      = /tmp/mysql.sock

[mysqld]
port        = 3306
socket      = /tmp/mysql.sock
datadir = /usr/local/mysql/var
skip-external-locking
key_buffer_size = 64M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
net_buffer_length = 8K
read_buffer_size = 1M
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 16M
thread_cache_size = 32
query_cache_size = 32M
tmp_table_size = 64M
performance_schema_max_table_instances = 500

explicit_defaults_for_timestamp = true
#skip-networking
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535

log-bin=mysql-bin
binlog_format=mixed
server-id   = 1
expire_logs_days = 10

default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_data_home_dir = /usr/local/mysql/var
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /usr/local/mysql/var
innodb_buffer_pool_size = 256M
innodb_log_file_size = 64M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 64M
sort_buffer_size = 1M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

[mysqld_safe]
log-error=/usr/local/mysql/log/mysql.log
pid-file=/usr/local/mysql/mysqld.pid

配置文件,如果你按照我上面的配置,就不用配置文件,但是线上就需要

安装php7.0

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make && make install
cd ..
wget http://iweb.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make && make install
cd ..
wget http://hivelocity.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2
tar jxvf mhash-0.9.9.9.tar.bz2
cd mhash-0.9.9.9
./configure
make && make install
cd ..
wget http://iweb.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
./configure
make && make install
cd ..

i  /etc/ld.so.conf
#最后一行添加
/usr/local/lib/
#载入
ldconfig
#创建群组
groupadd www
#创建一个用户,不允许登陆和不创主目录
useradd -s /sbin/nologin -g www -M www
#立即启动php-fpm
service php-fpm start

编译

./configure --prefix=/usr/local/php 
--with-config-file-path=/etc 
--with-mysql-sock=/var/lib/mysql/mysql.sock 
--with-mcrypt=/usr/include 
--with-mhash 
--with-openssl 
--with-mysqli=shared,mysqlnd 
--with-pdo-mysql=shared,mysqlnd 
--with-gd 
--with-iconv 
--with-zlib 
--enable-zip 
--enable-inline-optimization 
--disable-debug 
--disable-rpath 
--enable-shared 
--enable-xml 
--enable-bcmath 
--enable-shmop 
--enable-sysvsem 
--enable-mbregex 
--enable-mbstring 
--enable-ftp 
--enable-gd-native-ttf 
--enable-pcntl 
--enable-sockets 
--with-xmlrpc 
--enable-soap 
--without-pear 
--with-gettext 
--enable-session 
--with-curl 
--with-openssl 
--with-jpeg-dir 
--with-freetype-dir 
--enable-opcache 
--enable-fpm 
--with-fpm-user=www 
--with-fpm-group=www 
--without-gdbm 
--enable-fileinfo 
--with-pgsql 
--enable-calendar
--enable-fileinfo  composer 需要
ERROR: No pool defined. at least one pool section must be specified in
这个因为 没有执行这个
yum install -y libxml2 libxml2* openssl-dev libcurl3-openssl-dev openssl-devel.i686 
openssl-perl.i686 libcurl-devel.i686 libjpeg-turbo-devel.i686 libpng.i686 libpng-devel.i686l freetype-devel php-gd

缺依赖

mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
#注意:发现启动时错误,配置文件无法找到,需要mv /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/default.conf
#复制php.ini配置文件
cp php.ini-production /usr/local/php/etc/php.ini
#复制php-fpm启动脚本到init.d
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
#赋予执行权限
chmod +x /etc/init.d/php-fpm
#添加为启动项
#chkconfig --add php-fpm
#设置开机启动
chkconfig php-fpm on

service php-fpm start

还有sock模式,nginx在配置文件里面直接访问sock,现在也比较流行

 nginx安装

 
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz
注:如果地址失效,可以使用http://ufpr.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.zip
tar -zxvf pcre-8.35.tar.gz
cd pcre-8.35
./configure
make && make install
wget http://zlib.net/zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make && make install
wget http://nginx.org/download/nginx-1.8.0.tar.gz
tar zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure 
--user=www 
--group=www 
--prefix=/usr/local/nginx 
make && make install
cd ..

最新版是1.9.9

vi /etc/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:      /etc/sysconfig/nginx
# pidfile:     /var/run/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)
 
sysconfig="/etc/sysconfig/$prog"
lockfile="/var/lock/subsys/nginx"
pidfile="/usr/local/nginx/logs/nginx.pid"
 
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
 
[ -f $sysconfig ] && . $sysconfig
 
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 -p $pidfile $prog
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
 
restart() {
    configtest_q || return 6
    stop
    start
}
 
reload() {
    configtest_q || return 6
    echo -n $"Reloading $prog: "
    killproc -p $pidfile $prog -HUP
    echo
}
 
configtest() {
    $nginx -t -c $NGINX_CONF_FILE
}
 
configtest_q() {
    $nginx -t -q -c $NGINX_CONF_FILE
}
 
rh_status() {
    status $prog
}
 
rh_status_q() {
    rh_status >/dev/null 2>&1
}
 
# Upgrade the binary with no downtime.
upgrade() {
    local oldbin_pidfile="${pidfile}.oldbin"
 
    configtest_q || return 6
    echo -n $"Upgrading $prog: "
    killproc -p $pidfile $prog -USR2
    retval=$?
    sleep 1
    if [[ -f ${oldbin_pidfile} && -f ${pidfile} ]];  then
        killproc -p $oldbin_pidfile $prog -QUIT
        success $"$prog online upgrade"
        echo
        return 0
    else
        failure $"$prog online upgrade"
        echo
        return 1
    fi
}
 
# Tell nginx to reopen logs
reopen_logs() {
    configtest_q || return 6
    echo -n $"Reopening $prog logs: "
    killproc -p $pidfile $prog -USR1
    retval=$?
    echo
    return $retval
}
 
case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest|reopen_logs)
        $1
        ;;
    force-reload|upgrade)
        rh_status_q || exit 7
        upgrade
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    status|status_q)
        rh_$1
        ;;
    condrestart|try-restart)
        rh_status_q || exit 7
        restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|reload|configtest|status|force-reload|upgrade|restart|reopen_logs}"
        exit 2
esac
/etc/init.d/nginx restart
#或者
service nginx restart
#设置开机启动
chkconfig nginx on
#访问测试,暂时关闭防火墙
/etc/init.d/iptables stop
#访问成功后,开启防火墙,过滤80端口
#配置80,3306端口访问
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
/etc/rc.d/init.d/iptables save
/etc/init.d/iptables restart

这个必须要改

location ~ .php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
}

 配置文件

user  www www;
 
worker_processes 1;
 
error_log  /home/wwwlogs/nginx_error.log  crit;
 
pid        /usr/local/nginx/logs/nginx.pid;
 
google_perftools_profiles /tmp/tcmalloc;
 
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
 
events
    {
        use epoll;
        worker_connections 51200;
    }
 
http
    {
        include       mime.types;
        default_type  application/octet-stream;
 
        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 50m;
 
        sendfile on;
        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 256k;
 
        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;
        gzip_proxied        expired no-cache no-store private auth;
        gzip_disable        "MSIE [1-6].";
 
        #limit_zone  crawler  $binary_remote_addr  10m;
 
        server_tokens off;
        #log format
        log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
             '$status $body_bytes_sent "$http_referer" '
             '"$http_user_agent" $http_x_forwarded_for';
 
server
    {
        listen       80;
        server_name www.cnhzz.com;
        index index.html index.htm index.php;
        root  /home/wwwroot/htdocs;
 
            location ~ .php$ {
                    fastcgi_pass   127.0.0.1:9000;
                    fastcgi_index  index.php;
                    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include        fastcgi_params;
            }
 
        location /status {
            stub_status on;
            access_log   off;
        }
 
        location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
            {
                expires      30d;
            }
 
        location ~ .*.(js|css)?$
            {
                expires      12h;
            }
 
        access_log  /home/wwwlogs/access.log  access;
    }
include vhost/*.conf;
}

这个用户组,nginx权可以 chown -R www:www  /usr/local/nginx

参看文章 http://www.pangxieke.com/linux/981.html

原文地址:https://www.cnblogs.com/zx-admin/p/8572372.html