搭建LNMP环境
是什么?
LNMP = linux + nginx + mysql + php-fpm。
怎么安装?
nginx
sudo apt-get install nginx
mysql
sudo apt-get install mysql-server
php-fpm
sudo apt-get install php-fpm php-mysql
sudo apt-get install php-gd php-curl
搭建WordPress
配置mysql
Wordpress中需要使用到数据库,我们使用mysql来做wordpress的数据库。
mysql -u root -p
CREATE DATABASE wordpress;
CREATE USER user@localhost IDENTIFIED BY "Password";
GRANT ALL PRIVILEGES ON wordpress.* TO user@localhost IDENTIFIED BY'Password';
FLUSH PRIVILEGES;
exit;
配置nginx
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
配置php-fmp
主要需配置的是/etc/php/7.0/fpm/pool.d/www.conf中的listen字段。listen字段的内容要和nginx配置中fastcgi_pass一致,nginx才能和php-fpm沟通成功。
listen = /var/run/php/php7.0-fpm.sock
安装WordPress
下载WordPress可以到下载。
安装WordPress可以到安装。
我这里直接使用wget下载。
wget https://cn.wordpress.org/wordpress-5.0.4-zh_CN.tar.gz
配置WordPress
/**修改 WordPress 数据库配置*/
$ cd /var/www/html/wordpress/
$ cp wp-config-sample.php wp-config.php
$ sudo vi wp-config.php
/** WordPress数据库的名称 */
define( 'DB_NAME', 'wordpress' );
/** MySQL数据库用户名 */
define( 'DB_USER', 'user' );
/** MySQL数据库密码 */
# 将 Password 替换为前面配置数据的密码
define( 'DB_PASSWORD', 'Password' );
并在最后面添加 WordPress 进行更新时免登录的配置
/**修改WordPress工作目录的权限*/
define("FS_METHOD", "direct");
define("FS_CHMOD_DIR", 0777);
define("FS_CHMOD_FILE", 0777);
到这里WordPress就已经安装程序,可以从浏览器上访问"Ip:80",开始配置自己的WordPress站点。
其他参考网址
nginx配置参考
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;
#SSL 访问端口号为 443
listen 443 ssl default_server;
#填写绑定证书的域名
server_name www.xxx;
#证书文件名称
ssl_certificate 1_www.xxx.crt;
#私钥文件名称
ssl_certificate_key 2_www.xxx.key;
ssl_session_timeout 5m;
#请按照以下协议配置
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
#请按照以下套件配置,配置加密套件,写法遵循 openssl 标准。
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /usr/share/nginx/html/wordpress;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
WordPress更新或安装插件失败的解决方案
方法一:
如果不是自己编译的LAMP环境,那么网站的根目录都会是/var/www/,那么把wprdpress解压到此目录后,执行
$ cd /var/www/html/
# 将 wp 替换为你的用户名,www-data是服务器的默认组
$ sudo chown -R wp:www-data wordpress
# 修改读写属性
$ sudo chmod 777 -R wordpress
这样就完全解决问题了.注意了,不需要把/var/www/目录的所有者也设置为www-data,而只需要设置wordpress文件夹的所有者.
方法二:
wp-config.php里加入下面代码:
define(“FS_METHOD”, “direct”);
define(“FS_CHMOD_DIR”, 0777);
define(“FS_CHMOD_FILE”, 0777);
这个方法的原理也是和方法一的一样,它是直接在上传的时候把权限修改了,而方法一是在任何时候都拥有上传文件的权限。
方法三:
把apache2的运行用户改为你的当前用户
方法四:
把你的当前用户添加到www-data用户组