0%

CentOS 7安装Nignx, php, mysql服务器系统

添加nginx源, 因为CentOS的yum本身不带ngixn的包,所以必须事先添加

1
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

源添加完毕后,执行

1
yum install nginx -y

进行安装Nginx
安装成功后,我们执行

1
nginx

启动
并执行

1
nginx -t

测试命令
成功后,我们就可以通过127.0.0.1来查看是否成功了。(如果修改了nginx.conf的配置的话,可以通过)

1
nginx -s reload

来重载Nginx
不过因为防火墙的问题,不论是外网还是内网都无法访问网页,我们需要将端口打开,添加防火墙规则

1
2
firewall-cmd --permanent --zone=public --add-port=80/tcp  //添加80端口
firewall-cmd --reload //重新加载防火墙使之生效

PHP安装,首先添加源

1
2
3
yum-y install epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

PHP安装

1
yum install php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-mysql.x86_64 php70w-pdo.x86_64

PHP FPM安装

1
yum install php70w-fpm

配置 /etc/nginx/conf.d/default.conf 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
server {
listen 80;
server_name localhost;
/var/log/nginx/host.access.log main;

location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}

}

配置防火墙

1
firewall-cmd --zone=public --add-port=9000/tcp --permanent

重启服务,并把服务加入系统启动

1
2
3
4
5
6
systemctl restart php-fpm.service
systemctl enable nginx.service
systemctl enable php-fpm.service
ps -ef | grep nginx
kill -QUIT 主ID
nginx

接着安装mysql,此处为最新版(8.0),其他版本请自行去 MySQL官网下载
先下载MySQL源安装包

1
wget http://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm

安装MySQL源

1
yum -y install mysql80-community-release-el7-1.noarch.rpm

确认一下MySQL的源是否正确安装

1
yum repolist enabled | grep "mysql.*-community.*"

安装MySQL服务器

1
yum install mysql-community-server

查看MySQL默认密码

1
grep "password" /var/log/mysqld.log

注意,是最后面的字符串
启动MySQL服务器

1
systemctl start mysqld.service

登录MySQL服务器

1
2
mysql -uroot -p
输入刚才的密码

修改密码

1
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Xxxxx111!!!';

创建新用户

1
CREATE USER 'winbug'@'%' IDENTIFIED BY 'Xxxxxx22@@';

添加权限

1
2
GRANT ALL PRIVILEGES ON *.* TO 'winbug'@'%';
FLUSH PRIVILEGES;

开防火墙

1
2
firewall-cmd --permanent --zone=public --add-port=3306/tcp
firewall-cmd --reload

这样Nginx和PHP和MySQL就算安装完毕了