一、安装nginx
通过命令安装
yum -y install nginx
配置笔记:
server { listen 80; server_name **.cn; root /data/nginx/html/wordpress-enjoytoday; index index.php; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 6; gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml; gzip_vary on; gzip_proxied expired no-cache no-store private auth; gzip_disable "MSIE [1-6]\."; location / { try_files $uri $uri/ /index.php?$args ; } location ~ /favicon.ico { access_log off; log_not_found off; } location ~ \.php$ { try_files $uri /index.php; include fastcgi_params; fastcgi_pass unix:/var/run/php/php7.3-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } access_log /var/log/nginx/$host-access.log; error_log /var/log/nginx/wpms-error.log; }
启动命令
$nginx -t $/etc/init.d/nginx
二、安装Mariadb(mysql)
同样还是利用yum命令进行安装,并且配置开机启动
yum -y install mariadb-server mariadb #安装命令 systemctl start mariadb.service # 开启 systemctl enable mariadb.service # 设置开机启动
下面配置root密码:
mysql_secure_installation
大致过程如下,按需配置即可,我这测试全选的N,最后Y重载
Enter current password for root (enter for none):(输入原始root密码,若无enter) OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] (是否设置root密码) New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! Remove anonymous users? [Y/n] (是否移除匿名用户) ... Success! Disallow root login remotely? [Y/n] (是否禁止远程root登陆) ... skipping. Remove test database and access to it? [Y/n] (是否删除测试数据库) Reload privilege tables now? [Y/n] (重新载入) ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
三、安装PHP
- 安装PHP
$ yum -y install php
查看所有组件
$ yum search php
- 安装需要的一些组件
$ yum -y install php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel
完成。
我们可以新建一个PHP页面查看安装的组件
$ vi /var/www/html/info.php
编辑为以下内容
<?php phpinfo(); ?>
重启nginx服务
$ nginx -s reload
四、配置WordPress数据库
首先登陆MariaDB为WordPress建立数据库及用户
$ mysql -u root -p
这里进入了MariaDB,按行执行下面代码:
CREATE DATABASE wordpressdb //新建的数据库为wordpressdb CREATE USER wordpressuser@localhost IDENTIFIED BY '123456' //用户为wordpressuser,密码为123456 GRANT ALL PRIVILEGES ON wordpressdb.* TO wordpressuser@localhost FLUSH PRIVILEGES //更改用户权限 exit //保存并退出
重启相关服务
$ nginx -s reload $ systemctl restart mariadb.service
五、安装WordPress
下载WordPress
$ cd /home/www/demo $ yum -y install wget unzip net-tools $ wget http://wordpress.org/latest.zip
解压文件,并且将其复制到/home/www/wordpress目录下
$ unzip -q latest.zip $ cp -rf wordpress/* /home/www/wordpress
上面你也可以用windows下载好再传到服务器解压,我就是这样直接解压wordpress文件夹到wordpress目录。
修改文件夹权限
$ chown -R nginx:nginx /home/www/wordpress
编辑配置文件
$ cd /home/www/demo/wordpress // 假定你wordpress解压到当前目录 $ cp wp-config-sample.php wp-config.php $ vi wp-config.php
往下找到需要修改的内容,修改三个部分:其中wordpressdb为数据库名称,wordpressuser为数据库用户名,123456为数据库密码
/** WordPress数据库的名称 */ define('DB_NAME', 'wordpressdb'); /** MySQL数据库用户名 */ define('DB_USER', 'wordpressuser'); /** MySQL数据库密码 */ define('DB_PASSWORD', '123456');
保存后退出,重启相关服务
$ nginx -s relaod $ systemctl restart mariadb.service
如此,就完成了wordpress的安装