1、编译安装LNMP,并安装wordpress
192.168.2.240 mysql
192.168.2.241 nginx+php
1)下所需的所有的软件包
wget http://nginx.org/download/nginx-1.16.1.tar.gz
wget https://www.php.net/distributions/php-7.4.3.tar.xz
wget https://github.com/WordPress/WordPress/archive/5.3.2.tar.gz
wget https://github.com/MariaDB/server/archive/mariadb-10.2.18.tar.gz
2)源码编译安装nginx
安装所需依赖包,创建nginx账号
yum install gcc pcre-devel openssl-devel zlib-devel -y
useradd -r -s /sbin/nologin nginx
tar xf nginx-1.16.1.tar.gz
cd nginx-1.16.1
./configure --prefix=/data/nginx --conf-path=/data/nginx/conf/nginx.conf --error-log-path=/data/nginx/logs/error.log --http-log-path=/data/nginx/logs/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 && make install
3)配置nginx的环境变量,启动nginx服务
ln -sv /data/nginx/sbin/nginx /usr/sbin/
systemctl start nginx
4)源码编译php
解压php源码包 tar xf php-7.3.15.tar.xz
安装编译所需依赖包
yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel libzip gcc-c++
执行编译并安装
./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-fpm启动脚本,并且添加执行权限设置为开机启动
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
启动服务,查看程序运行状态
systemctl start php-fpm
创建php页面,验证nginx解析php
vim /data/nginx/html/index.php
<?php
phpinfo();
?>
启动服务,查看程序运行状态
systemctl start php-fpm
5)源码编译mariadb
安装依赖包
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
做准备用户和数据目录
useradd –r –s /sbin/nologin –d /data/mysql/ mysql
mkdir /data/mysql
chown mysql.mysql /data/mysql
tar xvf mariadb-10.2.18.tar.gz
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 && makeinstall
生成mysql环境变量
echo 'PATH=/app/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh
生成数据库文件
cd /app/mysql/
scripts/mysql_install_db --basedir=/app/mysql --datadir=/data/mysql/ --user=mysql
复制mysql配置文件
cp /app/mysql/support-files/my-huge.cnf /etc/my.cnf
准备mysql启动脚本
cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld
启动mysql服务
chkconfig --add mysqld ;systemctl start mysqld
2、配置虚拟主机,www.x.com域名实现首页访问,admin.x.com域名实现wordpress的后台访问。
基于已安装好的lnmp架构部署wordpress
登录数据创建wordpress库和授权账户
create database wordpress;
grant all on wordpress.* to 'wordpress'@'192.168.2.%' identified by 'wordpress';
flush privileges;
下载软件包,并解压到nginx网站的根目录
将WordPress程序解压到httpd网站根目录,重名了为wordpress,设置acl权限为nginx账户具有读写执行的权限
tar xf 5.3.2.tar.gz -C /data/nginx/html/
cd /data/nginx/html/
mv WordPress-5.3.2/ wordpress
setfacl -Rm u:nginx:rwx wordpress/
修改wordpress配置文件
/data/nginx/html/wordpress
cp wp-config-sample.php wp-config.php
define( 'DB_NAME', 'wordpress' );
/** MySQL database username */
define( 'DB_USER', 'wordpress' );
/** MySQL database password */
define( 'DB_PASSWORD', 'wordpress' );
/** MySQL hostname */
define( 'DB_HOST', '192.168.2.241' );
2)安装wordpress
3)修改nginx配置文件
www.blog.com域名实现首页访问
server {
listen 80;
server_name www.blog.com;
access_log /data/wwwlogs/access_nginx.log combined;
root /data/wwwroot/default;
location /wordpress {
index index.php index.html index.htm;
}
location ~ [^/]\.php(/|$) {
#fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
}
admin.blog.com域名实现wordpress的后台访问
server {
listen 80;
server_name admin.blog.com;
access_log /data/wwwlogs/admin_blog.log combined;
root /data/wwwroot/default;
location /wordpress/wp-admin {
index index.php index.html index.htm;
rewrite ^/wordpress/wp-admin/(.*)$ /wordpress/wp-login.php last;
}
location ~ [^/]\.php(/|$) {
#fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
}
3、配置nginx反向代理,实现api.x.com域名代理本地9001端口
server {
listen 80;
server_name api.blog.com;
access_log /data/wwwlogs/api_blog.log combined;
root /data/wwwroot/default;
location /api {
proxy_pass http://127.0.0.1:9001;
}
}