Centos 7.4 镜像 selinux 与 firewall 已关闭。
工作环境
- 腾讯云 1核 1GB 1Mbps 云服务器
- CentOS 7.2 64位
- 已经安装了PHP
- 使用putty链接服务器
1.安装nginx
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm Retrieving http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
安装nginx
yum -y install nginx
启动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;
# 设置网站根目录
# /wwww
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_param SCRIPT_FILENAME /www$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;
测试
我们可以通过下面的方法判断Nginx配置是否成功。
-
在Nginx的网站根目录(/usr/share/nginx/html)下创建一个php文件,随便起名我的是index.php
-
输入ip/index.php