LNMP
环境说明
- CentOS Linux release 7.5.1804 (Core) minimal install版本
- 192.168.80.101:nginx 1.14.2
- 192.168.80.102:mysql 5.7.30
- 192.168.80.103:php 5.5.38
- 全部为分离部署
nginx编译安装
1,安装依赖包
yum install -y lrzsz gcc gcc++ pcre-devel openssl-devel zlib-devel
# lrzsz用来上传本地下载好的源码包
2,下载源码包,解压,进入解压后目录
[root@nginx src]# ll
total 992
-rw-r--r-- 1 root root 1015384 Aug 24 09:23 nginx-1.14.2.tar.gz
[root@nginx src]# tar -xf nginx-1.14.2.tar.gz
[root@nginx src]# cd nginx-1.14.2
[root@nginx nginx-1.14.2]# pwd
/usr/local/src/nginx-1.14.2
3,三步走
#configure,根据需要启动或禁用相应的模块,指定worker进程的用户为nignx,指定安装目录为/usr/local/nginx
[root@nginx nginx-1.14.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_dav_module --with-http_stub_status_module --with-threads --with-file-aio --with-stream_realip_module --with-stream_ssl_module --with-stream --with-pcre --with-http_gzip_static_module --with-http_realip_module
#make
#make install
#安装后目录
[root@nginx nginx]# pwd
/usr/local/nginx
[root@nginx nginx]# ll
total 0
drwxr-xr-x 2 root root 333 Aug 30 16:35 conf
drwxr-xr-x 2 root root 40 Aug 30 16:35 html
drwxr-xr-x 2 root root 6 Aug 30 16:35 logs
drwxr-xr-x 2 root root 19 Aug 30 16:35 sbin
4,安装完成后
用户创建
[root@nginx nginx]# groupadd -g 2000 nginx
[root@nginx nginx]# useradd -u 2000 nginx -g nginx
[root@nginx nginx]# id nginx
uid=2000(nginx) gid=2000(nginx) groups=2000(nginx)
环境变量配置
[root@nginx nginx]# vim /etc/profile.d/nginx.sh
[root@nginx nginx]# cat /etc/profile.d/nginx.sh
export PATH=/usr/local/nginx/sbin:$PATH
[root@nginx nginx]# source /etc/profile.d/nginx.sh
[root@nginx nginx]# echo $PATH
/usr/local/nginx/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
启动测试
[root@nginx nginx]# nginx
[root@nginx nginx]# ss -nlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:80 *:*
[root@nginx nginx]# curl localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
...
php编译安装
1,安装依赖包
yum install -y bzip2-devel libmcrypt-devel openssl-devel libxml2-devel gcc gcc++
devel包不要写成level,写错过!
2,下载源码包,解压,进入解压后目录
[root@php src]# ll
total 17372
-rw-r--r-- 1 root root 17785731 Aug 19 15:26 php-5.5.38.tar.gz
[root@php src]# tar -xf php-5.5.38.tar.gz
[root@php src]# cd php-5.5.38
3,三步走
#configure:启用php-fpm方式,用mysqlnd连接数据库,指定安装目录,等,
[root@php php-5.5.38]# ./configure --prefix=/usr/local/php --with-openssl --with-mbstring --enable-sockets --with-freetype-dir --with-jpeg-dir --with-png-dir --with-libxml-dir=/usr --enable-xml --with-zlib --with-mcrypt --with-bz2 --with-mhash --with-config-file-path=/etc \--with-config-file-scan-dir=/etc/php.d --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-fpm
#make
#make install
php的configure脚本一些参数说明;
SAPI modules:
--with-apxs2=FILE Build shared Apache 2.0 Handler module. FILE is the optional
pathname to the Apache apxs tool apxs
php编译为apache模式的方式时,指定,模块的路径
--enable-fpm Enable building of the fpm SAPI executable
php单独运行为fpm格式;
General settings:
--with-config-file-path=PATH
Set the path in which to look for php.ini [PREFIX/lib]
php解释器的配置文件
--with-config-file-scan-dir=PATH
Set the path where to scan for configuration files
php-fpm的配置文件夹
---
php连接mysql方式2种;libmysql驱动连接、mysqlnd连接
# libmysql时:需先安装mysql,mysql-devel
# --with-mysql指定mysql安装路径
# with-mysqli mysql_config 脚本路径
# with-pdo-mysql mysql安装路径
# 例如:
./configure --prefix=/usr/local/php --with-mysql=/usrlocal/mysql --with-mysqli=/usr/local/mysql/bin/mysql_cofig
--with-pdo-mysql=/usr/local/mysql
--with-pdo-mysql=DIR PDO: MySQL support. DIR is the MySQL base directory
If no value or mysqlnd is passed as DIR, the
directory /usr/local/freetds
--with-mysql=DIR Include MySQL support. DIR is the MySQL base
directory, if no DIR is passed or the value is
mysqlnd the MySQL native driver will be used
--with-mysqli=FILE Include MySQLi support. FILE is the path
to mysql_config. If no value or mysqlnd is passed
as FILE, the MySQL native driver will be used
# mysqlnd驱动连接时,不需提前安装mysql mysql-devel
mysqlnd作为上面3项的值,然后enable-mysqlnd
# 例子
./configure --prefix=/usr/local/php --enable-mysqld --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd
--enable-mysqlnd Enable mysqlnd explicitly, will be done implicitly
when required by other extensions
建议用mysqlnd
# 扩展php支持类型的
--with-vpx-dir=DIR GD: Set the path to libvpx install prefix
--with-jpeg-dir=DIR GD: Set the path to libjpeg install prefix
--with-png-dir=DIR GD: Set the path to libpng install prefix
--with-zlib-dir=DIR GD: Set the path to libz install prefix
--with-xpm-dir=DIR GD: Set the path to libXpm install prefix
--with-freetype-dir=DIR GD: Set the path to FreeType 2 install prefix
加密,安装,压缩,等;
--with-libxml-dir=DIR LIBXML: libxml2 install prefix
--with-openssl=DIR Include OpenSSL support (requires OpenSSL >= 0.9.6)
--with-kerberos=DIR OPENSSL: Include Kerberos support
--with-pcre-regex=DIR Include Perl Compatible Regular Expressions support.
DIR is the PCRE install prefix BUNDLED
--without-sqlite3=DIR Do not include SQLite3 support. DIR is the prefix to
SQLite3 installation directory.
--with-zlib=DIR Include ZLIB support (requires zlib >= 1.0.9)
--with-zlib-dir=<DIR> Define the location of zlib install directory
4,安装后配置
php的配置文件php.ini
准备php的配置文件;php的一般还有个/etc/php.d/目录
[root@php php-5.5.38]# cp php.ini-production /etc/php.ini
[root@php php-5.5.38]# pwd
/usr/local/src/php-5.5.38
php-fpmd服务脚本
准备php-fpm的服务脚本,加入执行权限
[root@php php-5.5.38]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpmd
[root@php php-5.5.38]# chmod +x /etc/init.d/php-fpmd
[root@php php-5.5.38]# chkconfig php-fpmd on
php-fpmd的配置文件
准备php-fpm的配置文件;【和php的配置文件不一回事,类比java配置和tomcat的配置】
[root@php php-5.5.38]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
注意:/usr/local/php是编译安装的目录;根据情况修改;
修改监听端口为本机所有地址
[root@php php-5.5.38]# cd /usr/local/php/
[root@php php]# ll
total 0
drwxr-xr-x 2 root root 132 Aug 30 16:54 bin
drwxr-xr-x 2 root root 71 Aug 30 16:58 etc
drwxr-xr-x 3 root root 17 Aug 30 16:54 include
drwxr-xr-x 3 root root 17 Aug 30 16:54 lib
drwxr-xr-x 4 root root 28 Aug 30 16:54 php
drwxr-xr-x 2 root root 21 Aug 30 16:54 sbin
drwxr-xr-x 4 root root 28 Aug 30 16:54 var
[root@php php]# vim etc/php-fpm.conf
# 取消127.0.0.1,即改成监听所有地址
[root@php php]# service php-fpmd start
Starting php-fpm done
[root@php php]# ss -nlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:9000 *:*
LISTEN 0 128 *:22 *:*
修改php-fpm的进程用户
nginx配置转发时,需要2者进程用户一致,避免权限问题;uid不同时,测试也可以,但最好保持一致
[root@php php]# groupadd -g 2000 nginx
[root@php php]# useradd -u 2000 nginx -g nginx
[root@php php]# id nginx
uid=2000(nginx) gid=2000(nginx) groups=2000(nginx)
# 添加nginx用户,uid最好一致,
[root@php php]# vim etc/php-fpm.conf
[root@php php]# service php-fpmd restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
# 改为nginx用户启动
[root@php php]# ps aux|grep php
root 81399 0.0 0.4 74912 4196 ? Ss 17:02 0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
nginx 81400 0.0 0.3 74912 3744 ? S 17:02 0:00 php-fpm: pool www
nginx 81401 0.0 0.3 74912 3744 ? S 17:02 0:00 php-fpm: pool www
mysql二进制安装
1,下载二进制压缩包
2,解压,解压后目录做软链接
[root@mysql local]# tar -xf mysql-5.7.30-el7-x86_64.tar.gz
[root@mysql local]# ll
...
drwxr-xr-x 9 root root 129 Aug 30 17:10 mysql-5.7.30-el7-x86_64
-rw-r--r-- 1 root root 727333633 Aug 20 16:16 mysql-5.7.30-el7-x86_64.tar.gz
...
[root@mysql local]# ln -sv mysql-5.7.30-el7-x86_64 mysql
‘mysql’ -> ‘mysql-5.7.30-el7-x86_64’
3,配置环境变量
[root@mysql local]# vim /etc/profile.d/mysql.sh
[root@mysql local]# source /etc/profile.d/mysql.sh
[root@mysql local]# cat /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
4,创建数据目录
[root@mysql local]# mkdir /data/mysql -pv
mkdir: created directory ‘/data’
mkdir: created directory ‘/data/mysql’
5,创建用户
[root@mysql local]# useradd mysql
[root@mysql local]# chown -R mysql.mysql /data/mysql/
6,服务脚本
[root@mysql mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@mysql mysql]# pwd
/usr/local/mysql
7,配置文件
# 将原有配置文件备份,并修改
[root@mysql mysql]# cp /etc/my.cnf{,.bak}
[root@mysql mysql]# ll /etc/my.cnf*
-rw-r--r--. 1 root root 570 Jun 8 2017 /etc/my.cnf
-rw-r--r-- 1 root root 570 Aug 30 17:27 /etc/my.cnf.bak
# 修改如下
[root@mysql mysql]# vim /etc/my.cnf
[root@mysql mysql]# cat /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
symbolic-links=0
skip_name_resolve=on
[mysqld_safe]
log-error=/data/mysql/mariadb.log
pid-file=/data/mysql/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
6,执行数据库初始化脚本
[root@mysql mysql]# mysql_install_db --datadir=/data/mysql --user=mysql
2020-08-30 17:31:00 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2020-08-30 17:31:00 [ERROR] Child process: /usr/local/mysql-5.7.30-el7-x86_64/bin/mysqldterminated prematurely with errno= 32
2020-08-30 17:31:00 [ERROR] Failed to execute /usr/local/mysql-5.7.30-el7-x86_64/bin/mysqld --bootstrap --datadir=/data/mysql --lc-messages-dir=/usr/share/mysql --lc-messages=en_US
-- server log begin --
/usr/local/mysql-5.7.30-el7-x86_64/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
# 数据库初始化脚本会报错,需要libaio库,安装即可
[root@mysql mysql]# yum install -y libaio
# mysql_install_db脚本废弃,仍会报错,改用mysqld --initialize,会生成随机密码
[root@mysql mysql]# mysqld --initialize
...
[Note] A temporary password is generated for root@localhost: u5qu((8Cp>xs
7,本地连入,配置远程连接用户权限,建库,建用户
[root@mysql mysql]# service mysqld status
ERROR! MySQL is not running
[root@mysql mysql]# chkconfig mysqld on
[root@mysql mysql]# service mysqld start
Starting MySQL.Logging to '/data/mysql/mariadb.log'.
SUCCESS!
[root@mysql mysql]# ss -nlt
:::*
# 连接,用初始化时,生成的随机密码;-S指定通信的socket,默认的/tmp/mysql.sock替换为了/data/mysql/mysql.sock
[root@mysql mysql]# mysql -p"u5qu((8Cp>xs" -S /data/mysql/mysql.sock
# 需先修改密码
mysql> alter user root@'localhost' identified by 'wang';
Query OK, 0 rows affected (0.01 sec)
# 建立远程连接用户
mysql> grant all on *.* to root@'192.168.80.%' identified by 'wang';
配置nginx到php-fpm的转发
1,配置转发的虚拟主机
[root@nginx conf]# cat vhosts/lnmp.conf
server {
listen 80;
server_name www.pc.com;
location ~* \.php$ {
fastcgi_pass 192.168.80.103:9000;
fastcgi_param SCRIPT_FILENAME /php$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}
}
# 注意主配置文件中要include引入
# ping和status转发未配置,php-fpm也未启用
2,配置php-fpm环境
# 改php-fpm进程用户为nginx,上面已经完成
# 监听本机所有ip,上面已经完成
user = nginx
group = nginx
# 允许nginx主机的ip连接
listen.allowed_clients = 192.168.80.101
# 重启
[root@php php]# service php-fpmd restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
# 写入index.php文件
mkdir /php
[root@php php]# cat /php/index.php
<?php
phpinfo()
?>
至此,lnmp环境搭建完成
Discuz
单机部署
nginx和php-fpm在同一台主机部署;nginx的【网页根目录文件】,和php-fpm的【脚本文件根目录文件】是同一个目录,此时页面正常,discuz正常搭建;
1,下载程序包,解压,到网页根目录
# nginx配置,分离部署失败时,采用单机部署,
[root@php upload]# vim /etc/nginx/conf.d/lnmp.conf
server {
listen 80;
server_name www.test.com;
location / {
root /php; # /php是nginx的这个虚拟主机的网页文件根目录
index index.php index.html;
}
location ~* \.php$ {
fastcgi_pass 192.168.80.103:9000;
# 103就是本机地址,改为127.0.0.1也行,
# 注意php-fpm配置文件要允许192.168.80.103的自己的连接
fastcgi_param SCRIPT_FILENAME /php$fastcgi_script_name;
# /php也是转发php文件的存放php脚本文件的根目录
# 单机部署时,2者必须是同一个目录!!
fastcgi_index index.php;
include fastcgi_params;
}
}
# 网页目录,和脚本目录,/php
# 将discuz解压后的upload该/php目录下
[root@php upload]# pwd
/php/upload
[root@php upload]# ll
total 76
-rw-r--r-- 1 root root 2739 May 31 2016 admin.php
drwxr-xr-x 11 root root 163 May 31 2016 api
-rw-r--r-- 1 root root 727 May 31 2016 api.php
drwxr-xr-x 2 root root 23 May 31 2016 archiver
drwxrwxrwx 2 root root 141 Aug 30 19:32 config
...
2,浏览器打开http://www.test.com/uplaod
会有下图错误,根据提示创建对应目录,文件,修改权限即可
根据页面报错,做对应修改即可,命令如下
touch config/config_{global,ucenter}.php
chmod a+w config/config_{global,ucenter}.php
chmod a+w data config data/{cache,avatar,plugindata,download,addonmd5,template,threadcache,attachment,log} data/attachment/{album,forum,group}
chmod a+w uc_client/data/cache
chmod a+w uc_server/data uc_server/data/{cache,avatar,backup,logs,tmp,view}
修改后即可通过检查,根据提示,填入mysql的地址,即可成功安装;
多机分离部署
问题:
- nginx和php-fpm同一个主机部署时, nginx的网页文件目录,和转发的php-fpm的脚本文件根目录是同一个!
- 分开时:
- 需要nginx和php-fpm主机,各在自己的网页根目录,放一份discuz的upload目录,
- 都需要根据页面提示,创建文件,修改权限;
- 但是,打开后,动静资源分离不当,页面混乱如下图:
- 待解决;
解决方案:
- NFS!
- 既然必须要求nginx的网页根目录,和php的脚本文件根目录必须是同一个目录;
- 那么,nginx和php-fpm分离的情况下,nfs就可以实现!!!
- 注意点:
- 本来转发时,就要求,php-fpm的进程用户和nginx的worker进程用户一致,都是nginx,同理若是apache,那都要是apache,
- 做nfs共享目录时,2者nginx用户的uid必须保持一致!
- 一般php做nfs共享,让nginx去挂载;discuz的程序目录选一边放置即可;
- nfs共享出的目录和客户端挂载的目录,要保持一致!
Wordpress
wordpress临时笔记
wordpress采用多机分离部署:
nginx和php-fpm分离部署;
1,下载源码包
2,解压
tar -xf wordpress-3.9.32.tar.gz
drwxr-xr-x 5 nobody nfsnobody 4096 Jun 11 06:14 wordpress
-rw-r--r-- 1 root root 5795310 Aug 30 21:01 wordpress-3.9.32.tar.gz
chown -R nginx.nginx /wordpress/
3,创建数据库,和用户
mysql> create database wordpress;
mysql> grant all on wordpress.* to wp@’192.168.80.%' identified by 'wp';
4,遇到问题,
- 1,是wordpress解压后目录,所放目录位置;
- 1种是解压后wordpress目录下的内容,直接网站根目录——访问的是http://ip/
- 还1种是网站子目录,解压后wordpress目录放在网站根目录——访问的是http://ip/wordpress
- 2,还有就是版本兼容问题,一开始高版本的wordpress不兼容低版本的php,换成低版本的wordpress之后就可以了,或者把php换成高版本,总之版本要匹配;兼容
官方描述:
1种是直接网站根目录
1种是网站子目录
Upload the WordPress files to the desired location on your web server:
If you want to integrate WordPress into the root of your domain (e.g. http://example.com/), move or upload all contents of the unzipped WordPress directory (excluding the WordPress directory itself) into the root directory of your web server.
If you want to have your WordPress installation in its own subdirectory on your website (e.g. http://example.com/blog/), create the blog directory on your server and upload the contents of the unzipped WordPress package to the directory via FTP.
Note: If your FTP client has an option to convert file names to lower case, make sure it’s disabled.
Run the WordPress installation script by accessing the URL in a web browser. This should be the URL where you uploaded the WordPress files.
If you installed WordPress in the root directory, you should visit: http://example.com/
If you installed WordPress in its own subdirectory called blog, for example, you should visit: http://example.com/blog/
报错,显示,根据报错,怀疑为语法不兼容,换成低版本之后,即可;
从5.4.2,换成3.9.32后即可;
-rw-r--r-- 1 root root 5795310 Aug 30 21:01 wordpress-3.9.32.tar.gz
-rw-r--r-- 1 root root 12872547 Aug 30 20:12 wordpress-5.4.2-zh_CN.tar.gz
2020/08/30 20:53:11 [error] 10164#10164: *131 FastCGI sent in stderr: "PHP message: PHP Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in /wordpress/blog/wp-includes/functions.php on line 1081" while reading response header from upstream, client: 192.168.80.1, server: www.pc.com, request: "GET /blog/ HTTP/1.1", upstream: "fastcgi://192.168.80.103:9000", host: "www.pc.com
5,访问测试,访问http://www.pc.com/blog即打开wordpress的安装目录,填入数据库信息,一步步安装即可;
1,php-fpm,部署,nfs服务,开放给nginx挂载,用于存放一份程序;
[root@php ~]# mkdir /www
[root@php ~]# vim /etc/exports
[root@php ~]# cat /etc/exports
/wordpress 192.168.80.0/24(rw,no_root_squash,sync)
/www 192.168.80.0/24(rw,no_root_squash,sync)
2,nginx挂载,
mount.nfs 192.168.80.103:/www /www
3,nginx配置转发的虚拟主机
server {
listen 80;
server_name www.word.com;
location / {
root /www;
index index.php index.html index.htm;
}
location ~* \.php$ {
fastcgi_pass 192.168.80.103:9000;
fastcgi_param SCRIPT_FILENAME /www$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}
}
4,解压wordpress目录带合适目录,选择网站根目录,或子目录;
5,数据库,建立用户,建立数据库
6,浏览器打开
根据步骤,安装即可;
wordpress笔记梳理后
1,建立wordpress用到的数据库,和用户
mysql> create database word;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on word.* to word@'192.168.80.%' identified by 'word';
Query OK, 0 rows affected, 1 warning (0.01 sec)
2,在php-fpm主机上,配置nfs
yum install -y nfs-utils
systemctl start nfs
[root@php ~]# mkdir /data
[root@php ~]# chown -R nginx.nginx /data/
[root@php ~]# vim /etc/exports
[root@php ~]# systemctl restart nfs
[root@php ~]# showmount -e 192.168.80.103
Export list for 192.168.80.103:
/data 192.168.80.0/24
3,nginx主机上,挂载php-fpm共享出的目录
[root@nginx ~]# mkdir /data
#创建挂载点,和nfs共享出来的要相同
[root@nginx ~]# yum install -y mount.nfs
[root@nginx ~]# mount.nfs 192.168.80.103:/data /data
[root@nginx ~]#
#下载mount.nfs工具,然后挂载;
[root@nginx ~]# groupadd -g 2000 nginx
[root@nginx ~]# useradd -u 2000 -g nginx nginx
[root@nginx ~]# id nginx
uid=2000(nginx) gid=2000(nginx) groups=2000(nginx)
# 创建同id的nginx用户
[root@nginx ~]# chown -R nginx.nginx /data/
[root@nginx ~]# ll /data/ -d
drwxr-xr-x 2 nginx nginx 6 Aug 31 11:00 /data/
# 改为nginx属主
4,nginx配置转发,虚拟主机为www.word.com,该虚拟主机网页文件根目录为/data,也是phpfpm读取php脚本文件的根目录,2者是同一个目录,为php-fpm主机nfs共享给nginx所用;
[root@nginx conf.d]# cat word.conf
server {
listen 80;
server_name www.word.com;
root /data;
index index.php index.html;
location ~* \.php$ {
fastcgi_pass 192.168.80.103:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data$fastcgi_script_name;
include fastcgi_params;
}
}
[root@nginx conf.d]# pwd
/etc/nginx/conf.d
# 为nginx仓库yum安装的版本;
5,php-fpm修改配置文件
[root@php etc]# vim php-fpm.conf
[root@php etc]# grep -v "^;" php-fpm.conf
[global]
[www]
user = nginx
group = nginx
listen = 9000
listen.allowed_clients = 192.168.80.101,192.168.80.103
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
[root@php etc]# pwd
/usr/local/php/etc
[root@php etc]# service php-fpmd restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
# 主要修改,用户,组为nginx,监听本机所有ip,运行nginx的ip的连接;重启
6,写入测试页面,在网页文件根目录下
[root@php data]# pwd
/data
[root@php data]# cat test.php
<?php
phpinfo()
?>
7,改hosts文件,访问测试;
8,下载wordpress,解压
[root@php ~]# tar -xf wordpress-3.9.32.tar.gz
[root@php ~]# ll
drwxr-xr-x 5 nobody nfsnobody 4096 Jun 11 06:14 wordpress
-rw-r--r-- 1 root root 5795310 Aug 30 21:01 wordpress-3.9.32.tar.gz
-rw-r--r-- 1 root root 12872547 Aug 30 20:12 wordpress-5.4.2-zh_CN.tar.gz
[root@php ~]# cp -a wordpress /data/
[root@php ~]# chown -R nginx.nginx /data/wordpress/
[root@php ~]# ll /data/
total 4
drwxr-xr-x 5 nginx nginx 4096 Jun 11 06:14 wordpress
# php版本较低,改用低版本的wordpress
9,访问,安装
访问的是带有wordpress目录的
安装discuz
1,解压discz,将解压后的upload目录放到网站根目录/data目录下;
[root@php ~]# unzip Discuz_X3.2_SC_UTF8.zip
[root@php ~]# ll
total 30444
-rw-------. 1 root root 1391 Aug 8 12:02 anaconda-ks.cfg
-rw-r--r-- 1 root root 12486773 Aug 20 17:00 Discuz_X3.2_SC_UTF8.zip
drwxr-xr-x 2 root root 102 May 31 2016 readme
-rw-r--r-- 1 root root 21 Aug 31 14:20 test.php
drwxr-xr-x 12 root root 4096 May 31 2016 upload
drwxr-xr-x 4 root root 72 May 31 2016 utility
drwxr-xr-x 5 nobody nfsnobody 4096 Jun 11 06:14 wordpress
-rw-r--r-- 1 root root 5795310 Aug 30 21:01 wordpress-3.9.32.tar.gz
-rw-r--r-- 1 root root 12872547 Aug 30 20:12 wordpress-5.4.2-zh_CN.tar.gz
[root@php ~]# cp -a upload/ /data/
[root@php ~]# ll /data/
total 8
drwxr-xr-x 12 root root 4096 May 31 2016 upload
drwxr-xr-x 5 nginx nginx 4096 Aug 31 16:49 wordpress
#改属主
[root@php ~]# chown -R nginx.nginx /data/upload/
[root@php ~]# ll /data/
total 8
drwxr-xr-x 12 nginx nginx 4096 May 31 2016 upload
drwxr-xr-x 5 nginx nginx 4096 Aug 31 16:49 wordpress
2,浏览器访问,执行安装
填写数据库ip,数据库root的用户名和密码,指定数据库,稍后会在mysql里创建该库,用作discuz的数据库
安装成功
要点
- 单机部署时(nginx和php-fpm同一个主机)数据库无所谓,网通就行;
- nginx的虚拟主机的网站根目录要和php-fpm的脚本根目录是同一个目录!
- 主语nginx的worker进程和php-fpm的进程用户是不是相同,都为nginx或apache(LAMP时)
- 网站根目录下的文件属主要改为nginx,避免权限问题
- php-fpm要允许本机的连接,默认行为;
- 然后在网站根目录下,放置解压后的wordpress或discuz的upload目录
- 访问:http://域名/ [wordpress| upload],执行wordpress或discuz的安装程序即可;
- wordpress需要提前创建数据库和用户
- discuz需提供数据库的root用户密码,在安装时创建;
- 多机部署时(nginx和php-fpm不同主机)
- nginx的虚拟主机的网站根目录要和php-fpm的脚本根目录是同一个目录!
- 因此,通过nfs服务实现,2者挑一台做nfs服务端,另一端挂载
- 进程属主,目录权限,和单机类似
- nfs服务情况下,两端nignx或apache用户uid最好也保持一致
- php-fpm要监听本机所有ip,开放nginx主机过来的连接;
powerdns
1,下载程序包,解压
tar -xf poweradmin-2.1.7.tgz
mv poweradmin-2.1.7 poweradmin
cp -a poweradmin /data/
chown -R nginx.nginx /data/poweradmin/
#
解压
改解压后的目录名,去掉版本号
复制到网站根目录
改属主
2,访问安装
访问到install目录,报错;错误提示如下,估计又是php版本和程序包版本不兼容;
http://www.word.com/poweradmin/install/
2020/08/31 17:16:19 [error] 4395#4395: *76 FastCGI sent in stderr: "PHP message: PHP Fatal error: Call to undefined function _() in /data/poweradmin/inc/error.inc.php on line 25" while reading response header from upstream, client: 192.168.80.1, server: www.word.com, request: "GET /poweradmin/install/ HTTP/1.1", upstream: "fastcgi://192.168.80.103:9000", host: "www.word.com"
[root@nginx ~]# tail /var/log/nginx/error.log
phpmyadmin
1,下载程序包,解压,将解压后目录放到网页文件根目录
503 unzip phpMyAdmin-4.0.10.20-all-languages.zip
505 mv phpMyAdmin-4.0.10.20-all-languages phpmyadmin
506 cp -a phpmyadmin/ /data/
解压,改目录名去掉版本号,复制到网页根目录
512 cd phpmyadmin/
514 cp config.sample.inc.php config.inc.php
521 chown -R nginx.nginx /data/
准备config.inc.php问,改属主
2,浏览器访问,执行安装
php缺少mbstring扩展,在php.ini里取消mbstring扩展的注释,重启报错,原因在于php编译安装时,未编译该扩展;
[root@php phpmyadmin]# vim /etc/php.ini
[root@php phpmyadmin]# service php-fpmd restart
Gracefully shutting down php-fpm . done
Starting php-fpm [31-Aug-2020 17:29:07] NOTICE: PHP message: PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/php_mbstring.dll' - /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/php_mbstring.dll: cannot open shared object file: No such file or directory in Unknown on line 0
done
lnmp环境、应用部署总结
- lnmp环境部署(lamp同理,无非是用httpd配置一个fastcgi的转发虚拟主机)
- 单机部署
- 多机分离部署
- 需注意问题:见上面要点整理
- 应用部署
- wordpress
- discuz
- powerdns
- phpmyadmin
- 需注意问题:程序包版本和php的版本兼容问题;程序包需要的php扩展问题,编译安装php时尤其注意有无编译需要的扩展
- 遇到的问题有如:wordpress高版本需要高版本的php,phpmyadmin需要php有mbstring扩展;
- 多看程序官方文档;