利用LNMP搭建wordpress站点(源码编译)

1台  Linux+Nginx+PHP+WordPress  系统:CentOS 7.9

1台  MySQL+Redis 服务器                系统:CentOS 7.9

<Mysql>

hostnamectl set-hostname MySQL-Redis
bash

yum update -y    #非必要不更新,太久了

yum install mariadb-server -y
systemctl enable --now mariadb

mysql

create database wordpress;
create user wordpress@'另一台机IP' identified by '123456';
grant all on wordpress.* to wordpress@'另一台机IP';
exit;
<LNP服务器>

hostnamectl set-hostname LNP-Server
bash

yum install mariadb-server -y
mysql -uwordpress -p123456 -h + MYSQL服务器IP   #验证mysql连接性

<----------编译安装php---------->

yum -y install gcc openssl-devel libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel oniguruma-devel  #一定要检查是否全部安装成功,否则编译一定有问题

#######  yum update -y  #如果安装失败就更新一下再安装

wget https://www.php.net/distributions/php-7.4.28.tar.xz
tar xf php-7.4.28.tar.xz 
cd php-7.4.28/

<----------编译前检查---------->

./configure --prefix=/apps/php74 --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-zlib --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-mbstring --enable-xml --enable-sockets --enable-fpm -enable-maintainer-zts --disable-fileinfo

Thank you for using PHP.  #出现该信息才算成功

<----------编译---------->

make && make install

----------------------------------------------------------------'

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /apps/php74/lib/php/extensions/no-debug-zts-20190902/
Installing PHP CLI binary:        /apps/php74/bin/
Installing PHP CLI man page:      /apps/php74/php/man/man1/
Installing PHP FPM binary:        /apps/php74/sbin/
Installing PHP FPM defconfig:     /apps/php74/etc/
Installing PHP FPM man page:      /apps/php74/php/man/man8/
Installing PHP FPM status page:   /apps/php74/php/php/fpm/
Installing phpdbg binary:         /apps/php74/bin/
Installing phpdbg man page:       /apps/php74/php/man/man1/
Installing PHP CGI binary:        /apps/php74/bin/
Installing PHP CGI man page:      /apps/php74/php/man/man1/
Installing build environment:     /apps/php74/lib/php/build/
Installing header files:          /apps/php74/include/php/
Installing helper programs:       /apps/php74/bin/
  program: phpize
  program: php-config
Installing man pages:             /apps/php74/php/man/man1/
  page: phpize.1
  page: php-config.1
/usr/local/src/php-7.4.28/build/shtool install -c ext/phar/phar.phar /apps/php74/bin/phar.phar
ln -s -f phar.phar /apps/php74/bin/phar
Installing PDO headers:           /apps/php74/include/php/ext/pdo/

###出现这类字眼就算安装成功

----------------------------------------------------------------

cp php.ini-production /etc/php.ini
cd /apps/php74/etc
cp php-fpm.conf.default php-fpm.conf
cd php-fpm.d/
cp www.conf.default www.conf
vim www.conf

修改下列参数为:

;user = nobody
user = www

;group = nobody
group = www

;pm.status_path = /status
pm.status_path = /status

;ping.path = /ping
ping.path = /ping

;access.log = log/$pool.access.log
access.log = log/$pool.access.log 

;slowlog = log/$pool.log.slow
slowlog = log/$pool.log.slow

:wq!

grep '^[^;]' www.conf          #使用该命令隐藏所有以;开头的行,用作比对:
[www]
user = www
group = www
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.status_path = /status
ping.path = /ping
access.log = log/$pool.access.log
slowlog = log/$pool.log.slow  


useradd -r -s /sbin/nologin www
mkdir /apps/php74/log

/apps/php74/sbin/php-fpm -t     #检查配置文件语法
[28-Dec-2023 10:16:48] NOTICE: configuration file /apps/php74/etc/php-fpm.conf test is successful

cp ~/php-7.4.28/sapi/fpm/php-fpm.service /usr/lib/systemd/system/

systemctl daemon-reload
systemctl enable --now php-fpm


<----------编译安装nginx---------->


yum -y install gcc pcre-devel openssl-devel zlib-devel #安装依赖

cd /usr/local/src/       #nginx源码放置位置
wget http://nginx.org/download/nginx-1.20.2.tar.gz
tar xf nginx-1.20.2.tar.gz
cd nginx-1.20.2

<----------编译前检查---------->

./configure --prefix=/apps/nginx --user=www --group=www --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module

注意看依赖有没有缺少,然后安装

<----------编译---------->

make && make install

----------------------------------------------------------------

vim /usr/lib/systemd/system/nginx.service

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/apps/nginx/run/nginx.pid
ExecStart=/apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target

:wq!

vim /apps/nginx/conf/nginx.conf\

#仅修改以下内容:
pid        /apps/nginx/run/nginx.pid; 

:wq!

systemctl daemon-reload
systemctl enable --now nginx


<----------配置 Nginx 支持 fastcgi---------->

vim /apps/nginx/conf/nginx.conf
#仅修改以下内容,没有的要自己加上去,有点乱,仔细对比

worker_processes  auto;
pid        /apps/nginx/run/nginx.pid;
    server {
        listen       80;
        server_name  localhost;
        location / {
        root /data/nginx/wordpress;
        index index.php index.html index.htm; 
        }

        location \.php$ {
            root /data/nginx/wordpress;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }

        location ^/(ping|pm_status)$ {
        include fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
        }

:wq!

-----------------------------------------------------------------------------

grep -Ev '#|^$' /apps/nginx/conf/nginx.conf   #隐藏注释符继续对比

worker_processes  auto;
pid        /apps/nginx/run/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;    #指定域名
        location / {
        root /data/nginx/wordpress;    #指定数据目录
        index index.php index.html index.htm;    # 指定默认主页文件
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location \.php$ {                      #实现php-fpm
            root /data/nginx/wordpress;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
        location ^/(ping|pm_status)$ {         #PHP检测状态页
        include fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
        }
    }
}

-------------------------------------------------------------------------------

systemctl reload nginx
mkdir -p /data/nginx/wordpress
vim /data/nginx/wordpress/phpinfo.php

<?php
phpinfo();
?>

:wq!

###测试页面:

浏览器输入:ip/ping

###状态页:ip/phpinfo.php

<----------部署WordPress---------->

wget https://cn.wordpress.org/latest-zh_CN.tar.gz

cp -r wordpress/* /data/nginx/wordpress
chown -R www.www /data/nginx/wordpress/

可选使用域名访问:添加hosts:
C:\Windows\System32\drivers\etc\hosts
添加内容为ip<空格>域名

使用ip或域名访问即可看到WordPress首页





nginx源码位置:/usr/local/src/

安装位置:/apps/nginx

php源码位置:~/php-7.4.28.tar.xz

安装位置:/apps/php74

WordPress安装位置:/data/nginx/wordpress/

  • 8
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值