公众号:张小飞那些事儿
Ubuntu18配置wordpress服务器 (nginx + wordpress + mariadb)
三年前买的腾讯云的学生机马上过期,所以趁着这个机会赶紧玩玩,搜了下大家都是用apache来起的服务。(我原来也是)
nginx又比较轻量,所以趁着这个机会把服务器清了,重新用nginx又重新配置了下wordpress。特意来记录(水)下。
Ubuntu18默认源php版本就是7.2
安装软件
- nginx
- mariadb
- php
Ubuntu18默认源php版本就是7.2
sudo apt-get update
sudo apt-get install nginx
sudo apt-get install mariadb-server
sudo systemctl enable mariadb.service
apt-get install php7.2 php7.2-cli php7.2-fpm php7.2-mysql php7.2-json php7.2-opcache php7.2-mbstring php7.2-xml php7.2-gd php7.2-curl
数据库操作
创建一个wordpress的数据库,用户为wordpress ,密码为wordpress
mysql -u root -p
create database wordpress; //创建wordpress数据库
create user wordpress@localhost identified by 'wordpress'; //创建用户wordpress 密码也是wordpress
GRANT ALL ON *.* TO 'wordpress'@'localhost';
FLUSH PRIVILEGES;
exit;
配置nginx
绑定了我的二级域名 http://blog.cryfeifei.cn wordpress地址放到这里 /var/www/html/wordpress
cd /etc/nginx/sites-available
sudo vim wordpress.conf
添加如下代码,端口放开到80,绑定域名http://blog.cryfeifei.cn。 指定root地址
server {
listen 80;
root /var/www/html/wordpress;
index index.php index.html;
server_name blog.cryfeifei.cn;
access_log /var/log/nginx/SUBDOMAIN.access.log;
error_log /var/log/nginx/SUBDOMAIN.error.log;
location / {
try_files $uri $uri/ =404;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
location ~ /.ht {
deny all;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~* .(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
创建完这个文件后给个软链
sudo nginx -t
cd /etc/nginx/sites-enabled
sudo ln -s ../sites-available/wordpress.conf ./
配置nginx
把wordpress zip文件解压到 目录/var/www/html/wordpress
一定要做的 www-data权限是nginx默认的用户组。需要给对应目录权限。否则下载插件也下载不下来
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html/*
最后改一下wordpress的 config;
# cd /var/www/html/wordpress/public_html
# mv wp-config-sample.php wp-config.php
# vi wp-config.php
define('DB_NAME', 'wordpress');
define('DB_USER', 'wordpress');
define('DB_PASSWORD', 'wordpress');
最后别忘了
sudo systemctl restart nginx
最后就可以用wordpress起个服务了。