LNMP环境编译安装

LNMP环境编译安装

Scroll Down

安装nginx

下载链接 http://nginx.org/en/download.html

下载解压

#安装依赖包
[root@lnmp ~]# yum -y install apr* autoconf automake bison bzip2 bzip2* cpp curl curl-devel fontconfig fontconfig-devel freetype-devel gcc gcc-c++ gd gd-devel gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libxml* libXaw-devel libXmu-devel libtiff libtiff* make openssl openssl-devel patch pcre-devel perl php-common php-gd policycoreutils telnet wget zlib-devel ncurses-devel libtirpc-devel gtk* ntpstat na* bison*
[root@lnmp opt]# cd /opt
[root@lnmp opt]# wget http://nginx.org/download/nginx-1.17.4.tar.gz
[root@lnmp opt]# tar xf nginx-1.17.4.tar.gz
[root@lnmp opt]# cd nginx-1.17.4

编译安装

#创建用户
[root@lnmp opt]# groupadd www
[root@lnmp opt]# useradd -g www www -M -s /sbin/nologin

#编译安装
[root@lnmp nginx-1.17.4]# cd nginx-1.17.4
[root@lnmp nginx-1.17.4]# ./configure \
> --prefix=/usr/local/nginx/ \
> --user=nginx \
> --group=nginx \
> --with-pcre \
> --with-http_ssl_module \
> --with-http_v2_module \
> --with-http_realip_module \
> --with-http_addition_module \
> --with-http_sub_module \
> --with-http_dav_module \
> --with-http_flv_module \
> --with-http_mp4_module \
> --with-http_gunzip_module \
> --with-http_gzip_static_module \
> --with-http_random_index_module \
> --with-http_secure_link_module \
> --with-http_stub_status_module \
> --with-http_auth_request_module \
> --with-mail \
> --with-mail_ssl_module \
> --with-stream_ssl_module

[root@lnmp nginx-1.17.4]# make & make install

/usr/local/nginx/sbin/nginx             启动
/usr/local/nginx/sbin/nginx -s stop     停止
/usr/local/nginx/sbin/nginx -s reload   重启

设置开机自启

[root@lnmp ~]# cd /usr/lib/systemd/system

路径启动(不用管这个,当忘记快捷启动了再来看这个)
/usr/local/nginx/sbin/nginx             启动
/usr/local/nginx/sbin/nginx -s stop     停止
/usr/local/nginx/sbin/nginx -s reload   重启

[root@centos8 system]# vim nginx.service
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit

[Install]
WantedBy=multi-user.target
[root@lnmp system]# systemctl enable nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.

添加软连接

[root@lnmp opt]# ln -s /usr/local/nginx/sbin/nginx /usr/bin/

安装php

#更新依赖包
[root@lnmp ~]# yum -y update

#安装依赖包
[root@lnmp ~]#yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel libzip gcc-c++

#添加用户
[root@lnmp ~]#groupadd webid
[root@lnmp ~]#useradd -g webid webid

#开始编译
[root@lnmp ~]#./configure \
 --prefix=/usr/local/php\
 --enable-fpm\
 --with-fpm-user=webid\
 --with-fpm-group=webid\
 --with-config-file-path=/usr/local/php/conf\
 --disable-rpath\
 --enable-soap\
 --with-libxml-dir\
 --with-xmlrpc\
 --with-openssl\
 --with-mhash\
 --with-pcre-regex\
 --with-zlib\
 --enable-bcmath\
 --with-bz2\
 --enable-calendar\
 --with-curl\
 --enable-exif\
 --with-pcre-dir\
 --enable-ftp\
 --with-gd\
 --with-openssl-dir\
 --with-jpeg-dir\
 --with-png-dir\
 --with-zlib-dir\
 --with-freetype-dir\
 --enable-gd-jis-conv\
 --with-gettext\
 --with-gmp\
 --with-mhash\
 --enable-mbstring\
 --with-onig\
 --with-mysqli=mysqlnd\
 --with-pdo-mysql=mysqlnd\
 --with-zlib-dir\
 --with-readline\
 --enable-shmop\
 --enable-sockets\
 --enable-sysvmsg\
 --enable-sysvsem \
 --enable-sysvshm \
 --enable-wddx\
 --with-libxml-dir\
 --with-xsl\
 --enable-zip\
 --with-pear

这里会提示 configure: error: Please reinstall the libzip distribution,我们需要溢出libzip,手动安装最新版本
先编译安装最新版cmake

cd /usr/local/src
wget https://github.com/Kitware/CMake/releases/download/v3.14.3/cmake-3.14.3.tar.gz
tar -zxvf cmake-3.14.3.tar.gz
cd cmake-3.14.3
./bootstrap
make && make install

再编译安装libzip

yum remove libzip -y
cd /usr/local/src
wget  https://libzip.org/download/libzip-1.5.2.tar.gz
tar -zxvf libzip-1.5.2.tar.gz
cd libzip-1.5.2
mkdir build
cd build
cmake ..
make && make install

./configure                        \
--prefix=/usr/local/php            \
--enable-fpm                       \
--with-mysql-sock=/tmp/mysql.sock  \
--enable-embedded-mysqli           \
--with-mysqli                      \
--with-zlib                        \
--with-openssl                     \
--with-iconv                       \
--with-gd

再次编译php7.3,继续报错 error: off_t undefined; check your library configuration
执行以下命令

vi /etc/ld.so.conf 
#添加如下几行
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64 
#保存退出
:wq
ldconfig -v # 使之生效

继续编译安装

[root@lnmp php-7.2.5]# make  && make install #编译安装

#php-fpm开机自启
[root@lnmp php-7.3.5]# cp ./sapi/fpm/php-fpm.conf /usr/local/php/etc/
[root@lnmp php-7.3.5]# cp ./sapi/fpm/www.conf       /usr/local/php/etc/php-fpm.d/
[root@lnmp php-7.3.5]# cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@lnmp php-7.3.5]# chmod +x /etc/init.d/php-fpm
[root@lnmp php-7.3.5]# chkconfig php-fpm on
[root@lnmp php-7.3.5]# service php-fpm restart
Gracefully shutting down php-fpm warning, no pid file found - php-fpm is not running ?
Starting php-fpm  done
[root@lnmp php-7.3.5]# netstat -tnlp  | grep php-fpm
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      75979/php-fpm: mast