Centos7 搭建mariaDB + nginx + php环境
[root@localhost ~]# yum -y install epel-release
[root@localhost ~]# yum makecache
[root@localhost ~]# yum update
[root@localhost ~]# yum install xorg-x11-xauth
# 编辑/etc/ssh/sshd_config文件中的X11Forwarding参数为yes
[root@localhost ~]# vim /etc/ssh/sshd_config
[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
[root@localhost ~]# vim /etc/hostname
[root@localhost ~]# vim /etc/sysconfig/network
[root@localhost ~]# vim /etc/hosts
[root@localhost ~]# hostname localhost
添加新的用户账号使用useradd命令,其语法如下
useradd 选项 用户名
其中各选项含义如下:
代码:
用户名 指定新账号的登录名
1.添加nginx用户
[root@localhost ~]# groupadd nginx
[root@localhost ~]# useradd -c nginx -g nginx nginx -s /sbin/nologin
[root@localhost ~]# groupadd www
[root@localhost ~]# useradd -c www -g www www -s /sbin/nologin
[root@localhost]# yum -y install mariadb mariadb-server
[root@localhost ~]# systemctl enable mariadb
[root@localhost ~]# systemctl start 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密码
# 允许的IP地址,%为任意地址
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'IP地址' IDENTIFIED BY 'youpassword' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
[root@localhost ~]# yum -y install php php-devel
[root@localhost ~]# yum -y install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
# 安装 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
# 切换到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
# 常规启动、关闭和重启,不会改变启动时指定的配置文件
[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
# 修改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
# 修改nginx配置文件
# 源文件
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# 修改后的文件,将 /scripts 修改为$document_root
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;