1. Environment introduction
The installation environment introduced in this article is the Centos7.5 virtual machine of Baidu Cloud BCC.
The download and installation address of all software is: /opt/workspace/The
software installation user is: root
2. Install Nginx
Note: Nginx uses the source code installation method
1. Install the dependent libraries required for Nginx source code compilation, and use yum to install
yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
2. Use the wget command to download the nginx source package
wget http://nginx.org/download/nginx-1.15.11.tar.gz
3. Unzip the file
tar -zxvf nginx-1.15.11.tar.gz
4. Configure Nginx, plus common modules
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module
5. Compile and install Nginx, the default installation location of centos: /usr/local/nginx
make
make install
3. Install Mysql
1. Download the rpm package of the mysql repo and install mysql using yum
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
2. Install the rpm package of the repo
rpm -ivh mysql-community-release-el7-5.noarch.rpm
3. View mysql and use yum to install mysql-server
yum repolist all | grep mysql
yum install mysql-server
4. Start the mysql service
systemctl start mysqld.service
5. Configure mysql
//使用root账户登录
mysql -u root
//设置root密码
set password for 'root'@'localhost' =password('新密码');
//开启mysql的远程连接,默认只允许localhost访问数据库:
grant all privileges on *.* to root@'%'identified by 'password';
//创建wordpree数据库
create database wordpress charset utf8;
//配置完成退出登录
exit
Fourth, install php
1. Install the rpm package of the php warehouse address
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
2. Install php7.2
yum install php72w php72w* -y
yum install php72w-common php72w-fpm php72w-opcache php72w-gd php72w-mysqlnd php72w-mbstring php72w-pecl-redis php72w-pecl-memcached php72w-devel
3. Check whether the php version number is 7.2
php -v
4. Start the php-fpm service
systemctl start php-fpm
5. Download and configure wordpress
1. Download and unzip the file
//切换目录至/opt/wordspace
cd /opt/workspace
//下载wordpress压缩包
wget https://cn.wordpress.org/latest-zh_CN.tar.gz
//使用list查看下载的wordpress包,此处下载的包为:wordpress-5.0.3-zh_CN.tar.gz
ls
//解压压缩包
tar -zxvf wordpress-5.0.3-zh_CN.tar.gz
2. Modify the wordpress configuration
//切换目录至wordpress配置文件所在目录
cd wordpress/
//拷贝一份配置文件
cp wp-config-sample.php wp-config.php
//使用vi打开文件
vi wp-config.php
//根据注释修改文件开始的数据库连接信息
//修改后保存
Six, configure nginx
1. Configure the ssl certificate, support https, the certificate can be downloaded from various cloud service providers, select nginx for certificate download, and upload it to the /usr/local/nginx/conf/ directory
2. Modify the nginx.conf file
cd /usr/local/nginx/conf/
The nginx file configuration is as follows:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream php {
server unix:/tmp/php-cgi.socket;
server 127.0.0.1:9000;
}
server {
listen 80;
server_name xxxxx;
return 301 https://$server_name$request_uri;
root /opt/workspace/wordpress;
index index.php index.html;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php index.php;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# HTTPS server
#
server {
listen 443 ssl;
server_name xxxxxx;
root /opt/workspace/wordpress;
index index.php index.html;
ssl_certificate 你的ssl证书文件.pem;
ssl_certificate_key 你的ssl证书文件.key;
ssl_session_cache shared:SSL:1m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location = /favicon.ico {
log_not_found off;
access_log off;
expires max;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
# This is cool because no php is touched for static content.
# include the "$is_args$args" so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
access_log off;
log_not_found off;
}
}
}
3. After modification, you need to start nginx
//切换目录至nginx运行目录
cd /usr/local/nginx/sbin
//启动nginx
./nginx
//如果已经启动,重新加载配置
./nginx -s reload
4. Whether the access server test is normal
7. Solve the problem that wordpress cannot upload pictures, and ftp is required to install plugins
1. Modify wp-content permissions
//切换到wordpress目录
cd /opt/workspace/wordpress/
//切换wp-content权限至777
chmod 777 wp-content
2. Log in to WordPress and upload a picture into the media library
3. View the users and groups of the created upload directory
//切换目录
cd /opt/workspace/wordpress/wp-content
//使用ll查看目录权限
4. According to the previous step, you can see that the user and user group of the uploads directory are both apache
5. Modify the user and user group of the wp-content directory
chown -R apache:apache wp-content