centos7.4安装nginx1.8.1 php7.7.11 安装 MySQL5.7.20

解决依赖关系

yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel

nginx源码下载地址

http://nginx.org/download/

解压

tar -zxvf nginx-1.8.1.tar.gz

进入目录

cd nginx-1.8.1

检测配置

./configure --prefix=/usr/local/nginx --sbin-path=/usr/bin/nginx

--prefix 安装位置
--sbin-path 执行命令
参考手册

编译并安装

make && make install

启动nginx

/usr/bin/nginx

查看进程

pstree -p | grep nginx

显示2个进程 ( 一个主进程 一个工作进程 )

# 所有system的启动脚本都在此目录下(每当安装一个软件后都在这个目录下创建一个httpd.service文件)
/usr/lib/systemd/system

加入systemctl中管理

[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/bin/nginx 
ExecStop=/usr/bin/nginx -s stop
ExecReload=/usr/bin/nginx -s reload
PrivateTmp=true

[Install]
WantedBy=multi-user.target

重载systemctl配置

systemctl daemon-reload
注释  
想要执行systemctl stop nginx.service 那么nginx的启动必须用
systemctl start nginx.service
启动                    停止
/usr/bin/nginx           /usr/bin/nginx -s stop
systemctl stop nginx.service      systemctl start nginx.service
 
安装php

下载并解压源码包

tar zxf php-7.1.11.tar.gz
cd php-7.1.11
  1. 安装编译php所需的依赖包
yum install -y gcc gcc-c++ make 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 gmp-devel icu  libxslt libxslt-devel
  1. 进去源码目录配置 ./configure 信息
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql-sock --with-mysqli --with-libxml-dir --with-openssl --with-mcrypt --with-mhash --with-pcre-regex --with-zlib --with-iconv --with-bz2 --with-curl --with-cdb --with-pcre-dir --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --with-gettext --with-gmp --with-mhash --with-libmbfl --with-onig --with-pdo-mysql --with-zlib-dir --with-readline --with-libxml-dir --with-xsl --with-pear --enable-fpm --enable-soap --enable-bcmath --enable-calendar --enable-dom --enable-exif --enable-fileinfo --enable-filter --enable-ftp --enable-gd-native-ttf --enable-gd-jis-conv --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --enable-pdo --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --enable-zip --enable-mysqlnd-compression-support
  1. 编译 安装
make && make install
  1. 启动php-fpm
/usr/local/php/sbin/php-fpm

如果不知道启动命令在哪可以

find / -name php-fpm 
启动提示错误:
[09-Nov-2017 08:49:40] ERROR: failed to open configuration file '/usr/local/php/etc/php-fpm.conf': No such file or directory (2)
[09-Nov-2017 08:49:40] ERROR: failed to load configuration file '/usr/local/php/etc/php-fpm.conf'
[09-Nov-2017 08:49:40] ERROR: FPM initialization failed

意思是 提示找不到 php-fpm.conf
到/usr/local/php/etc目录下 将php-fpm.conf.default 复制一份出来

cp php-fpm.conf.default php-fpm.conf

php-fpm.conf只是php的主配置文件 还要到php-fpm.d目录下将默认的www.conf.default也复制一份为www.conf

  1. 再次启动
/usr/local/php/sbin/php-fpm

无任何提示输出
查看是否运行成功

pstree -p | grep php
  1. 将php-fpm加入到system中管理
# 所有system的启动脚本都在此目录下
/usr/lib/systemd/system

创建php-fpm.service文件
文件内容如下

[Unit]
Description=php-fpm
After=network.target

[Service]
Type=forking
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm
ExecStop=/usr/bin/pkill -9 php-fpm
PrivateTmp=true

[Install]
WantedBy=multi-user.target

重载systemctl配置

systemctl daemon-reload

这样就可以使用systemctl命令管理php-fpm了
systemctl start php-fpm.service
systemctl stop php-fpm.service

 

Mysql 安装

  1. 下载软件包
# 下载 mysql-5.7.20
wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20.tar.gz
# 解压 tar xzf mysql-5.7.20.tar.gz # 移动 ( 移动到你要安装的位置 ) mv /root/mysql-5.7.20 /usr/local/mysql # MySQL从5.7开始必须安装boost库才行 # 如果未安装cmake时可能会报错误 # CMake Error at cmake/boost.cmake:81 (MESSAGE) # 下载 boost_1_59_0 wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz # 解压 tar xzf boost_1_59_0.tar.gz # 将解压后的包拷贝到mysql安装目录下的boost目录下 ( 自行创建boost ) cp -R boost_1_59_0 /usr/local/mysql/boost/ 
  1. 处理依赖关系
yum install cmake cmake-gui gcc-c++ ncurses-devel
  1. cmake构建mysql  下面的操作必须在mysql目录下
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DMYSQL_DATADIR=/data/mysql/ -DSYSCONFDIR=/etc/ -DWITH_BOOST=/usr/local/mysql/boost/
# 安装目录 CMAKE_INSTALL_PREFIX # 数据目录 MYSQL_DATADIR # 配置文件目录 SYSCONFDIR # 指定boost库的位置 WITH_BOOST # cmake时遇到的错误 错误1: CMake Error: your C compiler: "CMAKE_C_COMPILER-NOTFOUND" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name. 解决: // 安装gcc yum install gcc-c++ 错误2: CMake Error at cmake/readline.cmake:64 (MESSAGE): Curses library not found. Please install appropriate package, remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel 解决: yum install ncurses-devel 解除错误后删除 CMakeCache.txt 在重新cmake
// 添加mysql用户
useradd -s /sbin/nologin mysql
// 创建mysql数据存放目录 mkdir -p /data/mysql // 给予目录权限 chown -R mysql:mysql /data/mysql
  1. 编译并安装
make 
make install
# mysql 编译时间较长建议make和make install分开执行 # mysql 编译非常消耗内存 如果内存较小可能无法编译通过 # 之前1G内存的阿里云编译到30%左右就挂了 换4G内存机器才编译通过 # 目测编译MySQL5.7.20至少要2G的内存 ( 未测试 ) 
  1. 安装完成后 初始化MySQL
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
# 生成MySQL临时密码 --initialize # 指定运行MySQL的用户 --user=mysql # 指定MySQL的安装目录 --basedir=/usr/local/mysql # 指定MySQL的数据目录 --datadir=/data/mysql # 初始化成功 A temporary password is generated for root@localhost: 5-h1Bbf*EQwk 临时密码: 5-h1Bbf*EQwk 
  1. 启动MySQL
# MySQL默认启动命令在
/usr/local/mysql/support-files/mysql.server
# 拷贝一个出来 cp /usr/local/mysql/support-files/mysql.server /usr/local/mysql/mysqld # 启动MySQL /usr/local/mysql/mysqld start # 启动报错 错误1: MySQL.2017-11-09T09:27:48.949025Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'. 解决: 猜测可能是日志文件没有权限 直接去修改MySQL配置文件 /etc/my.cnf 修改 log-error 位置 并给予日志文件权限 在 mysql 目录下创建了 log 存在错误日志 mkdir log chown mysql:mysql log 错误2: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 解决: 首先查看 /var/lib/mysql/ 下是否有 mysql.sock 然后建立软连接到 /tmp/ 下 ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock mysql.sock 的位置在my.cnf中也有配置 再次启动 /usr/local/mysql/mysqld start 启动成功 
  1. 连接MySQL
/usr/local/mysql/bin/mysql -h localhost -uroot -p 
# 密码是初始化的 : 5-h1Bbf*EQwk # 登陆成功 执行 show databases; 直接报错了 提示必须修改初始密码 # 修改密码 set password for root@localhost = password('MaShen666'); # 刷新权限 flush privileges; # 再次执行 show databases; 成功 
  1. MySQL加入到systemctl中管理
# mysql.service
systemctl daemon-reload
[Unit] Description=mysql After=network.target [Service] Type=forking PIDFile=/usr/local/mysql/pid/mysql.pid ExecStart=/usr/local/mysql/mysqld start ExecStop=/usr/local/mysql/mysqld stop ExecRestart=/usr/local/mysql/mysqld restart ExecStatus=/usr/local/mysql/mysqld status PrivateTmp=true [Install] WantedBy=multi-user.target 

重载systemctl配置

systemctl daemon-reload
总结
  1. MySQL5.7 必须安装boost库 这里折腾好久
  2. 初始化和5.7版本之前不同了
  3. 编译时如果内存较小可能无法编译完成
  4. 安装后启动MySQL时报的错误多数为权限问题
  5. 如果不修改初始密码无法操作MySQL

转载于:https://www.cnblogs.com/xin-jun/p/7833556.html

你可能感兴趣的:(centos7.4安装nginx1.8.1 php7.7.11 安装 MySQL5.7.20)