在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/src
wget 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

3. 设置编译参数,这里我只设置安装位置,其他参数可查看官方文档(http://nginx.org/en/docs/configure.html)

./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.0
built by gcc 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/src
wget 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目录的etc目录下,命名为php.ini;

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

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

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

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

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

6.1 查看php-fpm进程

[root@localhost php7]# ps -aux | grep php
root     30699  0.0  0.7 250584  7912 ?        Ss   13:41   0:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nobody   30700  0.0  0.7 250584  7660 ?        S    13:41   0:00 php-fpm: pool www
nobody   30701  0.0  0.7 250584  7660 ?        S    13:41   0:00 php-fpm: pool www
root     30738  0.0  0.0 112728   996 pts/0    S+   13:42   0:00 grep --color=auto php

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

# 进入模块源码目录执行phpize
cd /usr/local/src/php-7.3.7/ext/curl
phpize

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

# 修改php.ini,加入extension=curl.so # 查看已有的模块 php
-m

 三、安装MySQL8

下载repository,yum安装(参考官方文档https://dev.mysql.com/doc/refman/8.0/en/linux-installation-yum-repo.html)

cd /usr/local/repo
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
yum localinstall mysql80-community-release-el7-3.noarch.rpm
yum install mysql-community-server

 

转载于:https://www.cnblogs.com/kkxiaoyuan/p/11482210.html

你可能感兴趣的:(在centos7安装nginx+mysql8+php7(LNMP))