安装nginx
如题,centos默认源是没有nginx源的,若要使用yum安装nginx,nginx官网也有说明。
在此做一下记录
1、添加源
[root@ip-172-26-11-8 ~]#rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2、通过yum search nginx看看是否已经添加源成功。如果成功则执行下列命令安装Nginx。
[root@ip-172-26-11-8 ~]#yum install -y nginx
3、启动Nginx
[root@ip-172-26-11-8 ~]#systemctl start nginx.service
4、查看状态
[root@ip-172-26-11-8 ~]# systemctl status nginx.service
此时可以看到nginx已经运行。
安装mysql5.7
1、安装mysql源
yum -y localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
yum repolist enabled | grep "mysql.*-community.*"
2、安装mysql
yum -y install mysql-community-server install mysql-commumity-devel
3、启动mysql
service mysqld start
4、检查mysql是否启动
service mysqld status 或者 ps -ef | grep mysql
mysql5.7 以后的争强了安全机制,所以使用yum安装,系统会自动生成一个随机的密码,并且不能设置简单密码。所以需要修改 mysql 全局参数
先用日志密码登录 mysql
grep 'temporary password' /var/log/mysqld.log
会输出结果: A temporary password is generated for root@localhost: ******
使用此密码登录后 执行 SHOW VARIABLES LIKE 'validate_password%'; 查看 mysql 密码策略
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 8 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | MEDIUM |
| validate_password_special_char_count | 1 |
+--------------------------------------+--------+
执行 set global validate_password_policy=LOW; 修改密码策略
执行 set global validate_password_length=6; 修改验证密码长度
切换 user 库
update user set authentication_string = password('root'), password_expired = 'N', password_last_changed = now() where user = 'root';
重启 mysqld 服务,再用新密码登录即可
如果无法登录,提示Access denied for user 'root'@'localhost'
重新更新 root 用户的 plugin 字段
update user set plugin='mysql_native_password' where user = 'root';
更新成功后.重新执行更新密码操作
刷新权限 flush privileges;
此处我用原密码登陆mysql后修改密码
[root@ip-172-26-11-8 ~]#mysql -uroot -p*******
修改密码为123456
首先进入mysql库
mysql>use mysql;
mysql>grant all privileges on *.* to root@localhost identified by '123456';
mysql>flush privileges;
安装php7.1
1、换源和安装
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 -y install php71w php71w-fpm
yum -y install php71w-mbstring php71w-common php71w-gd php71w-mcrypt
yum -y install php71w-mysql php71w-xml php71w-cli php71w-devel
yum -y install php71w-pecl-memcached php71w-pecl-redis php71w-opcache
验证 PHP 是否安装成功 php -v
验证 PHP 拓展是否安装成功 php -m
启动php-fpm
service php-fpm start
若不能解析php页面则需要查看日志信息
cd /var/log/nginx/error.log
在nginx.conf 中设置了设置你本地的 root 目录(服务根目录),例如:
root /usr/share/nginx/html;
那么需要将 fastcgi_param 参数修改为:
默认配置为
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
修改为
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
此时重启nginx 和 php-fpm 即可。
如果装好php后无法解析php脚本文件,那么需要在nginx配置文件中server部分加上php-fpm
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}