- 安装 LNMP 平台相关软件
- 配置 Nginx 实现动静分离
- 配置数据库,创建账户与密码
- 上线 Wordpress 代码
- 使用 Wordpress 后台管理界面,调整 Wordpress 版式
备注:mariadb(数据库客户端软件)、mariadb-server(数据库服务器软件)、mariadb-devel(其他客户端软件的依赖包)、php(解释器)、php-fpm(进程管理器服务)、php-mysql(PHP 的数据库扩展包)。
1 . 首先安装编译器及依赖包
[root@lnmp ~]# yum -y install gcc openssl-devel pcre-devel
2 . 解压nginx包和网站模板
[root@lnmp lnmp]# tar -xf nginx-1.12.2.tar.gz
[root@lnmp lnmp]# cd nginx-1.12.2/
[root@lnmp nginx-1.12.2]# ls
auto CHANGES.ru configure html man src
CHANGES conf contrib LICENSE README
[root@lnmp nginx-1.12.2]# ./configure --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module
[root@lnmp nginx-1.12.2]# make && make install
3 . 安装数据库包和网站php包及依赖
[root@lnmp nginx-1.12.2]# yum -y install mariadb mariadb-server mariadb-devel php php-fpm php-mysql
4 . 启动nginx并修改配置,实现动静分离
[root@lnmp nginx-1.12.2]# /usr/local/nginx/sbin/nginx
nginx: [emerg] getpwnam(“nginx”) failed
- 出现报错,因为没有创建nginx用户
[root@lnmp nginx-1.12.2]# useradd -s /sbin/nologin nginx
[root@lnmp nginx-1.12.2]# /usr/local/nginx/sbin/nginx
[root@lnmp nginx-1.12.2]# echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local
[root@lnmp nginx-1.12.2]# chmod +x /etc/rc.local
[root@lnmp nginx-1.12.2]# ss -nutlp | grep nginx
[root@lnmp nginx-1.12.2]# vim /usr/local/nginx/conf/nginx.conf
…省略部分配置文件内容…
location / {
root html;
index index.php index.html index.htm;
}
…省略部分配置文件内容…
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
…省略部分配置文件内容…
/usr/local/nginx/sbin/nginx -s reload #重新加载配置
5 .启动数据库及网页php服务
[root@lnmp nginx-1.12.2]# systemctl start mariadb && systemctl enable mariadb
[root@lnmp nginx-1.12.2]# systemctl start php-fpm && systemctl enable php-fpm
6 .登录数据库,创建创建数据库及授权
[root@lnmp nginx-1.12.2]# mysql
MariaDB [(none)]> create database wordpress character set utf8mb4;
MariaDB [(none)]> grant all on wordpress.* to wordpress@localhost identified by "wordpress";
MariaDB [(none)]> grant all on wordpress.* to wordpress@192.168.1.20 identified by "wordpress";
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> show grants for wordpress@localhost;
MariaDB [(none)]> show grants for wordpress@192.168.1.20;
MariaDB [(none)]> exit
7 . 部署模板网页内容
[root@lnmp lnmp]# yum -y install unzip
[root@lnmp lnmp]# unzip wordpress.zip
[root@lnmp lnmp]# cd wordpress/
[root@lnmp wordpress]# ls
futurio.1.2.11.zip hestia.2.4.2.zip twentyfourteen.2.6.zip
generatepress.2.2.2.zip shop-isle.1.1.52.zip wordpress-5.0.3-zh_CN.tar.gz
[root@lnmp wordpress]# tar -xf wordpress-5.0.3-zh_CN.tar.gz
[root@lnmp wordpress]# ls
futurio.1.2.11.zip shop-isle.1.1.52.zip wordpress-5.0.3-zh_CN.tar.gz
generatepress.2.2.2.zip twentyfourteen.2.6.zip
hestia.2.4.2.zip wordpress
[root@lnmp wordpress]# cp -r wordpress/* /usr/local/nginx/html/
[root@lnmp wordpress]# chown -R apache.apache /usr/local/nginx/html/
[root@lnmp wordpress]# ll -ls /usr/local/nginx/html/
[root@lnmp wordpress]# curl 192.168.1.20
其他有关 wordpress 的使用方法与技巧,可以参考官方网站的文档资料,文档链接:
https://codex.wordpress.org/zh-cn:Main_Page。
附加知识:systemd!!!
源码安装的软件默认无法使用 systemd 管理,如果需要使用 systemd 管理源码安装
的软件需要手动编写服务的 service 文件(编写是可以参考其他服务的模板文件)。
以下是 nginx 服务最终编辑好的模板。
Service 文件存储路径为/usr/lib/system/system/目录。
[root@lnmp~]# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=The Nginx HTTP Server
#描述信息
After=network.target remote-fs.target nss-lookup.target
#指定启动nginx之前需要其他的其他服务,如network.target等
[Service]
Type=forking
#Type为服务的类型,仅启动一个主进程的服务为simple,需要启动若干子进程的服务为
forking
ExecStart=/usr/local/nginx/sbin/nginx
#设置执行systemctl start nginx后需要启动的具体命令.
ExecReload=/usr/local/nginx/sbin/nginx -s reload
#设置执行systemctl reload nginx后需要执行的具体命令.
ExecStop=/bin/kill -s QUIT ${MAINPID}
#设置执行systemctl stop nginx后需要执行的具体命令.
[Install]