Nginx专题:LNMP之WordPress部署

本文涉及的产品
RDS MySQL DuckDB 分析主实例,基础系列 4核8GB
RDS AI 助手,专业版
RDS MySQL DuckDB 分析主实例,集群系列 4核8GB
简介: Nginx专题:LNMP之WordPress部署

实验环境

实验环境:

[root@lnmp ~]# uname -r
2.6.32-754.el6.x86_64
[root@lnmp ~]# cat /etc/redhat-release 
CentOS release 6.10 (Final)
[root@lnmp ~]# cat /etc/hosts
192.168.1.30 lnmp
172.16.1.30 lnmp

软件版本:

NGINX:nginx-1.12.2.tar.gz
MYSQL:mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz
PHP:php-5.5.3.tar.gz
libiconv:libiconv-1.16.tar.gz
wordpress:wordpress-4.7.3-zh_CN.tar.gz

安装Nginx服务

Nginx服务部署过程:

请参考:Nginx服务部署过程

安装Mysql数据库

下载二进制MySQL包:

[root@lnmp tools]# wget -q https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.6/mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz

解压MySQL包:

[root@lnmp tools]# tar xf mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz -C /app/

创建MySQL用户及授权:

[root@lnmp tools]# cd /app/
[root@lnmp app]# ln -s mysql-5.6.47-linux-glibc2.12-x86_64/ /app/mysql
[root@lnmp tools]# useradd mysql -s /sbin/nologin -M
[root@lnmp mysql]# chown mysql.mysql /app/mysql/data/

初始化MySQL:

第一遍初始化报错,然后我把data目录下东西干掉后就好了。什么原理?

[root@lnmp mysql]# bin/mysqld --user=mysql --datadir=/app/mysql/data --basedir=/app/mysql

制作MySQL启动脚本:

[root@lnmp data]# cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld 
cp:是否覆盖"/etc/init.d/mysqld"? y
[root@lnmp mysql]# sed -ri 's#/usr/local#/app#g' /etc/init.d/mysqld /app/mysql/bin/mysqld_safe 

创建配置文件:

[root@lnmp mysql]# cp /app/mysql/support-files/my-default.cnf /etc/my.cnf 
cp:是否覆盖"/etc/my.cnf"? y

启动MySQL:

[root@lnmp mysql]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS! 
[root@lnmp mysql]# netstat -utpln | grep mysqld
tcp        0      0 :::3306                     :::*                        LISTEN      17796/mysqld      

设置环境变量:

[root@lnmp mysql]# echo 'export PATH=/app/mysql/bin:$PATH' >>/etc/profile
[root@lnmp mysql]# source /etc/profile

登录数据库:

因为初始密码为空,所以登录后要修改密码

[root@lnmp mysql]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.47 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> 
[root@lnmp mysql]# mysqladmin -u root password '123123'
Warning: Using a password on the command line interface can be insecure.
[root@lnmp mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.47 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> 

安装PHP

下载PHP包及liblconv包:

[root@lnmp ~]# cd /server/tools/
[root@lnmp tools]# wget https://museum.php.net/php5/php-5.5.3.tar.gz
[root@lnmp tools]# wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz

安装依赖包:

[root@lnmp tools]# yum -y install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel
[root@lnmp tools]# yum -y install libiconv-devel freetype-devel libpng-devel gd-devel
[root@lnmp tools]# yum -y install libcurl-devel libxslt-devel
[root@lnmp tools]# yum -y install libmcrypt-devel mhash mcrypt

编译安装语言转换工具:

[root@lnmp tools]# tar xf libiconv-1.16.tar.gz 
[root@lnmp tools]# cd libiconv-1.16
[root@lnmp libiconv-1.16]# ./configure --prefix=/usr/local/libiconv
[root@lnmp libiconv-1.16]# make && make install

解压PHP包进行预编译:

[root@lnmp libiconv-1.16]# cd /server/tools/
[root@lnmp tools]# tar xf php-5.5.3.tar.gz 
[root@lnmp tools]# cd php-5.5.3
[root@lnmp php-5.5.3]# mkdir -p /app/php-5.5.3
[root@lnmp php-5.5.3]# ./configure --prefix=/app/php-5.5.3 --with-mysql --with-pdo-mysql=mysqlnd --with-iconv-dir=/usr/local/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --enable-short-tags --enable-static --with-xsl --with-fpm-user=www --with-fpm-group=www --enable-ftp --enable-opcache=no
[root@lnmp php-5.5.3]# echo $?
0

防报错处理:

[root@lnmp php-5.5.3]# ln -s /app/mysql/lib/libmysqlclient.so.18 /usr/lib64/
[root@lnmp php-5.5.3]# touch ext/phar/phar.phar

编译安装PHP:

[root@lnmp php-5.5.3]# make && make install
[root@lnmp php-5.5.3]# echo $?
0
[root@lnmp php-5.5.3]# cp php.ini-production /app/php-5.5.3/lib/
[root@lnmp php-5.5.3]# ln -s /app/php-5.5.3/ /app/php
[root@lnmp php-5.5.3]# cd /app/php/etc/
[root@lnmp etc]# ll
总用量 28
-rw-r--r-- 1 root root  1152 8月  25 06:39 pear.conf
-rw-r--r-- 1 root root 21846 8月  25 06:39 php-fpm.conf.default
[root@lnmp etc]# cp php-fpm.conf.default php-fpm.conf
[root@lnmp etc]# vim php-fpm.conf
listen = 172.16.1.30:9000

启动PHP:

[root@lnmp etc]# useradd -s /sbin/nologin -M www
[root@lnmp etc]# /app/php/sbin/php-fpm
[root@lnmp etc]# netstat -utpln | grep php
tcp        0      0 172.16.1.30:9000            0.0.0.0:*                   LISTEN      39741/php-fpm         

修改Nginx配置文件

[root@lnmp etc]# cd /app/nginx/conf/
[root@lnmp conf]# cp nginx.conf nginx.conf.bak
[root@lnmp conf]# grep -Ev "#|^$" nginx.conf.default >nginx.conf
[root@lnmp conf]# vim nginx.conf
[root@lnmp conf]# cat nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  192.168.1.30;
        location / {
            root   html/www;
            index  index.html index.htm index.php;
            location ~* .*\.(php|php5)?$ {
                   fastcgi_pass 172.16.1.30:9000;
                   fastcgi_index index.php;
                   include fastcgi.conf;
             }     
  } 
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
[root@lnmp conf]# /app/nginx/sbin/nginx -t
nginx: the configuration file /app/nginx-1.12.2//conf/nginx.conf syntax is ok
nginx: configuration file /app/nginx-1.12.2//conf/nginx.conf test is successful

重新启动Nginx服务:

[root@lnmp etc]# /app/nginx/sbin/nginx -s reload

测试:

[root@lnmp etc]# cd /app/nginx/html/
[root@lnmp html]# ls
50x.html  index.html
[root@lnmp html]# vim test_php.php
[root@lnmp html]# cat test_php.php 
<?php
phpinfo();
?>
网页访问:192.168.1.30/test_php.php出现php页面,代表正常

部署WordPress个人博客

下载安装包:

[root@lnmp tools]# wget https://cn.wordpress.org/wordpress-4.7.3-zh_CN.tar.gz
[root@lnmp tools]# tar xf wordpress-4.7.3-zh_CN.tar.gz

部署站点:

[root@lnmp tools]# mkdir -p /app/nginx/html/www
[root@lnmp tools]# mv wordpress/* /app/nginx/html/www
[root@lnmp tools]# chown -R www.www /app/nginx/html/www/

创建数据库信息:

[root@lnmp tools]# mysql -uroot -p123123
mysql> create database wordpress;
Query OK, 1 row affected (0.01 sec)
mysql> grant all on wordpress.* to 'wordpress'@'localhost' identified by '123123';
Query OK, 0 rows affected (0.04 sec)


登录网站配置网站:

http://ip/wp-admin

主机默认localhost。截错了

到这里基本就部署好了,里面的一些详细配置就不说了。。。

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
目录
相关文章
|
4月前
|
应用服务中间件 网络安全 nginx
手把手教你使用 Docker 部署 Nginx 教程
本文详解Nginx核心功能与Docker部署优势,涵盖镜像拉取、容器化部署(快速、挂载、Compose)、HTTPS配置及常见问题处理,助力高效搭建稳定Web服务。
1930 4
|
4月前
|
应用服务中间件 Linux nginx
在虚拟机Docker环境下部署Nginx的步骤。
以上就是在Docker环境下部署Nginx的步骤。需要注意,Docker和Nginix都有很多高级用法和细节需要掌握,以上只是一个基础入门级别的教程。如果你想要更深入地学习和使用它们,请参考官方文档或者其他专业书籍。
224 5
|
应用服务中间件 PHP nginx
今日小结通过aliyun的本地容器镜像部署我的nginx和php环境
简介: 本教程介绍如何基于 Dragonwell 的 Ubuntu 镜像创建一个运行 Nginx 的 Docker 容器。首先从阿里云容器镜像服务拉取基础镜像,然后编写 Dockerfile 确保 Nginx 作为主进程运行,并暴露 80 端口。最后,在包含 Dockerfile 的目录下构建自定义镜像并启动容器,确保 Nginx 在前台运行,避免容器启动后立即退出。通过 `docker build` 和 `docker run` 命令完成整个流程。
463 25
今日小结通过aliyun的本地容器镜像部署我的nginx和php环境
|
11月前
|
运维 数据可视化 关系型数据库
使用 Websoft9 运维面板部署和维护 WordPress 到底有多简单?
如何实现 WordPress 极速部署?Websoft9 通过应用商店一键安装与可视化运维管理,10 分钟完成零门槛上线。
384 1
|
弹性计算 运维 监控
快速部署 Nginx 社区版
Nginx是一个高性能的HTTP和反向代理服务器。Nginx在计算巢上提供了社区版服务,您无需自行配置云主机,即可在计算巢上快速部署Nginx服务、实现运维监控,从而方便地基于Nginx搭建您自己的应用。本文介绍使用如何通过计算巢快速部署Nginx社区版。
快速部署 Nginx 社区版
|
数据可视化 NoSQL 开发者
国内免费高效部署WordPress方案探索之Websoft9多应用托管实践
在数字化普及的当下,WordPress 成为众多开发者和企业的建站首选。然而国内缺乏高效免费的部署方案。本文对比主流平台后推荐 **Websoft9**:其具备一键部署、多应用托管、性能优越、技术体系完善等优势,支持 WordPress 与其他系统的集成,适配阿里云、华为云等主流平台,是当前最值得尝试的开源建站方案之一。
228 0
国内免费高效部署WordPress方案探索之Websoft9多应用托管实践
|
9月前
|
应用服务中间件 Linux 网络安全
技术指南:如何把docsify项目部署到基于CentOS系统的Nginx中。
总结 与其他部署方法相比,将docsify项目部署到基于CentOS系统的Nginx中比较简单。以上步骤应当帮助你在不花费太多时间的情况下,将你的项目顺利部署到Nginx中。迈出第一步,开始部署你的docsify项目吧!
395 14
|
11月前
|
关系型数据库 MySQL 应用服务中间件
Linux 手动安装快速部署 LNMP 环境实战
本文详细记录了在阿里云ECS上手动搭建LNMP环境的过程,系统选用Ubuntu 24.04。主要内容包括:1) 使用`apt`安装Nginx和MySQL,并更新软件源;2) 编译安装PHP 8.4.5,配置PHP-FPM及环境路径;3) 配置MySQL root用户密码;4) 调整Nginx支持PHP解析并测试整体环境。通过此过程,重现手动配置服务器的细节,帮助熟悉各组件的安装与协同工作。
785 23
|
10月前
|
缓存 安全 应用服务中间件
宝塔部署 WordPress 太繁琐 那就用 Websoft9 一键部署 WordPress
随着 WordPress 成为最受欢迎的建站平台之一,传统通过宝塔面板部署的方式因步骤繁琐、手动干预多而显得效率低下。本文介绍 Websoft9 一键部署方案,利用容器化技术快速搭建 WordPress,内置 Nginx、PHP-FPM、MariaDB 和 Redis,集成安全组件如 ModSecurity-WAF 和 Fail2ban,支持自动 SSL 和性能优化功能。相比宝塔面板,Websoft9 提供更简便、稳定且安全的部署体验,适合希望高效上线 WordPress 的用户。
|
应用服务中间件 PHP nginx
Docker-compose 编排lnmp(dockerfile) 完成Wordpress
通过使用Docker Compose,我们可以轻松编排LNMP环境并部署WordPress。本文详细介绍了各组件的Dockerfile和配置文件编写,并通过docker-compose.yml文件实现了整个环境的自动化部署。这种方法不仅简化了部署过程,还提高了环境的可移植性和一致性。希望本文能帮助你更好地理解和使用Docker Compose来管理和部署复杂的应用程序。
744 4