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

当前系统为centos7

一、 编译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那样)

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

2.2 如果提示错误:找不到zipconf.h,则find / -name zipconf.h 搜索一下,手动把zipconf.h复制到/usr/local/include/zipconf.h

3. 设置编译参数,把常用的模块加上

./configure --prefix=/usr/local/php7 --with-fpm-user=php-fpm --with-fpm-group=php-fpm --enable-bcmath --with-bz2 --enable-calendar --with-curl --enable-exif --enable-ftp --with-gd --enable-mbstring --with-mysqli --with-pdo-mysql --with-openssl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvmsg --enable-sysvshm --with-tidy --enable-wddx --enable-xml --with-xmlrpc --with-xsl --enable-zip --with-zlib --enable-inline-optimization --enable-dba --with-pear --enable-fpm --enable-opcache --enable-gd-native-ttf --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-jis-conv --with-gettext --with-mcrypt --enable-pcntl --enable-mbregex --enable-exif --with-mhash --with-pcre-regex --with-libdir --with-kerberos --with-xpm-dir --enable-session --enable-shared --with-iconv --with-snmp --with-gmp

4. 编译安装

make && make install

5. 如果以后需要什么模块,可以使用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 -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

猜你喜欢

转载自www.cnblogs.com/kkxiaoyuan/p/11482210.html