源码编译安装LNMP+wordpress

实验环境:
node1:192.168.2.7 node2:192.168.2.17
OS:centos7 OS:centos7
安装包:nginx,php,wordpress 安装包 :mariadb

安装版本如下:

php-7.3.2.tar.xz
wordpress-5.0.3-zh_CN.tar.gz
mariadb-10.2.25.tar.gz
nginx-1.14.2.tar.gz

编译安装nginx
安装依赖包

[root@node1 ~]$yum -y install gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl openssl-devel
...

创建nginx用户

[root@node1 ~]$useradd -r -s /sbin/nologin nginx
[root@node1 ~]$id nginx
uid=998(nginx) gid=996(nginx) groups=996(nginx)
[root@node1 ~]$getent passwd nginx
nginx:x:998:996::/home/nginx:/sbin/nologin

解包,安装

[root@node1 ~]$tar xf nginx-1.14.2.tar.gz -C /usr/local/src/
[root@node1 ~]$cd /usr/local/src/
[root@node1 src]$cd nginx-1.14.2/
[root@node1 nginx-1.14.2]$./configure --prefix=/apps/nginx \
> --user=nginx \
> --group=nginx \
> --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

...

[root@node1 nginx-1.14.2]$make && make install
...

测试是否安装成功,并加入开机自启

[root@node1 nginx-1.14.2]$ss -tnl
State       Recv-Q Send-Q        Local Address:Port                       Peer Address:Port              
LISTEN      0      100               127.0.0.1:25                                    *:*                  
LISTEN      0      128                       *:22                                    *:*                  
LISTEN      0      100                   [::1]:25                                 [::]:*                  
LISTEN      0      128                    [::]:22                                 [::]:*                  
[root@node1 nginx-1.14.2]$/apps/nginx/sbin/nginx 
[root@node1 nginx-1.14.2]$ss -tnl
State       Recv-Q Send-Q        Local Address:Port                       Peer Address:Port              
LISTEN      0      100               127.0.0.1:25                                    *:*                  
LISTEN      0      128                       *:80                                    *:*                  
LISTEN      0      128                       *:22                                    *:*                  
LISTEN      0      100                   [::1]:25                                 [::]:*                  
LISTEN      0      128                    [::]:22                                 [::]:*                  
[root@node1 nginx-1.14.2]$curl 192.168.2.7
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

[root@node1 nginx-1.14.2]$ln -sv /apps/nginx/sbin/nginx /usr/sbin
‘/usr/sbin/nginx’ -> ‘/apps/nginx/sbin/nginx’

[root@node1 nginx-1.14.2]$ll /etc/rc.d/rc.local 
-rw-r--r--. 1 root root 497 Dec 13 12:24 /etc/rc.d/rc.local

[root@node1 nginx-1.14.2]$vim /etc/rc.d/rc.local
[root@node1 nginx-1.14.2]$tail -1 /etc/rc.d/rc.local
/apps/nginx/sbin/nginx

[root@node1 nginx-1.14.2]$chmod +x /etc/rc.d/rc.local
[root@node1 nginx-1.14.2]$ll /etc/rc.d/rc.local
-rwxr-xr-x. 1 root root 497 Dec 13 12:24 /etc/rc.d/rc.local

编译安装PHP
安装依赖包

[root@node1 ~]$yum -y install libxml2-devel bzip2-devel libmcrypt-devel
...

解压,安装

[root@node1 ~]$tar xf php-7.3.2.tar.xz -C /usr/local/src
[root@node1 ~]$cd /usr/local/src
[root@node1 src]$cd php-7.3.2/
[root@node1 php-7.3.2]$./configure --prefix=/apps/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
...

[root@node1 php-7.3.2]$make && make install
...

配置

[root@node1 php-7.3.2]$cp /usr/local/src/php-7.3.2/php.ini-production /etc/php.ini
[root@node1 php-7.3.2]$cp /apps/php/etc/php-fpm.conf.default /apps/php/etc/php-fpm.conf
[root@node1 php-7.3.2]$cp /apps/php/etc/php-fpm.d/www.conf.default /apps/php/etc/php-fpm.d/www.conf
[root@node1 php-7.3.2]$vim /apps/php/etc/php-fpm.d/www.conf
user = nginx
group = nginx

准备启动脚本

[root@node1 php-7.3.2]$cp /usr/local/src/php-7.3.2/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@node1 php-7.3.2]$ll /etc/init.d/php-fpm
-rw-r--r-- 1 root root 2396 Dec 13 12:52 /etc/init.d/php-fpm
[root@node1 php-7.3.2]$chmod +x /etc/init.d/php-fpm
[root@node1 php-7.3.2]$ll /etc/init.d/php-fpm
-rwxr-xr-x 1 root root 2396 Dec 13 12:52 /etc/init.d/php-fpm
[root@node1 php-7.3.2]$chkconfig --add php-fpm
[root@node1 php-7.3.2]$chkconfig php-fpm on
[root@node1 php-7.3.2]$chkconfig --list php-fpm

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

php-fpm         0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@node1 php-7.3.2]$service php-fpm start
Starting php-fpm  done
[root@node1 php-7.3.2]$ss -tnl
State       Recv-Q Send-Q        Local Address:Port                       Peer Address:Port              
LISTEN      0      100               127.0.0.1:25                                    *:*                  
LISTEN      0      128               127.0.0.1:9000                                  *:*                  
LISTEN      0      128                       *:80                                    *:*                  
LISTEN      0      128                       *:22                                    *:*                  
LISTEN      0      100                   [::1]:25                                 [::]:*                  
LISTEN      0      128                    [::]:22                                 [::]:*                  
[root@node1 php-7.3.2]$ps aux |grep nginx
root      12957  0.0  0.0  46168  1160 ?        Ss   12:21   0:00 nginx: master process /apps/nginx/sbin/nginx
nginx     12958  0.0  0.1  46616  2156 ?        S    12:21   0:00 nginx: worker process
nginx     15792  0.0  0.3  71004  5640 ?        S    12:54   0:00 php-fpm: pool www
nginx     15793  0.0  0.3  71004  5640 ?        S    12:54   0:00 php-fpm: pool www
root      15796  0.0  0.0 112812   968 pts/0    R+   12:54   0:00 grep --color=auto nginx

配置nginx,使其支持php,并测试

[root@node1 php-7.3.2]$cd
[root@node1 ~]$
[root@node1 ~]$vim /apps/nginx/conf/nginx.conf
include /apps/nginx/conf.d/*.conf;                              #在默认的server外增加这条
[root@node1 ~]$nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
[root@node1 ~]$mkdir /data/www/html -pv
mkdir: created directory ‘/data/www’
mkdir: created directory ‘/data/www/html’

[root@node1 ~]$mkdir /apps/nginx/conf.d
[root@node1 ~]$vim /apps/nginx/conf.d/vhosts.conf
[root@node1 ~]$cat /apps/nginx/conf.d/vhosts.conf
charset utf-8;
server {
    listen 80;
    server_name www.x.com;

    location / {
        root /data/www/html;
        index index.php index.html index.htm;
    }

    location ~* \.php$ {
        root /data/www/html;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

[root@node1 ~]$cat /data/www/html/index.php 
<?php
    phpinfo();
?>

windows机器配置hosts文件,显示如下:
源码编译安装LNMP+wordpress

编译安装mariadb(node2)
准备用户和存放数据库的目录

[root@node2 ~]$useradd -r -s /sbin/nologin -d /data/mysql mysql
[root@node2 ~]$id mysql
uid=998(mysql) gid=996(mysql) groups=996(mysql)
[root@node2 ~]$getent passwd mysql
mysql:x:998:996::/data/mysql:/sbin/nologin
[root@node2 ~]$ll /data/              #这里注意,不需要手动创建数据目录
total 0

安装依赖包

[root@node2 ~]$yum -y 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@node2 ~]$tar xf mariadb-10.2.25.tar.gz -C /usr/local/src
[root@node2 ~]$cd /usr/local/src
[root@node2 src]$cd mariadb-10.2.25/

[root@node2 mariadb-10.2.25]$cmake . \
> -DCMAKE_INSTALL_PREFIX=/apps/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
...

准备环境变量

[root@node2 mariadb-10.2.25]$echo "PATH=/apps/mysql/bin:$PATH" > /etc/profile.d/mysql.sh
[root@node2 mariadb-10.2.25]$. /etc/profile.d/mysql.sh

生成数据库文件

[root@node2 mysql]$./scripts/mysql_install_db --datadir=/data/mysql --user=mysql

准备配置文件

[root@node2 mysql]$cp support-files/my-huge.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y
[root@node2 mysql]$vim /etc/my.cnf
[mysqld]                            #添加以下三项即可
datadir = /data/mysql
innodb_file_per_table = on
skip_name_resolve = on

准备服务脚本,启动服务,并设置开机自启

[root@node2 mysql]$cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@node2 mysql]$chkconfig --add mysqld
[root@node2 mysql]$chkconfig --list mysqld

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@node2 mysql]$service mysqld start 
Starting mysqld (via systemctl):                           [  OK  ]
[root@node2 mysql]$ss -tnl
State       Recv-Q Send-Q      Local Address:Port                     Peer Address:Port              
LISTEN      0      100             127.0.0.1:25                                  *:*                  
LISTEN      0      128                     *:22                                  *:*                  
LISTEN      0      100                 [::1]:25                               [::]:*                  
LISTEN      0      80                   [::]:3306                             [::]:*                  
LISTEN      0      128                  [::]:22                               [::]:* 

安全初始化,密码是:123.com

[root@node2 mysql]$mysql_secure_installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] 
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] 
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] 
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] 
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

测试登录

[root@node2 mysql]$mysql -uroot -p123.com
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 18
Server version: 10.2.25-MariaDB-log 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)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> exit
Bye

安装wordpress
先清除之前放在/data/www/html/目录下的测试文件

[root@node1 ~]$rm -rf /data/www/html/index.*

解压,并放在/data/www/html目录下

[root@node1 ~]$tar xf wordpress-5.0.3-zh_CN.tar.gz -C /data/
[root@node1 ~]$mv /data/wordpress/* /data/www/html/
[root@node1 ~]$ls /data/www/html/
index.php        wp-admin              wp-content         wp-load.php      wp-signup.php
license.txt      wp-blog-header.php    wp-cron.php        wp-login.php     wp-trackback.php
readme.html      wp-comments-post.php  wp-includes        wp-mail.php      xmlrpc.php
wp-activate.php  wp-config-sample.php  wp-links-opml.php  wp-settings.php

配置wordpress

[root@node1 ~]$ll /data/www/html/
total 192
-rw-r--r--  1 1006 1006   418 Sep 25  2013 index.php
-rw-r--r--  1 1006 1006 19935 Jan  4  2019 license.txt
-rw-r--r--  1 1006 1006  6989 Jan 11  2019 readme.html
-rw-r--r--  1 1006 1006  6878 Dec 13  2018 wp-activate.php
drwxr-xr-x  9 1006 1006  4096 Jan 11  2019 wp-admin
-rw-r--r--  1 1006 1006   364 Dec 19  2015 wp-blog-header.php
-rw-r--r--  1 1006 1006  1889 May  3  2018 wp-comments-post.php
-rw-r--r--  1 1006 1006  2735 Jan 11  2019 wp-config-sample.php
drwxr-xr-x  5 1006 1006    69 Jan 11  2019 wp-content
-rw-r--r--  1 1006 1006  3669 Aug 20  2017 wp-cron.php
drwxr-xr-x 19 1006 1006  8192 Jan 11  2019 wp-includes
-rw-r--r--  1 1006 1006  2422 Nov 21  2016 wp-links-opml.php
-rw-r--r--  1 1006 1006  3306 Aug 22  2017 wp-load.php
-rw-r--r--  1 1006 1006 37296 Dec 13  2018 wp-login.php
-rw-r--r--  1 1006 1006  8048 Jan 11  2017 wp-mail.php
-rw-r--r--  1 1006 1006 17421 Oct 23  2018 wp-settings.php
-rw-r--r--  1 1006 1006 30091 Apr 30  2018 wp-signup.php
-rw-r--r--  1 1006 1006  4620 Oct 24  2017 wp-trackback.php
-rw-r--r--  1 1006 1006  3065 Sep  1  2016 xmlrpc.php

[root@node1 ~]$setfacl -R -m u:nginx:rwx /data/www/html/
[root@node1 ~]$ll /data/www/html/
total 192
-rw-rwxr--+  1 1006 1006   418 Sep 25  2013 index.php
-rw-rwxr--+  1 1006 1006 19935 Jan  4  2019 license.txt
-rw-rwxr--+  1 1006 1006  6989 Jan 11  2019 readme.html
-rw-rwxr--+  1 1006 1006  6878 Dec 13  2018 wp-activate.php
drwxrwxr-x+  9 1006 1006  4096 Jan 11  2019 wp-admin
-rw-rwxr--+  1 1006 1006   364 Dec 19  2015 wp-blog-header.php
-rw-rwxr--+  1 1006 1006  1889 May  3  2018 wp-comments-post.php
-rw-rwxr--+  1 1006 1006  2735 Jan 11  2019 wp-config-sample.php
drwxrwxr-x+  5 1006 1006    69 Jan 11  2019 wp-content
-rw-rwxr--+  1 1006 1006  3669 Aug 20  2017 wp-cron.php
drwxrwxr-x+ 19 1006 1006  8192 Jan 11  2019 wp-includes
-rw-rwxr--+  1 1006 1006  2422 Nov 21  2016 wp-links-opml.php
-rw-rwxr--+  1 1006 1006  3306 Aug 22  2017 wp-load.php
-rw-rwxr--+  1 1006 1006 37296 Dec 13  2018 wp-login.php
-rw-rwxr--+  1 1006 1006  8048 Jan 11  2017 wp-mail.php
-rw-rwxr--+  1 1006 1006 17421 Oct 23  2018 wp-settings.php
-rw-rwxr--+  1 1006 1006 30091 Apr 30  2018 wp-signup.php
-rw-rwxr--+  1 1006 1006  4620 Oct 24  2017 wp-trackback.php
-rw-rwxr--+  1 1006 1006  3065 Sep  1  2016 xmlrpc.php

[root@node1 ~]$cp  /data/www/html/wp-config-sample.php /data/www/html/wp-config.php
[root@node1 ~]$vim /data/www/html/wp-config.php
/** WordPress数据库的名称 */
define('DB_NAME', 'wordpress');

/** MySQL数据库用户名 */
define('DB_USER', 'wordpress');

/** MySQL数据库密码 */
define('DB_PASSWORD', '123.com');

/** MySQL主机 */
define('DB_HOST', '192.168.2.17');

配置mariadb,创建数据库和远程登录用户(node2)

[root@node2 mysql]$mysql -uroot -p123.com
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 19
Server version: 10.2.25-MariaDB-log 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)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| wordpress          |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> grant all on wordpress.* to 'wordpress'@'192.168.2.%' identified by '123.com';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> quit
Bye

[root@node2 mysql]$mysql -uwordpress -p123.com -h192.168.2.17
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 20
Server version: 10.2.25-MariaDB-log 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)]> quit
Bye

实现多虚拟主机

[root@node1 ~]$vim /apps/nginx/conf.d/vhosts.conf 
[root@node1 ~]$cat /apps/nginx/conf.d/vhosts.conf
charset utf-8;
server {
    listen 80;
    server_name www.x.com;

    location / {
        root /data/www/html;
        index index.php index.html index.htm;
    }

    location ~* \.php$ {
        root /data/www/html;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
server {
    listen 80;
    server_name admin.x.com;

    location / {
        root /data/www/html;
        index wp-login.php index.html index.htm;
    }

    location ~* \.php$ {
        root /data/www/html;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

修改windows的hosts

192.168.2.7  www.x.com admin.x.com

源码编译安装LNMP+wordpress
源码编译安装LNMP+wordpress
源码编译安装LNMP+wordpress
源码编译安装LNMP+wordpress
源码编译安装LNMP+wordpress
源码编译安装LNMP+wordpress
源码编译安装LNMP+wordpress

猜你喜欢

转载自blog.51cto.com/14812296/2563446