1 环镜准备
两台CentOS7 主机
一台提供LNP
一台提供MySQL
都禁用SELinux和防火墙
准备相关安装包
nginx-1.16.1.tar.gz
mysql-5.7.29-el7-x86_64.tar.gz
php-7.4.1.tar.xz
wordpress-5.4.1-zh_CN.tar.gz
2 二进制安装 MySQL 5.7
#第一台主机上实现MySQL
[root@centos7 ~]#tar xf mysql-5.7.29-el7-x86_64.tar.gz -C /usr/local/
[root@centos7 ~]#ln -s /usr/local/mysql-5.7.29-el7-x86_64 /usr/local/mysql
[root@centos7 ~]#chown -R root.root /usr/local/mysql/
[root@centos7 ~]#useradd -s /sbin/nologin -r mysql
[root@centos7 ~]#yum -y -q install numactl-libs libaio
[root@centos7 ~]#echo 'PATH=/usr/local/mysql/bin/:$PATH' > /etc/ profile .d/mysql.sh
[root@centos7 ~]#. /etc/profile.d/mysql.sh
[root@centos7 ~]#cat > /etc/my.cnf <<-EOF
[mysqld]
server-id=1
log-bin
datadir=/data/mysql
socket =/data/mysql/mysql.sock
skip_name_resolve = ON
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
socket=/data/mysql/mysql.sock
EOF
[root@centos7 ~]#mysqld --initialize --user=mysql --datadir=/data/mysql
[root@centos7 ~]#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@centos7 ~]#chkconfig --add mysqld
[root@centos7 ~]#chkconfig mysqld on
[root@centos7 ~]#service mysqld start
#查看并修改root密码
[root@centos7 ~]#MYSQL_OLDPASSWORD=`awk '/A temporary password/{print $NF}' /data/mysql/mysql.log`
[root@centos7 ~]#mysqladmin -uroot -p$MYSQL_OLDPASSWORD password magedu
[root@centos7 ~]#mysql -uroot -pmagedu
mysql> create database wordpress;
mysql> grant all on wordpress.* to wordpress@'10.0.0.%' identified by "magedu";
3 编译安装 nginx
#在第二台主机上实现nginx
[root@centos7 ~]#useradd -s /sbin/nologin -r nginx
[root@centos7 ~]#yum -q -y install gcc pcre-devel openssl-devel zlib-devel perl-ExtUtils-Embed
[root@centos7 ~]#tar xf nginx-1.16.1.tar.gz -C /usr/local/src
[root@centos7 ~]#cd /usr/local/src/nginx-1.16.1/
[root@centos7 nginx-1.16.1]#./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-http_perl_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module
[root@centos7 nginx-1.16.1]#make -j 2 && make install
[root@centos7 nginx-1.16.1]#cd && mkdir -pv /data/www/
[root@centos7 ~]#cat > /apps/nginx/conf/nginx.conf <<EOF
worker_processes auto;
events {
worker_connections 10240;
}
http {
include mime.types;
default_type application/octet-stream;
server_tokens off;
log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" '
sendfile on;
client_max_body_size 100m;
keepalive_timeout 65;
server {
listen 80 default_server;
server_name localhost ;
root /data/www ;
access_log logs/nginx.access.log main;
location / {
root /data/www/;
index index.php index. html index.htm;
}
error_page 500 502 503 504 / 50x .html;
location = /50x.html {
root html;
}
location ~ \.php$ {
root /data/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www\$fastcgi_script_name;
include fastcgi_params;
}
}
}
EOF
[root@centos7 ~]#echo 'PATH=/apps/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@centos7 ~]#. /etc/profile.d/nginx.sh
[root@centos7 ~]#cat > /usr/lib/ systemd /system/nginx. service <<EOF
[Unit]
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/apps/nginx/sbin/nginx
ExecReload=/apps/nginx/sbin/nginx -s reload
ExecStop=/apps/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target
EOF
[root@centos7 ~]#systemctl daemon-reload
[root@centos7 ~]#systemctl enable --now nginx
4 编译安装 fastcgi 方式的 php 7.4
#在第二台主机上实现php
[root@centos7 ~]#yum -y -q install gcc make libxml2-devel bzip2-devel libmcrypt-devel libsqlite3x-devel oniguruma-devel
[root@centos7 ~]#tar xvf php-7.4.1.tar.xz -C /usr/local/src/
[root@centos7 ~]#cd /usr/local/src/php-7.4.1/
[root@centos7 php-7.4.1]#./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
[root@centos7 php-7.4.1]#make -j 4 && make install
[root@centos7 php-7.4.1]#cp php.ini-production /etc/php.ini
[root@centos7 php-7.4.1]#mkdir /etc/php.d/
[root@centos7 php-7.4.1]#cat > /etc/php.d/ opcache .ini <<EOF
[opcache]
zend_extension=opcache.so
opcache.enable=1
EOF
[root@centos7 php-7.4.1]#cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
[root@centos7 php-7.4.1]#cd /apps/php74/etc
[root@centos7 etc]#cp php-fpm.conf.default php-fpm.conf
[root@centos7 php-fpm.d]#cd php-fpm.d/
[root@centos7 php-fpm.d]#cp www.conf.default www.conf
[root@centos7 php-fpm.d]#sed -i.bak -e 's/^user.*/user = nginx/' -e 's/^ group .*/group = nginx/' /apps/php74/etc/php-fpm.d/www.conf
[root@centos7 ~]#systemctl daemon-reload
[root@centos7 ~]#systemctl enable --now php-fpm
#配置PATH变量
[root@centos7 ~]#echo 'PATH=/apps/php74/bin:$PATH' > /etc/profile.d/php.sh
[root@centos7 ~]#. /etc/profile.d/php.sh
[root@centos7 ~]#php --version
PHP 7.4.1 (cli) (built: May 10 2020 15:41:54) ( ZTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.1, Copyright (c), by Zend Technologies
#确保相应的端口已打开
[root@centos7 ~]#ss -ntl
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 [::]:*
5 准备 wordpress 文件
#在第二台主机上实现wordpress
[root@centos7 ~]#tar xvf wordpress-5.4.1-zh_CN.tar.gz
[root@centos7 ~]#mv wordpress/* /data/www/
[root@centos7 ~]#chown -R nginx.nginx /data/www
6 测试访问
#打开浏览器访问第二台主机
服务器/