1、安装nginx:
yum install nginx
systemctl enable nginx
systemctl start nginx
2、安装memcached
yum install memcached
systemctl enable memcached
systemctl start memcached
3、安装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
yum install php72w php72w-opcache php72w-fpm php72w-pdo php72w-pecl-memcached php72w-mysqlnd php72w-mbstring php72w-gd php72w-devel php72w-pecl-memcached php72w-xml php72w-pecl-imagick php72w-pecl-mongodb
如果需要Mongodb扩展: yum install -y php72w-pecl-mongodb
如果需要redis扩展:yum install -y php72w-pecl-redis
systemctl enable php-fpm
systemctl start php-fpm
ps aux | grep php-fpm
如果不喜欢php-fpm的默认用户,可以修改用户和用户组,比如www用户:
添加用户:
useradd -M -s /sbin/nologin -d /data/web/www www
备注:
-M 不创建目录
-s 登陆的bash
-d 用户主目录
修改配置:
vim /etc/php-fpm.d/www.conf
修改如下两个配置项:
user = www
group = www
然后一定要更改phpsession的权限:
chown -R www:www /var/lib/php/session
4、安装mysql
yum -y install mariadb mariadb-server mariadb-devel
systemctl enable mariadb
systemctl start mariadb
安装完成后建议设置默认字符集为UTF-8:《给mysql设置UTF8编码》
5、安装mongodb
vim /etc/yum.repos.d/mongodb-3.4.repo
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=0
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc
yum install -y mongodb-org
systemctl start mongod
为mongodb添加用户和权限(注意:密码自己设置,我这里只是示例而已)
mongo
use admin;
db.createUser({
user: “root”,
pwd: “root”,
roles: [{
role: “root”,
db: “admin”
}]
});
show users;
去掉配置文件中的那两行注释:
security:
authorization: enabled
重启mongodb
systemctl restart mongod
添加自己需要的数据库,并添加一个只能操作该数据库的用户:
mongo -uroot -proot admin
use test;
db.createUser({
user: “test”,
pwd: “test”,
roles: [{
role: “readWrite”,
db: “test”
}]
});
show users;
这样,用户test就只能操作test数据库,而无法操作其它任何内容了,当然也无法添加用户,因为角色决定了他的权限。
如果要修改密码,请执行:
db.changeUserPassword(‘root’, ‘new password’);
如果mongodb是下载的压缩版,解压缩到比如/web目录下后,可以vim /lib/systemd/system/mongod.service,输入如下内容:
[Unit]
Description=mongodb service
Documentation=https://www.mongodb.com/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
ExecStart=/web/mongodb/bin/mongod -f /web/mongodb/mongod.conf
ExecStop=killall mongod
[Install]
WantedBy=multi-user.target
然后chmod +x /lib/systemd/system/mongod.service,systemctl enable mongod,systemctl start mongod。