centos7安装php7 php-fpm nginx mariadb及解决php7与php-fpm冲突的问题

本是古典 何须时尚 2022-06-17 02:51 463阅读 0赞

centos7安装php7 php-fpm nginx mariadb及解决php7与php-fpm冲突的问题

  • 简介
  • 关闭SELINUX
  • 设置80、3306端口开放
  • 可用的php7源
  • 安装nginx服务器
  • 安装MariaDB数据库
  • 重启nginx、php-fpm、MariaDB
  • 小问题集锦

简介

  • centos7废除了许多以前版本的命令,虽然现在依然向上兼容(最小化安装除外),但是不排除下几个版本彻底废除的事实。
  • 在本次安装php7与php-fpm的过程中发生许多源冲突等错误,所以后面附上可用的源(无冲突)。
  • MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可
    。开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,
    因此社区采用分支的方式来避开这个风险。

关闭SELINUX

vi /etc/selinux/config

  1. #SELINUX=enforcing #注释掉
  2. #SELINUXTYPE=targeted #注释掉
  3. SELINUX=disabled #增加

:wq

设置80、3306端口开放

使用firewalld代替了原来的iptables。下面记录如何使用firewalld开放Linux端口:
开启端口
firewall-cmd –zone=public –add-port=80/tcp –permanent
命令含义:
–zone #作用域
–add-port=80/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效
重启防火墙
firewall-cmd –reload

可用的php7源

1.安装EPEL源

yum -y install epel-release.noarch

2.手动进行系统更新

yum -y update

3.设置系统为香港时区并检查时区设置

timedatectl set-timezone Asia/Hong_Kong
timedatectl

4.删除之前的php版本

yum remove php* php-common

5.安装php7相关的源

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

6.安装php7及php-fpm

yum -y install php70w php70w-opcache php70w-fpm php70w-mysql php70w-pdo php70w-pgsql php70w-xml php70w-mbstring php70w-mcrypt php70w-gd

7.配置php-fpm

vi /etc/php-fpm.d/www.conf #编辑
user = nginx #修改用户为nginx
group = nginx #修改组为nginx
:wq #保存退出

8.设置php-fpm开机自启

systemctl enable php-fpm.service

安装nginx服务器

1.安装nginx

yum install nginx

2.配置nginx与php7

vi /etc/nginx/nginx.conf

  1. user nginx;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. include mime.types;
  12. default_type application/octet-stream;
  13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  14. # '$status $body_bytes_sent "$http_referer" '
  15. # '"$http_user_agent" "$http_x_forwarded_for"';
  16. #access_log logs/access.log main;
  17. sendfile on;
  18. #tcp_nopush on;
  19. #keepalive_timeout 0;
  20. keepalive_timeout 65;
  21. #gzip on;
  22. server {
  23. listen 80;
  24. server_name localhost;
  25. #charset koi8-r;
  26. #access_log logs/host.access.log main;
  27. location / {
  28. root /var/www/html;
  29. index index.html index.htm index.php;
  30. }
  31. #error_page 404 /404.html;
  32. # redirect server error pages to the static page /50x.html
  33. #
  34. error_page 500 502 503 504 /50x.html;
  35. location = /50x.html {
  36. root /var/www/html;
  37. }
  38. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  39. #
  40. #location ~ \.php$ {
  41. # proxy_pass http://127.0.0.1;
  42. #}
  43. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  44. #
  45. location ~ \.php$ {
  46. root /var/www/html;
  47. fastcgi_pass 127.0.0.1:9000;
  48. fastcgi_index index.php;
  49. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  50. include fastcgi_params;
  51. }
  52. # deny access to .htaccess files, if Apache's document root
  53. # concurs with nginx's one
  54. #
  55. #location ~ /\.ht {
  56. # deny all;
  57. #}
  58. }
  59. # another virtual host using mix of IP-, name-, and port-based configuration
  60. #
  61. #server {
  62. # listen 8000;
  63. # listen somename:8080;
  64. # server_name somename alias another.alias;
  65. # location / {
  66. # root html;
  67. # index index.html index.htm;
  68. # }
  69. #}
  70. # HTTPS server
  71. #
  72. #server {
  73. # listen 443 ssl;
  74. # server_name localhost;
  75. # ssl_certificate cert.pem;
  76. # ssl_certificate_key cert.key;
  77. # ssl_session_cache shared:SSL:1m;
  78. # ssl_session_timeout 5m;
  79. # ssl_ciphers HIGH:!aNULL:!MD5;
  80. # ssl_prefer_server_ciphers on;
  81. # location / {
  82. # root html;
  83. # index index.html index.htm;
  84. # }
  85. #
  86. #choolsearch
  87. }

:wq #保存退出

安装MariaDB

1.安装MariaDB

yum -y install mariadb mariadb-server net-tools

2.启动mariadb并设为开机自启

systemctl start mariadb.service
systemctl enable mariadb.service

3.安全性设置

mysql_secure_installation

运行后首先会提示输入root密码直接回车(密码为空);然后提示修改root密码直接回车(默认为yes)输入两遍新密码;之后出现的提示选择都是回车(默认为yes)

4.设置远程访问并管理数据库

grant all privileges on . to ‘root’@’%’ identified by ‘zdj123456’;

重启nginx、php-fpm、MariaDB

systemctl restart nginx.service
systemctl restart php-fpm.service
systemctl restart mysql.service

小问题集锦

  1. 装完centos7可能会遇到ping不通 连不上网的问题

cd /etc/sysconfig/network-scripts
ls
vi ifcfg-eno45643132
把ONBOOT=no改为yes
service network restart (重启network)
记住ifcfg-eno45643132(数字一人一个样子)
注:最小化安装的centos7不支持ifconfig 代替为ip addr命令

发表评论

表情:
评论列表 (有 0 条评论,463人围观)

还没有评论,来说两句吧...

相关阅读