||
dnf -y install parted git vim acpid curl unzip zip net-tools traceroute man ntp python-pip grub2 tar openssh-server openssh-clients gcc gcc-c++ libtool-ltdl-devel libtool* autoconf automake wget make
安装依赖:
dnf install -y pcre-devel libxml2-devel expat-devel bzip2 zlib-devel openssl-devel
注:echo $? 可以检查上一个命令是否执行完成,输出0为正常,其它有故障
APR安装
wget https://www.apache.org/dist/apr/apr-1.7.4.tar.bz2
tar xf /root/apr-1.7.4.tar.bz2
cd /root/apr-1.7.4
./configure --prefix=/usr/local/apr
make
make install
APR-util安装
wget https://www.apache.org/dist/apr/apr-util-1.6.3.tar.bz2
tar xf /root/apr-util-1.6.3.tar.bz2
cd /root/apr-util-1.6.3
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
make
make install
APR-iconv安装
wget https://www.apache.org/dist/apr/apr-iconv-1.2.2.tar.bz2
tar xf /root/apr-iconv-1.2.2.tar.bz2
cd /root/apr-iconv-1.2.2
./configure --prefix=/usr/local/apr-iconv --with-apr=/usr/local/apr/
make
make install
apache安装
wget https://www.apache.org/dist/httpd/httpd-2.4.58.tar.bz2
tar xf /root/httpd-2.4.58.tar.bz2
cd /root/httpd-2.4.58
./configure --prefix=/usr/local/apache --enable-mpms-shared=all --with-mpm=event --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-remoteip --enable-proxy --enable-proxy-fcgi --enable-proxy-uwsgi --enable-daflate=shared --enable-expires=shared --enable-rewrite=shared --enable-cache --enable-file-cache --enable-mem-cache --enable-disk-cache --enable-static-support --enable-static-ab --disable-userdir --enable-nonportable-atomics --disable-ipv6 --with-sendfile --with-ssl
make -j 4
make install
主要参数说明
--prefix=/usr/local/apache 指定安装目录
--enable-mpms-shared=all --with-mpm=event 开启动态MPM切换
--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util 指定依赖包apr apr-util安装路径
--enable-so 打开so模块,so模块是用来提供dso支持的apache核心模块
--enable-remoteip 支持基于客户端IP做访问控制(新特性)
--enable-proxy --enable-proxy-fcgi --enable-proxy-uwsgi 启用代理支持php python网站(以前是模块,现在是服务,速度更快)
--enable-daflate=shared 开启压缩
--enable-expires=shared 开启客户端缓存
--enable-rewrite=shared 开启URL重写
--enable-cache --enable-file-cache --enable-mem-cache --enable-disk-cache 开启服务器缓存
--enable-static-support 支持静态连接
--enable-static-ab 使用静态连接编译ab - apache http服务器性能测试工具
--disable-userdir 禁止用户主目录提供页面访问
--enable-nonportable-atomics 对新式CPU支持,支持原子的比较交换(compare-and-swap,CAS)操作指令
--disable-ipv6 禁用IPV6
--with-sendfile 开启sendfile 0复制机制
make clean 编译错误可以用此命令清空以前的编译文件
bin目录及文件
ab:压力测试文件
apachectl:管理命令,用来启动、关闭apache
apxs:扩展工具,是把第三方工具变成apache的模块
httpd:守护进程
rotetelogs:分割日志
apache配置
ln -s /usr/local/apache/bin/apachectl
/usr/bin/apachectl
useradd -r -s /sbin/nologin www
vim /usr/local/apache/conf/httpd.conf
安装gcc、gcc-c++、 openssl-devel、git
dnf -y install gcc gcc-c++ openssl-devel git
安装 ncurses-devel、bison、cmake等依赖
yum -y install ncurses-devel bison cmake libaio libtirpc*
安装ncurses
wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.3.tar.gz
tar xf /root/ncurses-6.3.tar.gz
cd /root/ncurses-6.3
./configure --with-shared --without-debug --without-ada --enable-overwrite
make
make install
安装mysql
MySQL软件创建运行用户,创建为系统用户,并限制此用户登录操作系统
useradd -r -s /sbin/nologin mysql
官网下载mysql-boost-5.7.38.tar.gz
tar xf /root/mysql-boost-5.7.38.tar.gz
cd /root/mysql-5.7.38
cmake . -DWITH_BOOST=./boost/ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITH_ZLIB=bundled -DWITH_SSL=system -DENABLED_LOCAL_INFILE=1 -DWITH_EMBEDDED_SERVER=1 -DENABLE_DOWNLOADS=1 -DWITH_DEBUG=0
make
make install
主要参数说明
-DCMAKE_INSTALL_PREFIX= 指向mysql安装目录
-DINSTALL_SBINDIR=sbin 指向可执行文件目录(prefix/sbin)
-DMYSQL_DATADIR=/var/lib/mysql 指向mysql数据文件目录(/var/lib/mysql)
-DSYSCONFDIR=/etc/mysql 指向mysql配置文件目录(/etc/mysql)
-DINSTALL_PLUGINDIR=lib/mysql/plugin 指向插件目录(prefix/lib/mysql/plugin)
-DINSTALL_MANDIR=share/man 指向man文档目录(prefix/share/man)
-DINSTALL_SHAREDIR=share 指向aclocal/mysql.m4安装目录(prefix/share)
-DINSTALL_LIBDIR=lib/mysql 指向对象代码库目录(prefix/lib/mysql)
-DINSTALL_INCLUDEDIR=include/mysql 指向头文件目录(prefix/include/mysql)
-DINSTALL_INFODIR=share/info 指向info文档存放目录(prefix/share/info)
-DWITH_READLINE=1 启用readline库支持(提供可编辑的命令行)
-DWITH_SSL=system 启用ssl库支持(安全套接层)
-DWITH_ZLIB=system 启用libz库支持(zib、gzib相关)
-DWTIH_LIBWRAP=0 禁用libwrap库(实现了通用TCP包装的功能,为网络服务守护进程使用)
-DMYSQL_TCP_PORT=3306 指定TCP端口为3306
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock 指定mysql.sock路径
-DENABLED_LOCAL_INFILE=1 启用本地数据导入支持
-DEXTRA_CHARSETS=all 启用额外的字符集类型(默认为all)
-DDEFAULT_CHARSET=utf8 指定默认的字符集为utf8
-DDEFAULT_COLLATION=utf8_general_ci 设定默认排序规则(utf8_general_ci快速/utf8_unicode_ci准确)
-DWITH_EMBEDDED_SERVER=1 编译嵌入式服务器支持
-DMYSQL_USER=mysql 指定mysql用户(默认为mysql)
-DWITH_DEBUG=0 禁用debug(默认为禁用)
-DENABLE_PROFILING=0 禁用Profiling分析(默认为开启)
-DWITH_COMMENT='string' 一个关于编译环境的描述性注释
配置环境变量
echo -e "export PATH=/usr/local/mysql/bin:\$PATH" >>/etc/profilesource /etc/profile
创建目录结构并赋权限
cd /usr/local/mysqlmkdir {data,logs,tmp}
chown -R mysql:mysql {data,logs,tmp}
写配置文件
cd /etc
vim /my.cnf
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
tmpdir = /usr/local/mysql/tmp
socket = /usr/local/mysql/tmp/mysql.sock
log-error = /usr/local/mysql/logs/error.log
初始化实例
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
加入systemctl管理
cp mysql/support-files/mysql.server /etc/init.d/mysqld
vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
After=network.target After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
systemctl daemon-reload
systemctl start mysqld
测试连接 修改默认密码、刷新权限 #密码在errer.log
/usr/local/mysql/bin/mysql -uroot -p'G&wyNX#Zv4>q'
alter user root@localhost identified by '123456';
flush privileges;
安装依赖
dnf -y install libxml2 libxml2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel zlib zlib-devel openldap openldap-devel sqlite-devel oniguruma-devel
安装libzip(必须手动安装并设置,否则有报错)
wget https://libzip.org/download/libzip-1.3.2.tar.gz
tar xf libzip-1.3.2.tar.gz
cd libzip-1.3.2./configure && make && make install
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"
php安装
wget https://mirrors.sohu.com/php/php-7.4.33.tar.bz2 #或者下面的
wget https://www.php.net/distributions/php-7.4.33.tar.bz2
tar xf php-7.4.33.tar.bz2
cd php-7.4.33
./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-openssl --with-mysqli=mysqlnd --with-mysql-sock=/var/lib/mysql/ --enable-pdo --with-pdo-mysql=mysqlnd --with-iconv-dir=/usr/local/ --enable-fpm --with-fpm-group=www --with-fpm-user=www --with-zlib --with-bz2 --with-zlib-dir --enable-calendar --with-curl --enable-dba --with-libxml --enable-xml --enable-ftp --enable-gd --with-jpeg --with-freetype --enable-gd-jis-conv --with-mhash --enable-bcmath --enable-mbstring --enable-opcache=yes --enable-pcntl --disable-rpath --enable-bcmath --disable-ipv6 --with-gettext --disable-debug --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs
make -j 4
make install
--with-mysql-sock=/var/lib/mysql/ --with-fpm-group=www --with-fpm-user=www 需要根据实际更改
7.4已弃用的配置项
configure: WARNING: unrecognized options: --with-libxml-dir, --with-pcre-regex, --with-pcre-dir, --with-gd, 应该使用 --enable-gd --with-jpeg-dir, 应该使用 --with-jpeg --with-png-dir, --with-freetype-dir, 应该使用 --with-freetype --enable-mbregex-backtrack, --with-onig, --enable-wddx, --with-libxml-dir, --enable-zip 应该使用 --with-zip
主要参数说明
--prefix=/usr/local/php7 安装路径
--with-config-file-path=/usr/local/php7/etc 配置文件路径
--with-openssl
--with-mysqli=mysqlnd --with-mysql-sock=/var/lib/mysql/ mysql支持及客户端设置
--enable-pdo --with-pdo-mysql=mysqlnd 开启pdo
--with-iconv-dir=/usr/local/ 指定转码工具,各种字符集间的转换
--enable-fpm --with-fpm-group=www --with-fpm-user=www 支持php-fpm,允许以服务的方式启动php
--with-zlib --with-bz2 --with-zlib-dir 支持压缩
--enable-calendar 支持日历
--with-curl 支持curl
--enable-dba 开启dba函数支持
--with-libxml 支持xml文件库对xml的读取和查询
--enable-xml 允许xml文件
--enable-ftp 支持ftp
--enable-gd --with-jpeg 支持图片
--with-freetype 支持字库
--enable-gd-jis-conv 支持gd库
--with-mhash --enable-bcmath --enable-mbstring 支持加密
--enable-opcache=yes 开启opcache
--enable-pcntl 开启PHP进程控制支持,默认事关闭的
--disable-rpath 关闭额外的运行库文件
--enable-bcmath 增加bcmath扩展的支持,这是一个支持大整数计算的扩展
--disable-ipv6 关闭IPV6支持
--with-gettext 打开gnu的gettext支持,编码库用到
--disable-debug 关闭调试模式
--enable-sockets 打开sockets支持
--with-apxs2=/usr/local/apache/bin/apxs 添加apache对php模块的支持
可能出现的错误
No package 'libxml-2.0' foundconfigure: error: Package requirements (libxml-2.0 >= 2.7.6) were not met:No package 'libxml-2.0' found
解决方法
yum install libxml2-devel
中途可能需要更新其他的依赖, 确定就可以了
No package 'openssl' foundconfigure: error: Package requirements (openssl >= 1.0.1) were not met:No package 'openssl' found
解决方法
yum install openssl-devel
No package 'sqlite3' foundconfigure: error: Package requirements (sqlite3 > 3.7.4) were not met:No package 'sqlite3' found
解决方法
yum install sqlite-devel
No package 'libcurl' foundconfigure: error: Package requirements (libcurl >= 7.15.5) were not met:No package 'libcurl' found
解决方法
yum install libcurl-devel
Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not metconfigure: error: Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met:No package 'icu-uc' foundNo package 'icu-io' foundNo package 'icu-i18n' found
解决方法
yum install libicu-devel
configure: error: C++ preprocessor "/lib/cpp" fails sanity checkchecking whether g++ accepts -g... nochecking how to run the C++ preprocessor... /lib/cppconfigure: error: in `/data/programs/php-7.4.7':configure: error: C++ preprocessor "/lib/cpp" fails sanity checkSee `config.log' for more details
解决方法, 缺少g++库, 安装
yum install gcc-c++
No package 'oniguruma' foundconfigure: error: Package requirements (oniguruma) were not met:No package 'oniguruma' found
如果启用了--with-mbstring,则需要安装 oniguruma, 因为7.4的正则表达式使用了oniguruma
解决方法
yum install oniguruma oniguruma-devel
No package 'libxslt' foundconfigure: error: Package requirements (libxslt >= 1.1.0) were not met:No package 'libxslt' found
--with-xsl 打开XSLT 文件支持,扩展了libXML2库 ,需要libxslt软件
解决方法
yum install libxslt-devel
No package 'libpng' foundconfigure: error: Package requirements (libpng) were not met:No package 'libpng' found
解决方法
yum install libpng-devel
No package 'libjpeg' foundconfigure: error: Package requirements (libjpeg) were not met:No package 'libjpeg' found
解决方法
yum install libjpeg-devel
No package 'freetype2' foundconfigure: error: Package requirements (freetype2) were not met:No package 'freetype2' found
解决方法
yum install freetype-devel
No package 'libzip' foundconfigure: error: Package requirements (libzip >= 0.11) were not met:No package 'libzip' found
解决方法
这里不使用软件仓库中的libzip, 也就是不使用yum install libzip-devel, 因为版本不够, 安装方法看下面一条 Requested 'libzip >= 0.11' but version of libzip is 0.10.1
这是因为软件仓库的libzip版本过低, 需要手动编译安装
php的配置
cp /root/php-7.4.33/php.ini-production /usr/local/php7/etc/php.ini #复制安装包文件夹的配置文件到安装目录
cp /root/php-7.4.33/sapi/fpm/php-fpm.service /etc/systemd/system/php-fpm.service
vim /etc/systemd/system/php-fpm.service 把“ProtectSystem=full”改成 “ProtectSystem=false” #这个必须改,不然会把/usr等目录作为只读目录打开,服务会启动不了
systemctl daemon-reload
systemctl start php-fpm
ln -s /usr/local/php7/bin/php /usr/bin/
ln -s /usr/local/php7/sbin/php-fpm /usr/bin/
cd /usr/local/php7/etc/
cp php-fpm.conf.default php-fpm.conf
cp php-fpm.d/www.conf.default php-fpm.d/www.conf
egrep -v "^;|^$" php-fpm.conf
[global] pid = run/php-fpm.pid
error_log = log/php-fpm.log
daemonize = yes
include=/usr/local/php7/etc/php-fpm.d/*.conf
egrep -v "^;|^$" php-fpm.d/www.conf
[www]
user = www
group = www
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
与apache关联的配置
第一种模式,当成apache的模块执行
在apache的配置文件中,增加LoadModule php7_module modules/libphp7.so行的注释;
在DirectoryIndex index.html行增加index.php
增加如下配置
#php settings
Include conf/extra/php.conf
vim conf/extra/php.conf
LoadModule php7_module modules/libphp7.soAddType application/x-httpd-php .php
第二种模式,当成单独的服务执行
在apache的配置文件中,增加LoadModule php7_module modules/libphp7.so行的注释;
在DirectoryIndex index.html行增加index.php
增加如下配置
#php-fpm settings
Include conf/extra/php-fpm.conf
vim conf/extra/php-fpm.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
SetHandler "proxy:fcgi://127.0.0.1:9000"
安装nginx
wget https://nginx.org/download/nginx-1.24.0.tar.gz
tar xf nginx-1.24.0.tar.gzcd nginx-1.24.0
./configure --prefix=/usr/local/nginx
make
make install
配置
打开配置文件pid和log,其它根据情况自己设置
添加服务
vim /etc/systemd/system/nginx.service
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start nginx
合作电话:010-64087828
社区邮箱:greatsql@greatdb.com