1. 安装并配置mariadb
[root@localhost ~]# yum install -y mariadb mariadb-server //安装程序
[root@localhost ~]# mysql_secure_installation //进行安全加固
//根据安全加固中设定的密码进行登录
[root@localhost ~]# mysql -uroot -h127.0.0.1 -p
Enter password:
MariaDB [(none)]>
//授权用户tom在如下ip段范围内,可远程登录,操作testdb数据库
MariaDB [(none)]> GRANT ALL ON testdb.* TO 'tom'@'192.168.75.%' IDENTIFIED BY 'tompass';
Query OK, 0 rows affected (0.00 sec)
//权限配置写入
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
//测试以tom身份登录
[root@localhost ~]# mysql -utom -ptompass -h192.168.75.130;
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 21
Server version: 5.5.64-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
//创建数据库
MariaDB [(none)]> CREATE DATABASE testdb CHARACTER SET 'utf8';
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| testdb |
+--------------------+
2 rows in set (0.00 sec)
MariaDB [(none)]>
2.安装php-fpm php-mysql
[root@localhost ~]# yum -y install php-fpm php-mysql
配置文件:
服务配置文件:/etc/php-fpm.conf, /etc/php-fpm.d/*.conf
环境配置文件:/etc/php.ini, /etc/php.d/*.ini
与httpd交互的配置文件:
/etc/php-fpm.d/www.conf
常用的配置选项:
listen = 127.0.0.1:9000 //php-fpm监听的地址端口
listen.allowed_clients = 127.0.0.1 //允许连接的FastCGI客户端的ipv4地址列表
user = apache
group = apache
pm.max_children = 50 //最大子进程数
pm.start_servers = 5 //启动php-fpm时,启动的子进程数
pm.min_spare_servers = 5 //最小空闲子进程数
pm.max_spare_servers = 35 //最大空闲子进程数
pm.max_requests = 500 //处理多少个请求后,重启子进程
pm.status_path = /pmstatus //fpm内建状态页面路径
ping.path = /ping //ping pong 用来测试服务器健康状态
ping.response = pong
//用户会话路径,且属主属组要改为上述设置的user与group,这里均为apache
php_value[session.save_path] = /var/lib/php/session
启动
[root@localhost ~]# systemctl start php-fpm
3.安装httpd
[root@localhost ~]# yum -y install httpd
[root@localhost ~]# httpd -M | grep fcgi //确认已装载fcgi模块
proxy_fcgi_module (shared)
增加一个vhost.conf文件,做如下配置:
<VirtualHost 192.168.75.130:80>
DocumentRoot "/data/www/vhost80"
ServerName www.aaa.com
<Directory "/data/www/vhost80">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
新建一个html页面,然后测试:
说明普通静态网页OK
修改vhost.conf:
DirectoryIndex index.php //指定索引文件
<VirtualHost 192.168.75.130:80>
DocumentRoot "/data/www/vhost80"
ServerName www.aaa.com
ProxyRequests Off //关闭正向代理
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/www/vhost80/$1 //匹配.php文件,通过fcgi接口反代至php-fpm
<Directory "/data/www/vhost80">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
修改index.html为index.php
index.php文件:
<?php
phpinfo()
?>
测试
说明fpm生效
4.安装phpmyadmin
[root@localhost ~]#sudo yum install -y phpmyadmin
[root@localhost ~]#vim /etc/httpd/conf.d/phpMyAdmin.conf
Require ip 127.0.0.1 192.168.75
此时打开,仍提示File Not Found,需要将pma路径软链接至实际路径
[root@localhost vhost80]# ln -s /usr/share/phpMyAdmin/ pma
[root@localhost vhost80]# ll
total 8
-rw-r--r-- 1 root root 37 Jan 31 23:56 index.html.bak
-rw-r--r-- 1 root root 22 Feb 1 11:33 index.php
lrwxrwxrwx 1 root root 22 Feb 1 11:35 pma -> /usr/share/phpMyAdmin/
[root@localhost vhost80]#
[root@localhost vhost80]#
此时打开若提示 mbstring extension is missing
则是因为systemctl start php-fpm的时候,未安装php-mbstring
而安装phpMyAdmin时,根据依赖关系,自动安装了php-mbstring
所以此时需要systemctl restart php-fpm