Linux, WEB, 应用部署

搭建LNMP平台并部署wordpress

一、编译安装Nginx

先安装依赖

 yum -y install gcc gcc-c++* openssl openssl-devel zlib zlib-devel pcre pcre-devel libxml2 libxml2-devel libxslt-devel  perl-devel perl-ExtUtils-Embed  gd-devel GeoIP GeoIP-devel GeoIP-data ncurses ncurses-devel libtool-ltdl-devel libjpeg-devel libpng-devel libtiff-devel fontconfig-devel freetype-devel libXpm-devel gettext-devel

解压编译安装

tar -zxvf nginx-1.16.1.tar.gz 
cd nginx-1.16.1
useradd -M -s /sbin/nologin nginx
\\配置时指定worker进程运行用户及组为nginx
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module
make && make install

配置

主配置文件:/usr/local/nginx/conf/nginx.conf
[root@T2 qingmei]# grep -Ev "^[[:space:]]*(#|$)" /usr/local/nginx/conf/nginx.conf
//初始workder数量
worker_processes  1;
//指定pid文件
pid        logs/nginx.pid;
events {
//每个worker最多接受的连接数
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
//域名
        server_name  www.qingmei.com;
//网站文档根
        root   html/qingmei;
        access_log  logs/qingmei.access.log;
        location / {
//设置默认文档页
            index  index.html index.htm index.php;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
//设置php文件的处理方式
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /$document_root$fastcgi_script_name;
//$document_root    这是nginx系统的一个系统变量,表示文档根目录,也就是默认的/usr/local/nginx/html
//$fastcgi_script_name    nginx系统的一个系统变量,表示文件名
            include        fastcgi_params;
        }
    }
    server {
        listen       80;
//第二个虚拟主机的域名
        server_name  www.guimei.com;
        access_log  logs/guimei.access.log;
        location / {
            root   html/guimei;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location = /status{
            stub_status on;
            access_log off;
        }
    }
}

常用命令

	nginx -h #查看nginx命令参数
	nginx -v #查看nginx版本
	nginx -V #查看版本详细信息,并加上安装配置时参数
	nginx -t #检测配置文件
	nginx -T #检测并打印出配置文件
	nginx -q #在测试期间不输出非错误提示。
	nginx -s(常用) #发送信号给主进程:stop强制退出,quit优雅的退出 reopen重开日志,reload 重新装载配置。		-s stop ,-s quit -s reopen -s reload
	nginx -p  prefix #设置nginx安装目录
	nginx -c filename #指定启动时使用的配置文件。
	nginx -g directives # 在配置文件之外设置全局命令。

二、安装PHP

安装PHP之前先安装mysql,可以参照之前的文章,此处略过。

先安装依赖:
yum -y install libxml2-devel libjpeg-devel libpng-devel freetype-devel curl-devel openssl-devel sqlite-devel  oniguruma oniguruma-devel
创建用户:
useradd -M -s /sbin/nologin www
解压配置:
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www  --with-fpm-group=www --enable-mysqlnd  --with-mysqli   --with-pdo-mysql --with-iconv-dir  --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp  --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts 

编译、安装:
​	make && make install

准备配置文件及配置服务

使用php-fpm进行管理php服务,有两个配置文件:

php.ini            #默认的PHP配置文件

php-fpm.conf       #php-fpm相关的配置

  1)复制配置文件:
​	cp /usr/local/php/etc/php-fpm.conf.default  /usr/local/php/etc/php-fpm.conf
​	cp /usr/local/php/etc/php-fpm.d/www.conf.default   /usr/local/php/etc/php-fpm.d/www.conf
​[root@T1 php-7.3.9]# cp php.ini-development /usr/local/php/etc/php.ini

  2)添加环境变量:

​		echo 'PATH=/usr/local/php/bin:$PATH'>>/etc/profile
​		source   /etc/profile

三、安装wordpress

把wordpress解压到/usr/local/nginx/html目录下
unzip wordpress-5.6-zh_CN.zip -d /usr/local/nginx/html/
mv /usr/local/nginx/html/wordpress /usr/local/nginx/html/qingmei

创建数据库wp:
mysql -uroot -p -e "CREATE DATABASE IF NOT EXISTS wp;"

浏览器打开URL:http://www.qingmei.com/wp-admin/setup-config.php
根据提示操作即可,然后把生成的网站配置信息复制保存到文档根目录的wp-config.php文件中
然后重新刷新浏览器,根据提示一步步完成安装。

注意1、数据如果使用localhost无法连接可以修改为127.0.0.1
      2、安装完wordpress后不要再次移动nginx的文档根。

Leave a Reply