LNMP
Linux Nginx Mysql PHP
LNMT
Linux Nginx Mysql Tomcat(JAVA)
搭建博客网站blog.wsm.com
1.部署nginx
参见web服务部署过程
],修改nginx配置文件
[root@test01 conf]# vim conf.d/blog.conf
server {
listen 80;
server_name blog.wsm.com;
location / {
root html/gcy;
index index.php index.html index.htm;
}
location ~* \.(php|php5)$ { #添加location 匹配正则 以.php .php5结尾
root html/blog; #站点目录
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
测试nginx是否正常-静态
[root@test01 conf]# curl -H Host:blog.wsm.com 10.0.0.111
blog gcy
2.安装MySQL
Centos7中mysql 替换为 mariadb
安装
yum -y install mariadb-server
启动mariadb
systemctl start mariadb
检查是否有进程
root@test01 ~]# ps -ef |grep mysql
mysql 32529 1 0 05:59 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
mysql 32691 32529 0 05:59 ? 00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock
root 32728 11511 0 06:00 pts/1 00:00:00 grep --color=auto mysql
默认端口号3306
[root@test01 ~]# ss -lntup|grep mysql
tcp LISTEN 0 50 *:3306 *:* users:(("mysqld",pid=32691,fd=13))
进入mysql
[root@test01 ~]# mysql -uroot -p
- 显示所有数据库
show databases;
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
- 创建数据库
create database wordpress;
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)
- 添加用户
MariaDB [(none)]> grant all on wordpress.* to wordpress@'172.16.1.%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all on wordpress.* to wordpress@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
- 查看用户
select user,host from mysql.user;
MariaDB [(none)]> select user,host from mysql.user;
+-----------+------------+
| user | host |
+-----------+------------+
| root | 127.0.0.1 |
| wordpress | 172.16.1.% |
| root | ::1 |
| | localhost |
| root | localhost |
| wordpress | localhost |
| | test01 |
| root | test01 |
+-----------+------------+
8 rows in set (0.00 sec)
- 删除无用用户
drop user ''@'localhost' ;
MariaDB [(none)]> drop user ''@'localhost' ;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> drop user ''@'test01' ;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> select user,host from mysql.user;
+-----------+------------+
| user | host |
+-----------+------------+
| root | 127.0.0.1 |
| wordpress | 172.16.1.% |
| root | ::1 |
| root | localhost |
| wordpress | localhost |
| root | test01 |
+-----------+------------+
6 rows in set (0.00 sec)
- 更新一下权限信息
flush privileges ;
MariaDB [(none)]> flush privileges ;
Query OK, 0 rows affected (0.00 sec)
3.安装PHP
先配置php yum源安装
yum remove php-mysql-5.4 php php-fpm php-common #移除系统中已存在的数据库及php等
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
- 安装以下工具
yum -y install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb
- 修改php-fpm.d配置文件
[root@test01 ~]# vim /etc/php-fpm.d/www.conf
[root@test01 ~]# grep -n '=.www' /etc/php-fpm.d/www.conf
8:user = www
10:group = www
- systemctl restart php-fpm 重启
检查端口与进程,端口为9000
[root@test01 ~]# ss -lntup |grep php-fpm
tcp LISTEN 0 128 127.0.0.1:9000 *:* users:(("php-fpm",pid=32779,fd=9),("php-fpm",pid=32778,fd=9),("php-fpm",pid=32777,fd=9),("php-fpm",pid=32776,fd=9),("php-fpm",pid=32775,fd=9),("php-fpm",pid=32774,fd=7))
[root@test01 ~]# ps -ef |grep php
root 32774 1 0 06:37 ? 00:00:00 php-fpm: master process (/etc/php-fpm.conf)
www 32775 32774 0 06:37 ? 00:00:00 php-fpm: pool www
www 32776 32774 0 06:37 ? 00:00:00 php-fpm: pool www
www 32777 32774 0 06:37 ? 00:00:00 php-fpm: pool www
www 32778 32774 0 06:37 ? 00:00:00 php-fpm: pool www
www 32779 32774 0 06:37 ? 00:00:00 php-fpm: pool www
root 32785 11511 0 06:39 pts/1 00:00:00 grep --color=auto php
4.联合测试
- 测试nginx是否正常-静态
[root@test01 conf]# curl -H Host:blog.wsm.com 10.0.0.111
blog gcy
- 测试php是否正常-显示动态 nginx + php
写入一个测试文件
[root@test01 blog]# cat /application/nginx-1.14.2/html/blog/info.php
phpinfo();
?>
浏览器访问blog.wsm.com/info.php显示页面
表示成功
- 测试php与mariadb
写入一个测试文件
[root@web01 blog]#cat /application/nginx-1.14.2/html/blog/mysql.php
浏览器访问blog.wsm.com/mysql.php显示页面
########LNMP部署完成########
- 下载wordpress 搭建网站 放入程序代码
unzip wordpress-5.0.3-zh_CN.zip
mv wordpress/* /application/nginx-1.14.2/html/blog/
chown www.www /application/nginx-1.14.2/html/blog/
- 浏览器访问blog.wsm.com
填写信息成功访问
显示数据库内容
MariaDB [(none)]> show tables from wordpress;
+-----------------------+
| Tables_in_wordpress |
+-----------------------+
| wp_commentmeta |
| wp_comments |
| wp_links |
| wp_options |
| wp_postmeta |
| wp_posts |
| wp_term_relationships |
| wp_term_taxonomy |
| wp_termmeta |
| wp_terms |
| wp_usermeta |
| wp_users |
+-----------------------+
12 rows in set (0.00 sec)