环境准备
本系统将基于LNMP进行搭建,LNMP系统搭建准备请参考博主另外两篇文章
https://blog.csdn.net/gao36951/article/details/73321345
https://blog.csdn.net/gao36951/article/details/89702602
环境版本信息
- linux 版本
- nginx 版本
- mysql版本
- php版本
- WordPress版本
Tips:
本来php和WordPress打算用最新的版本的,到最后一直报mysql依赖未安装,安装网上的方式,各种都试了不行。而且PHP直接连写代码连mysql用下面的两种方式都不行,后来不得不退而求其次,选了低一点的版本。
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
?>
<?php
$con = mysqli_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysqli_error());
}
?>
开始安装
这里简单说一下在安装php5.6时候遇到的问题
./configure --prefix=/usr/local/php5.6 --with-mysql=mysqlnd \
--with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-fpm \
--enable-sockets --enable-sysvshm --enable-mbstring --with-freetype-dir --with-jpeg-dir \
--with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-mhash \
--with-mcrypt=/usr/local/libmcrypt --with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts
报错
checking for mcrypt support... yes
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决方案
yum install -y libmcrypt-devel
安装WordPress
到这里去下载对应版本的 tar.gz 包https://cn.wordpress.org/download/releases/
本例子为5.0版本。
在linux里面直接下载可以先找到对应包的下载路径使用下面命令下载,注意要下载到非用户主目录下,以避免不需要的麻烦。
wget https://cn.wordpress.org/wordpress-5.0-zh_CN.tar.gz
本示例安装路径为/project/wordpress
- 首先切换到此目录
cd /project/wordpress
wget https://cn.wordpress.org/wordpress-5.0-zh_CN.tar.gz
- 解压安装包
tar -zxvf wordpress-5.0-zh_CN.tar.gz
- 将wordpress授权nginx
chown -R nginx:nginx ./wordpress
- 配置nginx,可以从网上找一个favicon.ico放到/project/wordpress/wordpress目录下
server {
listen 80;
server_name localhost;
include /etc/nginx/default.d/*.conf;
location / {
root /project/wordpress/wordpress;
index index.php;
}
location /favicon.ico {
root /project/wordpress/wordpress;
}
location ~ \.php$ {
root /project/wordpress/wordpress;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
- 配置好重启nginx
nginx -s reload
然后浏览器直接输入你的域名(需要nginx配置)IP地址,如下图所示说明WordPress成功,后续可以自己随意发挥了~
参考
https://www.cnblogs.com/smyhvae/p/4965163.html
https://blog.csdn.net/qq_29058883/article/details/78106514
https://blog.51cto.com/xpleaf/1903115
https://www.jianshu.com/p/68f852b922b5