欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 运维知识 > 数据库 >内容正文

数据库

mysql8 php7_在centos7安装nginx+mysql8+php7(LNMP)

发布时间:2023/12/20 数据库 60 豆豆
生活随笔 收集整理的这篇文章主要介绍了 mysql8 php7_在centos7安装nginx+mysql8+php7(LNMP) 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

当前系统为centos7

参考这里

开始之前,先安装一些库和软件,会用的着的,如果已经安装过了,那么可以去掉

yum install -y \

libtool make automake mlocate \

pam-devel unzip gcc openssl openssl-devel \

iptables-services bash-completion* pcre-devel \

libxslt* perl-ExtUtils-Embed \

at gcc-c++ gperf rpm-build \

curl bzip2-devel libcurl-devel gd gd-devel \

t1lib t1lib-devel libmcrypt libmcrypt-devel libtidy \

libtidy-devel GeoIP-devel libatomic_ops-devel \

zlib-devel libstdc++* net-snmp net-snmp* \

gmp gmp-devel openldap openldap-devel

一、 编译nginx

1. 获取源码并解压

cd /usr/local/srcwget http://nginx.org/download/nginx-1.16.0.tar.gz

tar zxf nginx-1.16.0

2. 如果在下面编译过程中提示缺少库,则用yum安装,如:HTTP rewrite模块需要pcre、pcre-devel;HTTP gzip模块需要zlib、zlib-devel

./configure --prefix=/usr/local/nginx

4. 编译安装

make && make install

5. 以后要是需要安装其他模块,先用原来的nginx查看编译参数,在用原来的源码重新编译(make之后不执行make install安装,否则原来的配置文件会被替换),编译参数就填原来的参数,再加上想要的新模块,编译完之后在源码目录的objs目录下有新的nginx,用它替换原来的nginx即可

# 查看编译参数

[root@kyuan~]# /usr/local/nginx/sbin/nginx -V

nginx version: nginx/1.16.0built bygcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)

configure arguments:--prefix=/usr/local/nginx

# 设置编译参数后编译不安装

[root@kyuan~]# cd /usr/local/src/nginx-1.16.0/[root@kyuan nginx-1.16.0]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module

...

...

...

[root@kyuan nginx-1.16.0]# make# 在源码目录下的objs目录有新编译出来的nginx

[root@kyuan~]# ll /usr/local/src/nginx-1.16.0/objs/nginx-rwxr-xr-x 1 root root 3825184 Jul 12 11:05 /usr/local/src/nginx-1.16.0/objs/nginx

二、编译安装php7

1. 获取源码并解压

cd /usr/local/srcwget https://www.php.net/distributions/php-7.3.9.tar.gz

tar zxf ./php-7.3.9.tar.gz

2. 如果下面编译过程中提示缺少什么库,就用yum安装什么库(像编译nginx那样)

3. 设置编译参数,把常用的模块加上,可以直接复制下面的配置参数,也可以选择一些最最常用的模块

最最常用的,比如:mysql、gd、ttf、fpm模块是最常用的(连接mysql数据库、gd画图、ttf字体、fpm方式运行):

./configure --prefix=/usr/local/php7 \

--with-mysqli \

--with-gd \

--enable-gd-native-ttf \

--enable-gd-jis-conv \

--enable-fpm

较为常用的(建议):

./configure --prefix=/usr/local/php7 \

--enable-bcmath --with-bz2 \

--enable-calendar \

--enable-exif \

--enable-ftp \

--enable-mbstring \

--enable-shmop \

--enable-soap \

--enable-sockets \

--enable-sysvsem \

--enable-sysvmsg \

--enable-sysvshm \

--enable-wddx \

--enable-xml \

--enable-zip \

--enable-inline-optimization \

--enable-session \

--enable-shared \

--enable-pcntl \

--enable-mbregex \

--enable-exif \

--enable-gd-jis-conv \

--enable-fpm \

--enable-opcache \

--enable-gd-native-ttf \

--enable-dba \

--with-gd \

--with-fpm-user=nobody \

--with-fpm-group=nobody \

--with-mysqli \

--with-pdo-mysql \

--with-openssl \

--with-curl \

--with-tidy \

--with-xmlrpc \

--with-xsl \

--with-zlib \

--with-pear \

--with-jpeg-dir \

--with-png-dir \

--with-freetype-dir \

--with-gettext \

--with-mcrypt \

--with-mhash \

--with-pcre-regex \

--with-libdir \

--with-kerberos \

--with-xpm-dir \

--with-iconv \

--with-snmp \

--with-gmp

**出现错误的解决方案:

1. 提示libzip版本太低,则到https://nih.at/libzip/libzip-1.2.0.tar.gz下载1.2.0的源码编译安装(要先卸载原来的libzip)。

2. 提示错误:找不到zipconf.h,则find / -name zipconf.h 搜索一下,是在 /usr/local/lib/libzip/include/zipconf.h,手动把zipconf.h复制到/usr/local/include/zipconf.h,或者用 ln 命令创建一个软连接,连接到/usr/local/include/zipconf.h也行。

3. 提示错误:off_t undefined; check your library configuration,则

# 添加搜索路径到配置文件

echo '/usr/local/lib64

/usr/local/lib

/usr/lib

/usr/lib64'>>/etc/ld.so.conf

# 更新配置

ldconfig -v

4. 缺少libtidy,用yum安装,如果yum没有资源,则在http://binaries.html-tidy.org/下载一个rpm,用rpm安装

4. 编译安装

make && make install

5. 安装完后,把源码目录下的php.ini-development复制到php目录的lib目录下(这个目录是默认的配置文件目录),命名为php.ini;

你也可以在编译之前配置--with-config-file-path参数,指定配置文件的目录

cp /usr/local/src/php-7.3.7/php.ini-development /usr/local/php7/lib/php.ini

5.1 复制一份php-fpm的配置文件

cd /usr/local/php7/etccp php-fpm.conf.default php-fpm.conf

cd/usr/local/php7/etc/php-fpm.dcp www.conf.default www.test.conf

5.2 如果想在终端直接执行php,可以将 /usr/local/php7/bin 这个路径加入到环境变量中。

6. 启动php-fpm,默认监听9000端口

/usr/local/php7/sbin/php-fpm

6.1 查看php-fpm进程

[root@localhost php7]# ps -aux | grepphp

root30699 0.0 0.7 250584 7912 ? Ss 13:41 0:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)

nobody30700 0.0 0.7 250584 7660 ? S 13:41 0:00 php-fpm: pool www

nobody30701 0.0 0.7 250584 7660 ? S 13:41 0:00 php-fpm: pool www

root30738 0.0 0.0 112728 996 pts/0 S+ 13:42 0:00 grep --color=auto php

7. 如果以后需要什么模块,可以使用phpize编译模块,比如需要curl模块

# 1、进入模块源码目录执行phpize

cd/usr/local/src/php-7.3.7/ext/curl

/usr/local/php7/bin/phpize

# 2、设置php配置文件路径

./configure --with-php-config=/usr/local/php7/bin/php-configmake # 成功后会在 ./module 里面生成一个 curl.somake install# 安装这个模块(就是把curl.so复制到php的扩展目录下)

# 3、修改php.ini,加入extension=curl.so

# 4、查看已有的模块

/usr/local/php7/bin/php-m

如果在执行phpize的时候,出现说cannot find autoconf,比如:

Configuring for:

PHP Api Version:20180731Zend Module Api No:20180731Zend Extension Api No:320180731Cannotfindautoconf. Please check your autoconf installation and the

$PHP_AUTOCONF environment variable. Then, rerun this script.

则先安装autoconf(可以用yum安装)

查看模块目录

/usr/local/php7/bin/php -i | grep extension_dir

三、安装MySQL8

cd /usr/local/repowget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

yum localinstall mysql80-community-release-el7-3.noarch.rpmyum install mysql-community-server

总结

以上是生活随笔为你收集整理的mysql8 php7_在centos7安装nginx+mysql8+php7(LNMP)的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。