安装LNMP环境,centos7

原创 2015年06月08日 13:28:34

nginx

    rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
   yum install nginx
   systemctl start nginx
   yum install links
   links 127.0.0.1
   links 192.168.208.6
   firewall-cmd --get-active-zones 
   firewall-cmd --zone=public --list-services 
   firewall-cmd --permanent --zone=public --add-service=http
   firewall-cmd --reload

安装安装成功,可以测试,出现nginx欢迎页面就ok

mysql

   rpm -ivf mysql-community-release-el7-5.noarch.rpm 
   yum search yum-utils
   yum install yum-utils
   yum-config-manager --disable mysql56-community
   yum-config-manager --enable mysql57-community-dmr
   yum search mysql-server
   yum repolist | grep 'mysql'
   yum repolist enabled | grep 'mysql'
   yum search mysql-community-server
   yum install mysql-community-server
   [root@localhost log]# systemctl start mysqld.service 
   [root@localhost log]# grep 'temporary password' /var/log/mysqld.log
2015-06-08T01:44:44.713032Z 1 [Warning] A temporary password is generated for root@localhost: ln3hb?;Jkk6w

    [root@localhost log]# mysql_secure_installation 

    Securing the MySQL server deployment.

    Enter password for root user: 这里填grep 'temporary password' /var/log/mysqld.log命令显示出的密码

    The existing password for the user account has expired. Please set a new password.
    重新设置密码
    New password: 

    Re-enter new password: 

    VALIDATE PASSWORD PLUGIN can be used to test passwords
    and improve security. It checks the strength of password
    and allows the users to set only those passwords which are
    secure enough. Would you like to setup VALIDATE PASSWORD plugin?
    密码强度插件
    Press y|Y for Yes, any other key for No: y

    There are three levels of password validation policy:

    LOW    Length >= 8
    MEDIUM Length >= 8, numeric, mixed case, and special characters
    STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

    Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
    Using existing root password.

    Estimated strength of the password: 100 
    Change the root password? (Press y|Y for Yes, any other key for No) : n

     ... skipping.
    By default, a MySQL installation has an anonymous user,
    allowing anyone to log into MySQL without having to have
    a user account created for them. This is intended only for
    testing, and to make the installation go a bit smoother.
    You should remove them before moving into a production
    environment.
    删除anonymous用户,
    Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
    Success.


    Normally, root should only be allowed to connect from
    'localhost'. This ensures that someone cannot guess at
    the root password from the network.
    是都禁止root远程连接
    Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n

     ... skipping.
    By default, MySQL comes with a database named 'test' that
    anyone can access. This is also intended only for testing,
    and should be removed before moving into a production
    environment.

    删除test数据库
    Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
     - Dropping test database...
    Success.

     - Removing privileges on test database...
    Success.

    Reloading the privilege tables will ensure that all changes
    made so far will take effect immediately.
    重新载入权限表
    Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
    Success.

    All done!

php

yum install epel-release
   rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
   yum install --enablerepo=remi --enablerepo=remi-php56 php php-fpm php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof

整合nginx和php
修改vi /etc/php.ini
cgi.fix_pathinfo=0
修改nginx配置文件

vim /etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

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

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        #root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    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;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

[root@localhost log]# systemctl start php-fpm.service
[root@localhost log]# systemctl restart nginx.service 

ok
php和mysql
新建一个文件连接mysql试试

<?php
$con = mysql_connect("192.168.208.6:3306","root","testTEST!@#123");
if($con){
echo "ok";
}else{
echo mysql_error();
}
?>

但是连接报错
Permission denied
于是用远程连接mysql试试看
进入mysql

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY 'testTEST!@#123' WITH GRANT OPTION;
FLUSH PRIVILEGES;

然后再本机上面用远程连接时ok的,于是试着关掉selinux,

setenforce 0

就ok了
于是再开启selinux,查看http相关的selinux选项

[root@localhost html]# getsebool -a|grep -i httpd | grep net
httpd_can_network_connect --> off
httpd_can_network_connect_cobbler --> off
httpd_can_network_connect_db --> off
httpd_can_network_memcache --> off
httpd_can_network_relay --> off

修改selinux的选项

[root@localhost html]# setsebool -P httpd_can_network_connect=1

再就ok了~~~

CentOS 7 YUM 10分钟快速安装 LNMP 环境详细教程

源码编译安装 LNMP 环境虽然便于自定义,但是对于小型服务器来说,漫长的编译时间让人无法等待。如果能在 10 分钟后内搞定环境安装,再好不多了。 那么如何在 10 分钟内快速安装完 LNMP 环...
  • fusuogang
  • fusuogang
  • 2016-07-06 13:12:35
  • 7374

centos 7使用yum安装lnmp环境

centos 7使用yum安装lnmp环境,初次搭建环境的同学可以参考一下,有不当之处请指正,谢谢
  • 2015年08月20日 23:32

CentOS 7.2 编译安装 posix扩展

直接 yum install php-process 简单粗暴省事 即可安装pcntl和posix扩展 编译安装 首先查看服务器版本 php -v 比如我的版本是 php ...
  • ChenZhuoDeDiKang
  • ChenZhuoDeDiKang
  • 2018-01-26 10:21:53
  • 155

lanp安装流程

安装需要用依赖包 yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype fre...
  • q490880
  • q490880
  • 2017-11-01 13:07:47
  • 164

Centos7 手把手教你 编译安装LNMP环境 (古月)

我使用的是腾讯云的服务器 Centos7 64位的版本 在我们刚购买完服务器后我们可以使用Xshell来连接到服务器 , 但是现在Xshell开始收费了 我们不得不使用之前的版本 下面放上百度云...
  • qq_35061546
  • qq_35061546
  • 2017-12-03 18:57:55
  • 1780

Conent7.0安装lanp全过程

一、配置防火墙,开启80端口、3306端口CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。1、关闭firewall:systemctl stop firew...
  • a1085075119
  • a1085075119
  • 2017-08-25 09:46:50
  • 111

安装LNMP环境,centos7

nginx rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.no...
  • scchary
  • scchary
  • 2015-06-08 13:28:34
  • 1283

CentOS7快速搭建LNMP环境

我发布到简书的连接 CentOS7快速搭建LNMP环境
  • anan890624
  • anan890624
  • 2017-05-28 22:12:12
  • 5301

CentOS7 LNMP安装及环境配置

本篇文章使用环境为 Linux:CentOS7 PHP:5.6源码包: http://cn2.php.net/distributions/php-5.6.30.tar.bz2 MySQL:5...
  • TynMhxx
  • TynMhxx
  • 2018-01-14 14:04:43
  • 184

在CentOS7中安装mongodb

原文地址:http://www.linuxidc.com/Linux/2016-06/132675.htm 在 CentOS7 上安装 MongoDB 1 通过 SecureC...
  • qq_17805795
  • qq_17805795
  • 2016-09-07 18:07:04
  • 182
收藏助手
不良信息举报
您举报文章:安装LNMP环境,centos7
举报原因:
原因补充:

(最多只允许输入30个字)