LNMP部署wordpress

1、编译安装LNMP,并安装wordpress

node-1:192.168.10.3:编译安装nginx,php-fpm

node-2:192.168.10.4:编译安装mariadb-10.0.38

node-2编译安装mariadb-10.0.38:

安装相关依赖包

yum install bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel gcc gcc-c++ cmake ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel

准备用户和数据目录

[root@node-2 ~]# useradd -r -s /sbin/nologin -d /data/mysql/ mysql

[root@node-2 ~]# ls /data/mysql/

[root@node-2 ~]# chown mysql.mysql /data/mysql

[root@node-2 ~]# ll -d /data/mysql

drwxr-xr-x 2 mysql mysql 6 May  7 08:43 /data/mysql

解压安装包:

[root@node-2 ~]# tar xvf mariadb-10.0.38.tar.gz

cmake 编译安装

cd mariadb-10.2.18/

cmake . \

-DCMAKE_INSTALL_PREFIX=/app/mysql \

-DMYSQL_DATADIR=/data/mysql/ \

-DSYSCONFDIR=/etc/ \

-DMYSQL_USER=mysql \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DWITHOUT_MROONGA_STORAGE_ENGINE=1 \

-DWITH_DEBUG=0 \

-DWITH_READLINE=1 \

-DWITH_SSL=system \

-DWITH_ZLIB=system \

-DWITH_LIBWRAP=0 \

-DENABLED_LOCAL_INFILE=1 \

-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci

make -j 4&& make install

提示:如果出错,执行rm -f CMakeCache.txt

准备环境变量

echo 'PATH=/app/mysql/bin:$PATH' > /etc/profile.d/mysql.sh

. /etc/profile.d/mysql.sh

生成数据库文件

cd /app/mysql/

scripts/mysql_install_db --datadir=/data/mysql/ --user=mysql

准备配置文件

cp /app/mysql/support-files/my-huge.cnf /etc/my.cnf

准备启动脚本

cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld

启动服务

chkconfig --add mysqld ;service mysqld start

创建数据库并授权

[root@node-2 ~]# mysql

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 6

Server version: 10.0.38-MariaDB Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database wordpress;

Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all privileges on wordpress.* to "wordpress"@"192.168.10.%" idenfied by "123456";

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'idenfied by "123456"' at line 1

MariaDB [(none)]> grant all privileges on wordpress.* to "wordpress"@"192.168.10.%" identified by "123456";

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show databases;

+--------------------+

| Database          |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test              |

| wordpress          |

+--------------------+

5 rows in set (0.05 sec)

编译安装php7.2.15:

yum install libxml2-devel bzip2-devel libmcrypt-devel (epel)

tar xvf php-7.3.5.tar.bz2

cd php-7.3.5/

./configure --prefix=/app/php \

--enable-mysqlnd \

--with-mysqli=mysqlnd \

--with-pdo-mysql=mysqlnd \

--with-openssl \

--with-freetype-dir \

--with-jpeg-dir \

--with-png-dir \

--with-zlib \

--with-libxml-dir=/usr \

--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

make && make install

准备PHP配置文件:

    cp php.ini-production /etc/php.ini 

    cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

    chmod +x /etc/init.d/php-fpm

    chkconfig --add php-fpm

    chkconfig php-fpm on

    cd /app/php/etc

    cp php-fpm.conf.default php-fpm.conf

    cp php-fpm.d/www.conf.default php-fpm.d/www.conf

    service php-fpm start

修改PHP配置文件:

[root@node-1 php-fpm.d]# grep -v ";" www.conf |grep -v "^$"

[www]

user = www

group = www

listen = 127.0.0.1:9000

pm = dynamic

pm.max_children = 50

pm.start_servers = 30

pm.min_spare_servers = 30

pm.max_spare_servers = 35

pm.status_path = /pm_status

ping.path = /ping

ping.response = pong

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

slowlog = log/$pool.log.slow

[root@node-1 php-fpm.d]# mkdir /app/php/log        创建日志文件

[root@node-1 php-fpm.d]# /app/php/sbin/php-fpm -t        验证php-fpm

[07-May-2020 12:40:33] NOTICE: configuration file /app/php/etc/php-fpm.conf test is successful

编译安装nginx:

   useradd -r -s /sbin/nologin nginx        创建nginx用户

./configure --prefix=/apps/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --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

make -j 4 && make install

准备环境变量

echo 'PATH=/apps/nginx/sbin/:$PATH' > /etc/profile.d/nginx.sh

. /etc/profile.d/nginx.sh

准备PHP测试页面:

[root@node-1 nginx-1.12.2]# mkdir /data/nginx/wordpress -p

[root@node-1 nginx-1.12.2]# vim /data/nginx/wordpress/index.php

[root@node-1 nginx-1.12.2]# vim /data/nginx/wordpress/index.php

        phpinfo();

?>

配置nginx

server {

        listen      80;

        server_name  www.magedu.net;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {

            root  /data/nginx/wordpress;

            index  index.php index.html index.htm;

                if ($http_user_agent ~ "ApacheBench|WebBench|TurnitinBot|Sogou web spider|GridServer") {

                return 403;

                }

location ~ \.php$ {

            proxy_pass  http://127.0.0.1;

                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;

测试PHP

部署wordpress:

[root@node-1 ~]# cd /data/nginx/wordpress/

[root@node-1 ~]# tar xvf wordpress-5.0-zh_CN.tar.gz

[root@node-1 wordpress]# mv index.php /opt

[root@node-1 wordpress]# mv wordpress/* .

[root@node-1 wordpress]# mv wordpress-5.0-zh_CN.tar.gz /root         

[root@node-1 wordpress]# cp wp-config-sample.php wp-config.php         

[root@node-1 wordpress]# vim wp-config.php

define('DB_NAME', 'wordpress');

/** MySQL数据库用户名 */

define('DB_USER', 'wordpress');

/** MySQL数据库密码 */

define('DB_PASSWORD', '123456');

/** MySQL主机 */

define('DB_HOST', '192.168.10.4');

[root@node-1 wordpress]# chown www.www /data/nginx/wordpress/ /apps/nginx/ -R

[root@node-1 wordpress]# /apps/nginx/sbin/nginx -s reload

你可能感兴趣的:(LNMP部署wordpress)