搭建php-fpm工作方式的LAMP环境,实现wordpress

2018-06-28  本文已影响9人  任总

1、LAMP定义

2、搭建Lamp

 [root@bogon ~]# systemctl stop firewalld
[root@bogon ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@bogon ~]# vim /etc/selinux/config 
 SELINUX=disabled
 [root@bogon ~]# systemctl reboot  #重启生效

(1)安装mariadb服务

 [root@bogon ~]# yum install  mariadb-server -y
 [root@bogon ~]# vim /etc/my.cnf.d/server.cnf
 
 [mysqld]
skip_name_resolve=ON               #添加
innodb_file_per_table=ON          #添加
 
 [root@bogon ~]# systemctl start mariadb
 [root@bogon ~]# systemctl enable mariadb
 [root@bogon ~]# ss -tnl
   [root@bogon ~]mysql_secure_installation
      Enter current password for root (enter for none):      #输入root密码第一次没有直接回车
      Set root password? [Y/n] y                                  #设定root密码输入y
      New password:                                                #新密码
      Re-enter new password:                                        #再输入一次
      Remove anonymous users? [Y/n] y                           #是否移除匿名用户
    Disallow root login remotely? [Y/n] y                         #是否远程禁止root登录
    Remove test database and access to it? [Y/n] y              #是否删除测试数据库
    Reload privilege tables now? [Y/n] y                        #是否重新加载特权表
[root@bogon ~]# mysql -u root -p123                    #登录数据库
  MariaDB [(none)]> GRANT ALL ON *.* TO 'test'@'192.168.%.%' IDENTIFIED BY "123";    #创建授权用户
  Query OK, 0 rows affected (0.00 sec)                                             
  MariaDB [(none)]> FLUSH PRIVILEGES;               #刷新
  Query OK, 0 rows affected (0.01 sec)
  MariaDB [(none)]> EXIT                                   #退出
  Bye
[root@bogon ~]# mysql -utest -h'192.168.1.11' -p123   测试登录

(2)安装php服务

 [root@bogon ~]# yum -y install php               #安装php
 [root@bogon ~]# yum -y install php-fpm php-mysql php-mbstring php-mcrypt  #安装PHP相关模块

服务配置文件:/etc/php-fpm.conf,/etc/php-fpm.d/.conf
php环境配置文件:/etc/php.ini,/etc/php.d/
.ini

[root@bogon ~]# cp /etc/php-fpm.d/www.conf{,.bak}      #备份原配置文件
[root@bogon ~]# vim  /etc/php-fpm.d/www.conf            #编辑

listen =127.0.0.1:9000  修改可以监听的主机可以本地  *:9000   也可以其他主机
listen.backlog = -1后援队列   -1代表无限长
listen.allowed_clients = 127.0.0.1   允许那些客户端请求,授权连接
 user = apache
 group = apache
 pm=dynamic      static或者dynamic 默认dynamic
 pm.max_children=50  子进程数量
 pm.start_server=5    开始启动进程数量
 pm.max_spare_servers=15   最大空闲数量
 pm.max_requests=500   每个进程响应多少个请求然后关掉
 pm.starus_path=/pm-status  内置的状态页
 ping.path=pong 可以ping服务器远程状态探测
 php_value[session.save_hadler]=files  客户会话保留
 php_value[session.save_save_path]=/var/lib/php/session   目录不存在要手动创建然后修改
[root@bogon ~]# mkdir /var/lib/php/session -pv     #建立文件
[root@bogon ~]# chown apache.apache /var/lib/php/session   #修改属组属主
[root@bogon ~]# ll  /var/lib/php/                          #查看
total 0
drwxrwx--- 2 apache apache 6 Apr 12 15:04 session
[root@bogon ~]# systemctl start php-fpm
[root@bogon ~]# ss -tnl
State      Recv-Q Send-Q                       Local Address:Port                                      Peer Address:Port              
LISTEN     0      128                          172.16.15.106:9000                                                 *:*                  
LISTEN     0      50                                       *:3306                                                 *:*                  

(3)、安装httpd服务

[root@bogon ~]# yum install httpd -y        #安装httpd
[root@bogon ~]# httpd -M                    #查询是否有fcgi模块
.......
 proxy_fcgi_module (shared)
.......
[root@bogon ~]# mkdir /data/www/html -pv
mkdir: 已创建目录 "/data"
mkdir: 已创建目录 "/data/www"
mkdir: 已创建目录 "/data/www/html"
[root@httpd ~]# vim /etc/httpd/conf.d/fcgi.conf
DirectoryIndex index.php  #设置默认主页为index.php
ProxyRequests off  #关闭正向代理
将以.php结尾的URL代理转发给fcgi://127.0.0.1:9000
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/www/html/$1  
ProxyPassMatch ^/(ping|pmstatus)$ fcgi://127.0.0.1:9000/$1
DirectoryIndex index.php
<VirtualHost *:80>
        ServerName www.hehe.com
        DocumentRoot /data/www/html
        ProxyRequests Off #关闭反向代理
        ProxyPassMatch ^/(.*\.php)$  fcgi://127.0.0.1:9000/data/www/html/$1   #将以.php结尾的URL代理转发给fcgi://url
        ProxyPassMatch ^/(ping|pmstatus)$ fcgi://127.0.0.1:9000/$1  #将以ping或pmstatus结尾的URL代理转发给fcgi://url
        <Directory "/data/www/html">
                Options None
                AllowOverride None
                Require all granted
        </Directory>
</VirtualHost>
~                                                                                                                                                         
[root@bogon ~]# vim /data/www/html/index.php 
                    <?php 
                            phpinfo();
                       ?>
[root@bogon ~]# vim /data/www/html/mysql.php           
<?php     #编辑mysql登录测试页
$conn = mysql_connect('192.168.1.11','test','123');
        if ($conn)
                echo "Connected to mysql.";
        else
                echo "Fail";
?>
[root@bogon ~]# httpd -t             #语法检查
Syntax OK
[root@bogon ~]# systemctl start httpd   #启动httpd

3、部署wordpress

(1)下载安装wordpress

[root@bogon ~]# wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
[root@bogon ~]# ls
 wordpress-4.9.4-zh_CN.tar.gz
[root@bogon ~]# tar xf wordpress-4.9.4-zh_CN.tar.gz 
[root@bogon ~]# cp -a wordpress /data/www/html
[root@bogon ~]# chown -R apache:apache /data/www/html/wordpress/
image.png
  [root@bogon ~]# mysql -uroot -p123
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE wordpress;                   #创建一个数据库
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> GRANT ALL ON wordpress.* TO 'wpuser'@'192.168.%.%'IDENTIFIED BY '12345678';               #授权用户
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> EXIT
Bye
image.png image.png image.png
上一篇下一篇

猜你喜欢

热点阅读