科技常识:CentOS 7.2.1511 编译安装Nginx1.10.1+MySQL5.7.14+PHP7.0.11

2021-04-18 16:38:36
导读 今天小编跟大家讲解下有关科技常识:CentOS 7 2 1511 编译安装Nginx1 10 1+MySQL5 7 14+PHP7 0 11,相信小伙伴们对这个话题应该也很关注

今天小编跟大家讲解下有关科技常识:CentOS 7.2.1511 编译安装Nginx1.10.1+MySQL5.7.14+PHP7.0.11,相信小伙伴们对这个话题应该也很关注吧,小编也收集到了有关科技常识:CentOS 7.2.1511 编译安装Nginx1.10.1+MySQL5.7.14+PHP7.0.11的相关资料,希望小伙伴会喜欢也能够帮助大家。

准备篇

一、防火墙配置

CentOS 7.x默认使用的是firewall作为防火墙,这里改为iptables防火墙。

1、关闭firewall:

systemctl stop firewalld.service #停止firewallsystemctl disable firewalld.service #禁止firewall开机启动

2、安装iptables防火墙

yum install iptables-services #安装

vi /etc/sysconfig/iptables #编辑防火墙配置文件

# sample configuration for iptables service# you can edit this manually or use system-config-firewall# please do not ask us to add additional ports/services to this default configuration*filter:INPUT ACCEPT [0:0]:FORWARD ACCEPT [0:0]:OUTPUT ACCEPT [0:0]-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT-A INPUT -p icmp -j ACCEPT-A INPUT -i lo -j ACCEPT-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT-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-A INPUT -j REJECT --reject-with icmp-host-prohibited-A FORWARD -j REJECT --reject-with icmp-host-prohibitedCOMMIT

:wq! #保存退出

systemctl restart iptables.service #最后重启防火墙使配置生效systemctl enable iptables.service #设置防火墙开机启动/usr/libexec/iptables/iptables.init restart #重启防火墙

二、关闭SELINUX

vi /etc/selinux/config#SELINUX=enforcing #注释掉#SELINUXTYPE=targeted #注释掉SELINUX=disabled #增加:wq! #保存退出setenforce 0 #使配置立即生效

三 、系统约定

软件源代码包存放位置:/usr/local/src源码包编译安装位置:/usr/local/软件名字

四、下载软件包

1、下载nginxhttp://nginx.org/download/nginx-1.10.1.tar.gz2、下载MySQLhttp://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.33.tar.gz3、下载phphttp://cn2.php.net/distributions/php-5.6.26.tar.gz4、下载cmake(MySQL编译工具)https://cmake.org/files/v3.6/cmake-3.6.2.tar.gz5、下载pcre (支持nginx伪静态)ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz6、下载openssl(nginx扩展)https://www.openssl.org/source/openssl-1.0.2j.tar.gz7、下载zlib(nginx扩展)http://zlib.net/zlib-1.2.8.tar.gz8、下载libmcrypt(php扩展)http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz9、下载yasm(php扩展)http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz10、t1lib(php扩展)ftp://sunsite.unc.edu/pub/Linux/libs/graphics/t1lib-5.1.2.tar.gz11、下载gd库安装包https://bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.1.tar.gz12、libvpx(gd库需要)http://ftp.osuosl.org/pub/blfs/conglomeration/libvpx/libvpx-1.6.0.tar.bz213、tiff(gd库需要)http://download.osgeo.org/libtiff/tiff-4.0.6.tar.gz14、libpng(gd库需要)ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng16/libpng-1.6.25.tar.gz15、freetype(gd库需要)http://download.savannah.gnu.org/releases/freetype/freetype-2.7.tar.gz16、jpegsrc(gd库需要)http://www.ijg.org/files/jpegsrc.v9b.tar.gz17、Boost(编译mysql需要)http://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz以上软件包上传到/usr/local/src目录

五、安装编译工具及库文件(使用yum命令安装)

yum install -y apr* autoconf automake bison bzip2 bzip2* cloog-ppl compat* cpp curl curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libxml* libtiff libtiff* make mpfr ncurses* ntp openssl openssl-devel patch pcre-devel perl php-common php-gd policycoreutils telnet t1lib t1lib* nasm nasm* wget zlib-devel

安装篇

以下是用putty工具远程登录到服务器,在命令行下面操作的

一、安装MySQL

1、安装cmake

cd /usr/local/srctar zxvf cmake-3.6.2.tar.gzcd cmake-3.6.2./configuremakemake install

2、安装MySQL

mkdir -p /usr/local/boostcd /usr/local/srccp boost_1_59_0.tar.gz /usr/local/boostgroupadd mysql #添加mysql组useradd -g mysql mysql -s /bin/false #创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统mkdir -p /data/mysql #创建MySQL数据库存放目录chown -R mysql:mysql /data/mysql #设置MySQL数据库存放目录权限mkdir -p /usr/local/mysql #创建MySQL安装目录cd /usr/local/src #进入软件包存放目录tar zxvf mysql-5.7.14.tar.gz #解压cd mysql-5.7.14 #进入目录cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EMBEDDED_SERVER=OFF -DWITH_BOOST=/usr/local/boost注意:可以使用-DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost参数在线安装boost软件包,需要服务器联网,容易下载失败。cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DMYSQL_USER=mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DENABLED_LOCAL_INFILE=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITH_EMBEDDED_SERVER=OFF -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boostmake #编译make install #安装编译出错, 重新编译前要删除编译失败的文件,重新编译时,需要清除旧的对象文件和缓存信息。make cleanrm -f CMakeCache.txtrm -rf /etc/my.cnf #删除系统默认的配置文件(如果默认没有就不用删除)cd /usr/local/mysql #进入MySQL安装目录./bin/mysqld --user=mysql --initialize --basedir=/usr/local/mysql --datadir=/data/mysql #生成mysql系统数据库--initialize表示默认生成密码, --initialize-insecure 表示不生成密码, 密码为空。看到这一行[Note] A temporary password is generated for root@localhost: CSJlm3DyTG.dcp /usr/local/mysql/support-files/my-default.cnf /usr/local/mysql/my.cnfln -s /usr/local/mysql/my.cnf /etc/my.cnf #添加到/etc目录的软连接cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld #把MySQL加入系统启动chmod 755 /etc/init.d/mysqld #增加执行权限chkconfig mysqld on #加入开机启动vi /etc/rc.d/init.d/mysqld #编辑basedir=/usr/local/mysql #MySQL程序安装路径datadir=/data/mysql #MySQl数据库存放目录:wq! #保存退出service mysqld start #启动vi /etc/profile #把mysql服务加入系统环境变量:在最后添加下面这一行export PATH=$PATH:/usr/local/mysql/bin:wq! #保存退出source /etc/profile #使配置立刻生效

下面这两行把myslq的库文件链接到系统默认的位置,这样你在编译类似PHP等软件时可以不用指定mysql的库文件地址。

ln -s /usr/local/mysql/lib/mysql /usr/lib/mysqlln -s /usr/local/mysql/include/mysql /usr/include/mysqlmkdir /var/lib/mysql #创建目录ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock #添加软链接mysql_secure_installation #修改Mysql密码,输入之前生成的密CSJlm3DyTG.d回车,根据提示操作。Press y|Y for Yes, any other key for No: y #是否安装密码安全插件?选择yThere are three levels of password validation policy: #有以下几种密码强度选择LOW Length >= 8MEDIUM Length >= 8, numeric, mixed case, and special charactersSTRONG Length >= 8, numeric, mixed case, special characters and dictionary filePlease enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0 #选择0,只要8位数字即可,选1要有大写,小写,特殊字符等相关操作:进入MySQL控制台UNINSTALL PLUGIN validate_password ; #卸载密码强度插件mysqladmin -uroot -p password 123456 #修改密码SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456'); #登录mysql控制台修改alter user user() identified by '123456'; #修改密码

二、安装Nginx

1、安装pcre

cd /usr/local/srcmkdir /usr/local/pcretar zxvf pcre-8.39.tar.gzcd pcre-8.39./configure --prefix=/usr/local/pcremakemake install

2、安装openssl

cd /usr/local/srcmkdir /usr/local/openssltar zxvf openssl-1.0.2j.tar.gzcd openssl-1.0.2j./config --prefix=/usr/local/opensslmakemake installvi /etc/profileexport PATH=$PATH:/usr/local/openssl/bin:wq!source /etc/profile

3、安装zlib

cd /usr/local/srcmkdir /usr/local/zlibtar zxvf zlib-1.2.8.tar.gzcd zlib-1.2.8./configure --prefix=/usr/local/zlibmakemake install

4、安装Nginxgroupadd wwwuseradd -g www www -s /bin/falsecd /usr/local/srctar zxvf nginx-1.10.1.tar.gzcd nginx-1.10.1./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.2j --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.39注意:--with-openssl=/usr/local/src/openssl-1.0.2j --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.39指向的是源码包解压的路径,而不是安装的路径,否则会报错makemake install/usr/local/nginx/sbin/nginx #启动Nginx

设置nginx开机启动

vi /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 0nginx="/usr/local/nginx/sbin/nginx"prog=$(basename $nginx)NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginxlockfile=/var/lock/subsys/nginxmake_dirs() {# make required directoriesuser=`$nginx -V 2>&1 | grep"configure arguments:"| sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`if [ -z"`grep $user /etc/passwd`"]; thenuseradd -M -s /bin/nologin $userfioptions=`$nginx -V 2>&1 | grep 'configure arguments:'`for opt in $options; doif [ `echo $opt | grep '.*-temp-path'` ]; thenvalue=`echo $opt | cut -d"="-f 2`if [ ! -d"$value"]; then# echo"creating"$valuemkdir -p $value && chown -R $user $valuefifidone}start() {[ -x $nginx ] || exit 5[ -f $NGINX_CONF_FILE ] || exit 6make_dirsecho -n $"Starting $prog:"daemon $nginx -c $NGINX_CONF_FILEretval=$?echo[ $retval -eq 0 ] && touch $lockfilereturn $retval}stop() {echo -n $"Stopping $prog:"killproc $prog -QUITretval=$?echo[ $retval -eq 0 ] && rm -f $lockfilereturn $retval}restart() {#configtest || return $?stopsleep 1start}reload() {#configtest || return $?echo -n $"Reloading $prog:"killproc $nginx -HUPRETVAL=$?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"instart)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 2esac############################################################

:wq! #保存退出

chmod 775 /etc/rc.d/init.d/nginx #赋予文件执行权限chkconfig nginx on #设置开机启动/etc/rc.d/init.d/nginx restart #重启

在浏览器中打开服务器IP地址,会看到下面的界面,说明Nginx安装成功。

三、安装php

1、安装yasmcd /usr/local/srctar zxvf yasm-1.3.0.tar.gzcd yasm-1.3.0./configuremakemake install2、安装libmcryptcd /usr/local/srctar zxvf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8./configuremakemake install3、安装libvpxcd /usr/local/srctar xvf libvpx-1.6.0.tar.bz2cd libvpx-1.6.0./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9makemake install4、安装tiffcd /usr/local/srctar zxvf tiff-4.0.6.tar.gzcd tiff-4.0.6./configure --prefix=/usr/local/tiff --enable-sharedmakemake install5、安装libpngcd /usr/local/srctar zxvf libpng-1.6.25.tar.gzcd libpng-1.6.25./configure --prefix=/usr/local/libpng --enable-sharedmakemake install6、安装freetypecd /usr/local/srctar zxvf freetype-2.7.tar.gzcd freetype-2.7./configure --prefix=/usr/local/freetype --enable-sharedmakemake install7、安装jpegcd /usr/local/srctar zxvf jpegsrc.v9b.tar.gzcd jpeg-9b./configure --prefix=/usr/local/jpeg --enable-sharedmakemake install8、安装libgdcd /usr/local/srctar zxvf libgd-2.1.1.tar.gzcd libgd-2.1.1./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/libvpxmakemake install说明:如果libgd编译失败,可以先跳过,直接使用系统默认的2.1.0版本,在编译php的时候把参数--with-gd=/usr/local/libgd修改为--with-gd即可。9、安装t1libcd /usr/local/srctar zxvf t1lib-5.1.2.tar.gzcd t1lib-5.1.2./configure --prefix=/usr/local/t1lib --enable-sharedmake without_docmake install10、安装php注意:如果系统是64位,请执行以下命令,否则安装php会出错。

\cp -frp /usr/lib64/libltdl.so* /usr/lib/\cp -frp /usr/lib64/libXpm.so* /usr/lib/cd /usr/local/srctar -zvxf php-7.0.11.tar.gzcd php-7.0.11export LD_LIBRARY_PATH=/usr/local/libgd/lib./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd=/usr/local/libgd --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-xpm-dir=/usr/lib64 --with-zlib-dir=/usr/local/zlib --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 --enable-mysqlndmake #编译make install #安装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 #添加软链接到 /etc目录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目录vi /usr/local/php/etc/php-fpm.conf #编辑pid = run/php-fpm.pid #取消前面的分号:wq! #保存退出cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.confvi /usr/local/php/etc/php-fpm.d/www.conf #编辑user = www #设置php-fpm运行账号为wwwgroup = www #设置php-fpm运行组为www设置 php-fpm开机启动cp /usr/local/src/php-7.0.11/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm #拷贝php-fpm到启动目录chmod +x /etc/rc.d/init.d/php-fpm #添加执行权限chkconfig php-fpm on #设置开机启动vi /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 #php支持opcode缓存修改为:opcache.enable_cli=0在最后一行添加:zend_extension=opcache.so #开启opcode缓存功能:wq! #保存退出配置nginx支持phpvi /usr/local/nginx/conf/nginx.conf修改/usr/local/nginx/conf/nginx.conf 配置文件,需做如下修改user www www; #首行user去掉注释,修改Nginx运行组为www www;必须与/usr/local/php/etc/php-fpm.conf中的user,group配置相同,否则php运行出错index index.html index.htm index.php; #添加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;}#取消FastCGI server部分location的注释,注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径/etc/init.d/nginx restart #重启nginxservice php-fpm start #启动php-fpm测试篇cd /usr/local/nginx/html/ #进入nginx默认网站根目录rm -rf /usr/local/nginx/html/* #删除默认测试页vi index.php #新建index.php文件

<?phpphpinfo();?>

:wq! #保存退出chown www.www /usr/local/nginx/html/ -R #设置目录所有者chmod 700 /usr/local/nginx/html/ -R #设置目录权限在浏览器中打开服务器IP地址,会看到下面的界面

至此,CentOS 7.2.1511编译安装Nginx1.10.1+MySQL5.7.14+PHP7.0.11教程完成。

来源:爱蒂网

免责声明:本文由用户上传,如有侵权请联系删除!

猜你喜欢

最新文章