一. 配置实验yum源环境
创建/opt/目录下的centos文件夹,将镜像挂载至该文件夹下作为yum源
mkdir /opt/centos
mount -t iso9600 /dev/cdrom /opt/centos
上传lnmp-yum文件作为yum源
编写yum文件:
vi /etc/yum.repos.d/local.repo
[centos]
name=centos
baseurl=file:///opt/centos
gpgcheck=0
enabled=1
[lnmp]
name=lnmp
baseurl=file:///opt/lnmp-yum
gpgcheck=0
enabled=1
二.安装nginx、php、mariadb,并进行相关配置
安装nginx:
yum install nginx -y
systemctl start nginx
systemctl enable nginx
接着使用物理机访问nginx服务器地址,测试nginx是否正常工作,如果访问不正常则检查防火墙状态以及nginx端口等是否正常启动
安装数据库:
yum install mariadb mariadb-server -y
sysetmctl start mariadb
sysetmctl enable mariadb
初始化数据库:
mysql_secure_installation
安装php:
yum install php php-fpm php-mysql php-devel -y
systemctl start php
systemctl enable php
修改nginx文件,验证php是否正常解析php文件:
vi /etc/nginx/conf.d/default.conf
server {
listen 80;
1 server {
2 listen 80;
3 server_name localhost;
4
5 #charset koi8-r;
6 #access_log /var/log/nginx/host.access.log main;
7
8 location / {
9 root /usr/share/nginx/html;
10 index index.php index.html index.htm;
11 }
12
13 #error_page 404 /404.html;
14
15 # redirect server error pages to the static page /50x.html
16 #
17 error_page 500 502 503 504 /50x.html;
18 location = /50x.html {
19 root /usr/share/nginx/html;
20 }
21
22 # proxy the PHP scripts to Apache listening on 127.0.0.1:80
23 #
24 #location ~ \.php$ {
25 # proxy_pass http://127.0.0.1;
26 #}
27
28 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
29 #
30 location ~ \.php$ {
31 root /usr/share/nginx/html;
32 fastcgi_pass 127.0.0.1:9000;
33 fastcgi_index index.php;
34 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
35 include fastcgi_params;
36 }
37
38 # deny access to .htaccess files, if Apache's document root
39 # concurs with nginx's one
40 #
41 #location ~ /\.ht {
42 # deny all;
43 #}
注意观察:在第10行增加了 index.php,修改了30~36行部分内容
然后在/usr/share/nginx/html目录下新建一个index.php文件:
vi /usr/share/nginx/html/index.php
<?php
phpinfo();
?>
重启php服务器,在本地访问主机IP,出现php版本信息即为成功
安装wordpress
上传wordpress压缩包至/opt/目录下,然后解压缩(如果没有解压软件自行安装:yum install zip unzip -y)
unzip wordpress-4.7.3-zh_CN.zip
在/opt/目录下的wordpress目录下,将wp-config-sample.php复制一份,并将文件名修改为wp-config.php,然后修改该文件内容.
注意:只需要修改第23行、26行、29行内容
cp wp-config-sample.php wp-config.php
vi wp-config.php
......
22 /** WordPress数据库的名称 */
23 define('DB_NAME', 'wordpress');
24
25 /** MySQL数据库用户名 */
26 define('DB_USER', 'root');
27
28 /** MySQL数据库密码 */
29 define('DB_PASSWORD', '000000');
......
在数据库中新建名为wordpress的数据库:
mysql -uroot -p000000
MariaDB [(none)]> create database wordpress;
修改nginx配置文件:
将#/etc/nginx/conf.d/default.conf 文件的第9行“root /usr/share/nginx/html;”修改为“root /opt/wordpress;”;第31行的“root /usr/share/nginx/html;”修改为“root /opt/wordpress;”即可,然后重启nginx
vi /etc/nginx/conf.d/default.conf
8 location / {
9 root /usr/share/nginx/html;
10 index index.php index.html index.htm;
11 }
.....
30 location ~ \.php$ {
31 root /usr/share/nginx/html;
32 fastcgi_pass 127.0.0.1:9000;
33 fastcgi_index index.php;
34 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
35 include fastcgi_params;
36 }
#systemctl restart nginx
然后在物理机上访问服务器地址即可安装wordpress