环境:阿里云Centos 7.4 镜像 selinux 与 firewall 已关闭。
参考了https://blog.csdn.net/zjiang1994/article/details/72876193
与https://blog.csdn.net/wszll_alex/article/details/76285324的文章
1.安装nginx
1.1 下载合适版本的nginx包
wget http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.10.0-1.el7.ngx.x86_64.rpm
1.2 建立nginx的yum仓库
rpm -ivh nginx-1.10.0-1.el7.ngx.x86_64.rpm
1.3 安装nginx
yum -y install nginx
1.4 启动nginx
systemctl start nginx
2.安装PHP7
2.1 安装 epel-release
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
2.2 安装 php7 的 yum 源
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
2.3 安装php7.0
yum install -y php70w
2.4 安装php扩展
yum install -y php70w-mysql.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64
2.5 安装 php-fpm
yum install -y php70w-fpm
3 修改配置文件
3.1 修改nginx配置文件,nginx配置文件的位置在 /etc/nginx/nginx.config
vim /etc/nginx/nginx.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
# 这里改动了,也可以写你的域名
server_name localhost;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
# 这里改动了 定义首页索引文件的名称
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# 这里新加的
# PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI协议默认配置.
# Fastcgi服务器和程序(PHP,Python)沟通的协议.
location ~ \.php$ {
# 设置监听端口
fastcgi_pass 127.0.0.1:9000;
# 设置nginx的默认首页文件(上面已经设置过了,可以删除)
fastcgi_index index.php;
# 设置脚本文件请求的路径
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# 引入fastcgi的配置文件
include fastcgi_params;
}
}
3.2 修改php-fpm 配置文件 (/etc/php-fpm.d/www.conf)
user =nginx
group=nginx
3.3 重新启动nginx
systemctl restart nginx
3.4 启动php-fpm
systemctl start php-fpm.service
3.5 设置服务开机自启
systemctl enable nginx
systemctl enable php-fpm
4. 安装mysql
4.1下载mysql的repo源
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
4.2 安装mysql-community-release-el7-5.noarch.rpm包
rpm -ivh mysql-community-release-el7-5.noarch.rpm
4.3 安装mysql
sudo yum install -y mysql-server
4.4 更改mysql的用户权限
sudo chown -R root:root /var/lib/mysql
4.5 重启服务
systemctl restart mysql.service
4.6 登陆并修改密码
mysql -u root
mysql > use mysql;
mysql > update user set password=password(‘66666‘) where user=‘root‘;
mysql > flush privileges;
mysql > exit;
若有错误和疏漏,欢迎留言指正