Centos7安装配置mariaDB + nginx + php-fpm环境

Centos7 搭建mariaDB + nginx + php环境

系统更新

  • 1.安装开启安装EPEL YUM源
[root@localhost ~]# yum -y install epel-release
[root@localhost ~]# yum makecache
  • 2.系统更新
[root@localhost ~]# yum update
  • 3.解决The remote SSH server rejected X11 forwarding request提示
[root@localhost ~]# yum install xorg-x11-xauth
# 编辑/etc/ssh/sshd_config文件中的X11Forwarding参数为yes
[root@localhost ~]# vim /etc/ssh/sshd_config
  • 4.安装编译组件和依赖
[root@localhost ~]# yum -y install gcc gcc-c++ make unixODBC wxBase wxGTK wxGTK-gl ncurses-devel zlib zlib-devel openssl openssl-devel kernel-devel m4 xmlto net-tools lksctp-tools socat cmake perl perl-JSON libtool pcre pcre-devel yasm yasm-devel libmcrypt libmcrypt-devel libvpx libvpx-devel tiff tiff-devel libpng libpng-devel freetype freetype-devel jpeg jpeg-devel libgd libgd-devel t1lib t1lib-devel gd gd-devel

修改主机名

  • 1.将/etc/hostname中的值修改为localhost或者其他主机名
[root@localhost ~]# vim /etc/hostname
  • 2.在/etc/sysconfig/network 中添加或者修改为HOSTNAME=localhost或者其他主机名
[root@localhost ~]# vim /etc/sysconfig/network
  • 3.将/etc/hosts 中各项值修改为localhost或者其他主机名
[root@localhost ~]# vim /etc/hosts
  • 4.临时修改主机名
[root@localhost ~]# hostname localhost

添加用户

添加新的用户账号使用useradd命令,其语法如下

useradd 选项 用户名

其中各选项含义如下:
代码:

  • -c comment 指定一段注释性描述。
  • -d 目录 指定用户主目录,如果此目录不存在,则同时使用-m选项,可以创建主目录。
  • -g 用户组 指定用户所属的用户组。
  • -G 用户组,用户组 指定用户所属的附加组。
  • -s Shell文件 指定用户的登录Shell。
  • -u 用户号 指定用户的用户号,如果同时有-o选项,则可以重复使用其他用户的标识号。
  • 用户名 指定新账号的登录名

  • 1.添加nginx用户

[root@localhost ~]# groupadd nginx
[root@localhost ~]# useradd -c nginx -g nginx nginx -s /sbin/nologin
  • 2.添加网站专用wwwroot用户
[root@localhost ~]# groupadd www
[root@localhost ~]# useradd -c www -g www www -s /sbin/nologin

安装MARIADB

  • 1.使用yum命令安装mariaDB
[root@localhost]# yum -y install mariadb mariadb-server
  • 2.设置开机启动
[root@localhost ~]# systemctl enable mariadb
  • 3.启动MySQL服务
[root@localhost ~]# systemctl start mariadb
  • 4.MariaDB的相关简单配置
[root@localhost ~]# mysql_secure_installation
# 首先是设置密码,会提示先输入密码,初次运行直接回车
Enter current password for root (enter for none):
# 设置密码,是否设置root用户密码,输入y并回车或直接回车
Set root password? [Y/n]
# 设置root用户的密码
New password:
# 再输入一次你设置的密码
Re-enter new password:
# 其他配置
# 是否删除匿名用户,回车
Remove anonymous users? [Y/n]
# 是否禁止root远程登录,回车
Disallow root login remotely? [Y/n]
# 是否删除test数据库,回车
Remove test database and access to it? [Y/n]
# 是否重新加载权限表,回车
Reload privilege tables now? [Y/n]
# 初始化MariaDB完成,接下来测试登录
# mysql -uroot -proot密码
  • 5.授权远程用户登录
# 允许的IP地址,%为任意地址
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'IP地址' IDENTIFIED BY 'youpassword' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;

安装PHP

  • 1.安装php
[root@localhost ~]# yum -y install php php-devel
  • 2.安装php扩展
[root@localhost ~]# yum -y install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
  • 3.安装php-fpm
# 安装 php-fpm
[root@localhost ~]# yum -y install php-fpm
# 设置fpm开机自启动
[root@localhost ~]# systemctl enable php-fpm
# 启动fpm
[root@localhost ~]# systemctl start php-fpm
# php-fpm配置文件路径/etc/php-fpm.conf

安装NGINX

  • 1.下载nginx
# 切换到src目录
[root@localhost ~]# cd /usr/local/src
# 下载nginx源码包
[root@localhost src]# wget http://nginx.org/download/nginx-1.12.0.tar.gz
# 解压并切换到nginx目录
[root@localhost src]# tar zxvf nginx-1.12.0.tar.gz
[root@localhost src]# cd nginx-1.12.0
# 配置编译选项
[root@localhost nginx-1.12.0]# ./configure --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-pcre
# 安装
[root@localhost nginx-1.12.0]# make & make install
  • 2.启动关闭nginx
# 常规启动、关闭和重启,不会改变启动时指定的配置文件
[root@localhost ~]# /usr/local/nginx/sbin/nginx
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s stop
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload
# 设置开机自启动
[root@localhost ~]# vim /lib/systemd/system/nginx.service
# 写入以下内容
# --------------------------------------------------
[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target
# --------------------------------------------------
[root@localhost ~]# systemctl enable nginx
  • 3.添加php支持
# 修改nginx.conf,去掉以下代码的注释
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }
# 重启nginx
[root@localhost]# /usr/local/nginx/sbin/nginx -s reload
  • 4.解决访问php提示File not found.
# 修改nginx配置文件
# 源文件
fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
# 修改后的文件,将 /scripts 修改为$document_root
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
标签:MariaDBCentosPHPNginx 发布于:2019-11-17 23:47:10