服务器安装 lnmp 跟 lamp (centos7.5)

2 篇文章 0 订阅
1 篇文章 0 订阅

1.查看centos版本

cat /etc/redhat-release

2.检查是否装相关应用 

检查apache

httpd -v

检查mysql

service mysqld start

如果有安装过,清理下

yum remove mysql
rpm -qa | grep httpd

二(1) 安装apache

yum -y install httpd

安装apache扩展

yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql

启动apache

systemctl start httpd.service #启动apache
systemctl stop httpd.service #停止
systemctl restart httpd.service #重启

设置开机自启动

systemctl enable httpd.service

(2)安装nginx

yum install yum-priorities -y 
wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm  
rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm 
yum install nginx  
systemctl start nginx.service #启动nginx
systemctl stop nginx.service #停止  
systemctl restart nginx.service #重启  
systemctl enable nginx.service #设置开机启动

安装php-fpm

yum install php-fpm  
systemctl start php-fpm.service #启动php-fpm  
systemctl enable php-fpm.service #设置开机启动

更改nginx配置文件识别php

 vi /etc/nginx/conf.d/default.conf,把之前的#给去掉就可以了,顺手改一下fastcgi_param
location ~ \.php$ {  
    root           html;  
    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;  
}

三 安装php

配置yum源 
CentOS 7.0的源。

yum install epel-release

rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

yum源配置好了,下一步就安装PHP5.6。

yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-gd php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof

安装PHP-fpm

yum install --enablerepo=remi --enablerepo=remi-php56 php-fpm 

四 安装mysql

使用wget下载官方yum源的rpm包:

wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

安装rpm包:

rpm -ivh mysql57-community-release-el7-11.noarch.rpm

使用yum来安装mysql-server:

yum install -y mysql-server

安装完成后,启动mysqld服务

systemctl start mysqld #启动
systemctl start mysqld.service #重启

设置mysqld服务开机自启动

systemctl enable mysqld

使用初始密码登录

由于MySQL从5.7开始不允许首次安装后,使用空密码进行登录,系统会随机生成一个密码以供管理员首次登录使用,这个密码记录在/var/log/mysqld.log文件中,使用下面的命令可以查看此密码:

cat /var/log/mysqld.log|grep 'A temporary password'

修改数据库密码

刚安装的mysql的密码默认强度是最高的,如果想要设置简单的密码就要修改安全级别跟密码长度

//密码强度
set global validate_password_policy=0;
//密码长度
set global validate_password_length=4;
格式:mysql> set password for 用户名@localhost = password('新密码');  

例子:mysql> set password for root@localhost = password('123');  

番外篇

nginx安装成功后,在浏览器输入IP地址,打不开默认欢迎页面

原因:CentOS 7版本之后对防火墙进行加强,不再使用原来的iptables,启用firewall防火墙默认不开放任何端口,所以Nginx默认的80端口也没有被放开,故而无法访问。

关闭防火墙

systemctl stop firewalld.service

nginx网站存放目录  vi /usr/share/nginx/html/

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值