CentOS7yum安装nginx+php7+mysql

短命女 2022-04-24 14:44 518阅读 0赞

相关笔记:
CentOS7源码编译安装nginx+php7.2+mysql5.7并使用systemctl管理
CentOS6.9源码编译安装nginx+php7+mysql环境
CentOS6.9yum安装nginx+php7+mysql环境
1.安装nginx

设置nginx安装源

  1. vim /etc/yum.repos.d/nginx.repo

输入如下配置

  1. [nginx]
  2. name=nginx repo
  3. baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
  4. gpgcheck=0
  5. enabled=1

查看nginx版本

  1. yum list nginx
  2. nginx.x86_64 1:1.14.2-1.el7_4.ngx

安装nginx

  1. yum -y install nginx

查看安装版本和configure参数

  1. [root@jmsiteos7 ~]# nginx -v
  2. nginx version: nginx/1.14.2
  3. [root@jmsiteos7 ~]# nginx -V
  4. nginx version: nginx/1.14.2
  5. built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
  6. built with OpenSSL 1.0.2k-fips 26 Jan 2017
  7. TLS SNI support enabled
  8. configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

启动nginx

  1. systemctl start nginx

查看nginx状态

  1. systemctl status nginx
  2. nginx.service - nginx - high performance web server
  3. Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
  4. Active: active (running) since 2019-01-03 13:36:25 CST; 11s ago
  5. Docs: http://nginx.org/en/docs/
  6. Process: 7376 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
  7. Main PID: 7377 (nginx)
  8. CGroup: /system.slice/nginx.service
  9. ├─7377 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
  10. └─7378 nginx: worker process
  11. 1 03 13:36:25 jmsiteos7 systemd[1]: Starting nginx - high performance web server...
  12. 1 03 13:36:25 jmsiteos7 systemd[1]: Started nginx - high performance web server.

设置开机启动

  1. systemctl enable nginx
  2. Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

nginx详细配置请移步(nginx的configure参数,配置文件,虚拟主机配置,信号控制)
2.安装mysql

设置mysql5.7安装源

  1. rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

安装mysql

  1. yum -y install mysql-community-server

启动mysql

  1. systemctl start mysqld

设置开机启动

  1. systemctl enable mysqld

mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改

  1. cat /var/log/mysqld.log | grep "A temporary password is generated for root"
  2. 2019-01-03T05:41:47.164940Z 1 [Note] A temporary password is generated for root@localhost: zMnep.TsF3tE

zMnep.TsF3tE便是root密码,修改root密码

  1. mysql -uroot -pzMnep.TsF3tE
  2. mysql: [Warning] Using a password on the command line interface can be insecure.
  3. Welcome to the MySQL monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 4
  5. Server version: 5.7.24
  6. Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.
  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  11. mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'jmsite.cn';
  12. ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
  13. mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Jmsite.cn:80';
  14. Query OK, 0 rows affected (0.00 sec)
  15. mysql> exit
  16. Bye

设置编码

  1. vim /etc/my.cnf

如下设置

  1. [mysqld]
  2. character_set_server=utf8
  3. init_connect='SET NAMES utf8'

重启mysql

  1. systemctl restart mysqld

3.安装php7.2

设置centos7的php7安装源

  1. rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
  2. rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

安装php7.2和各种扩展

  1. yum install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml

启动php

  1. systemctl start php-fpm

设置开机启动

  1. systemctl enable php-fpm

4.配置nginx支持php

修改配置

  1. vim /etc/nginx/conf.d/default.conf

server段中去掉下面的注释,并更改成如下配置

  1. location ~ \.php$ {
  2. root /usr/share/nginx/html;
  3. fastcgi_pass 127.0.0.1:9000;
  4. fastcgi_index index.php;
  5. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  6. include fastcgi_params;
  7. }

创建测试php文件

  1. vim /usr/share/nginx/html/test.php

写入下面的php代码

  1. <?php
  2. phpinfo();
  3. ?>

重新加载nginx配置

  1. systemctl reload nginx

浏览器输入:你的ip地址/test.php

20190103145836p1.png
原文地址:https://www.jmsite.cn/blog-304.html

发表评论

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

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

相关阅读