Linux搭建lnmp
LNMP安装
#购买一台新的服务器之后,当然是要安装环境啦!
#下面是安装LNMP的步骤
yum -y update
yum install gcc gcc-c++ make automake pcre pcre-devel zlip zlib-devel openssl openssl-devel expat-devel libtool autoconf -y
wget https://nginx.org/download/nginx-1.22.1.tar.gz
tar zvxf nginx-1.22.1.tar.gz && cd nginx-1.22.1
groupadd nginx
useradd nginx -g nginx -s /sbin/nologin -M
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_mp4_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre
make && make install
mkdir /var/tmp/nginx/client -p
#新建文件
vim /usr/lib/systemd/system/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 stop
[Install]
WantedBy=multi-user.target
#重载systemd
systemctl daemon-reload
#设置开机启动
systemctl enable nginx.service
yum -y install libxml2 libxml2-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 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 httpd-devel sqlite-devel -y
#进行这一步的时候,目录还在/root/nginx-1.22.1
#回到上一级目录操作下面的步骤
cd .. && wget https://www.php.net/distributions/php-7.4.33.tar.gz
wget https://github.com/Kitware/CMake/archive/refs/tags/v3.26.1.tar.gz
tar zxvf v3.26.1.tar.gz && cd CMake-3.26.1
./configure
gmake && gmake install
wget https://libzip.org/download/libzip-1.9.2.tar.gz
tar zxvf libzip-1.9.2.tar.gz && cd libzip-1.9.2
mkdir build && cd build && cmake .. && make && make install
wget -c https://github.com/kkos/oniguruma/archive/refs/tags/v6.9.7.1.tar.gz
tar -zvxf v6.9.7.1.tar.gz && cd oniguruma-6.9.7.1
./autogen.sh
./configure --bindir=/usr/sbin/
--sbindir=/usr/sbin/
--libexecdir=/usr/libexec
--sysconfdir=/etc/
--localstatedir=/var
--libdir=/usr/lib64/
--includedir=/usr/include/
--datarootdir=/usr/share
--infodir=/usr/share/info
--localedir=/usr/share/locale
--mandir=/usr/share/man/
--docdir=/usr/share/doc/oniguruma
make && make install
groupadd www
useradd -g www www
tar zxvf php-7.4.33.tar.gz && cd php-7.4.33
./configure
--prefix=/usr/local/php
--with-config-file-path=/etc
--with-fpm-user=www
--with-fpm-group=www
--with-zlib-dir
--with-freetype-dir
--with-zlib-dir=DIR
--with-pcre-dir
--with-libzip=DIR
--enable-mbstring
--with-libxml-dir=/usr
--enable-xmlreader
--enable-xmlwriter
--enable-soap
--enable-calendar
--with-curl
--with-zlib
--with-gd
--with-pdo-sqlite
--with-pdo-mysql
--with-mysqli
--with-mysql-sock
--enable-mysqlnd
--disable-rpath
--enable-inline-optimization
--with-bz2
--with-zlib
--enable-sockets
--enable-sysvsem
--enable-sysvshm
--enable-pcntl
--enable-mbregex
--enable-exif
--enable-bcmath
--with-mhash
--enable-zip
--with-pcre-regex
--with-jpeg-dir=/usr
--with-png-dir=/usr
--with-openssl
--enable-ftp
--with-kerberos
--with-gettext
--with-xmlrpc
--with-xsl
--enable-fpm
--enable-opcache
--enable-fileinfo
make && make install
cp php.ini-production /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/php-fpm.service
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod a+x /etc/init.d/php-fpm
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
ln -s /usr/local/php/etc/php-fpm.d/www.conf /etc/www.conf
REDES 扩展
wget http://pecl.php.net/get/redis-4.3.0.tgz
tar zxvf redis-4.3.0.tgz && cd redis-4.3.0
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
GD扩展
cd ~/php-7.4.33/ext/gd
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-jpeg --with-freetype
make && make install
#php配置和启动
/etc/php.ini
/usr/local/php/etc/php-fpm.conf
/etc/www.conf
/etc/init.d/php-fpm restart
#NG配置&启动
/usr/local/nginx/conf/nginx.conf
/usr/local/nginx/sbin/nginx
#第二篇文章中讲到如何创建软链接 该步骤即可简化为 nginx -s reload
/usr/local/nginx/sbin/nginx -s reload
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: