CentOS7 配置搭建安装LNMP

1. 关闭防火墙和selinux

打开文件selinux

vim  /etc/sysconfig/selinux
  • 1

将文件中SELINUX=enforcing改为disabled,然后执行”setenforce 0″不用重启地关闭selinux。

SELINUX=disabled
  • 1

关闭放火墙

systemctl stop firewalld.service

如果不想关闭防火墙  就把端口加进去就可以

查看防火墙的状态
不管当前防火墙的状态如何(重启或者开启防火墙自动启动)运行指令systemctl  start firewalld.service
或者systemctl restart firewalld.service

firewall-cmd --state
查看端口是否被开发





添加一个测试的端口8080并测试是否开放(此操作只作为测试用,inux重启的化端口又出来不对外开放)




添加一个开放的端口并写入配置文件中永久保存,重启防火墙并查看开放的端口
查看防火墙中对外公开的端口的配置文件



2.安装软件

2.1.MYSQL安装

下载mysql的repo源

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
  • 1

安装mysql-community-release-el7-5.noarch.rpm包

rpm -ivh mysql-community-release-el7-5.noarch.rpm
  • 1

安装MYSQL

​ sudo yum install -y  mysql-server
  • 1

​ 更改MYSQL用户权限:

sudo chown -R root:root /var/lib/mysql
  • 1

​ 重启服务:

systemctl restart mysql.service
  • 1

登录,并修改密码:

mysql -u root
mysql > use mysql;
mysql > update user set password=password(‘123456‘) where user=‘root‘;
mysql > flush privileges;
mysql > exit;


CentOS 7.0 使用 yum 安装 MariaDB 与 MariaDB 的简单配置
闲置已久的空间环境配置忘得差不多了,今天得空整理,重置了磁盘重新搭建环境,首先在 CentOS  7.0安装MariaDB的数据库,在这里记录下安装过程,以便以后查看。
1、安装MariaDB
安装命令
yum -y install mariadb mariadb-server
安装完成MariaDB,首先启动MariaDB
systemctl start mariadb
设置开机启动
systemctl enable mariadb
接下来进行MariaDB的相关简单配置
mysql_secure_installation
首先是设置密码,会提示先输入密码
Enter current password for root (enter for none):<–初次运行直接回车
设置密码
Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
New password: <– 设置root用户的密码
Re-enter new password: <– 再输入一次你设置的密码
其他配置
Remove anonymous users? [Y/n] <– 是否删除匿名用户,回车
Disallow root login remotely? [Y/n] <–是否禁止root远程登录,回车,
Remove test database and access to it? [Y/n] <– 是否删除test数据库,回车
Reload privilege tables now? [Y/n] <– 是否重新加载权限表,回车
初始化MariaDB完成,接下来测试登录
mysql -uroot -ppassword
完成。
 
2、配置MariaDB的字符集
文件/etc/my.cnf
vi /etc/my.cnf
在[mysqld]标签下添加
init_connect= 'SET collation_connection = utf8_unicode_ci' init_connect = 'SET NAMES utf8' character -set-server= utf8 collation -server= utf8_unicode_ci skip -character-set-client-handshake
文件/etc/my.cnf.d/client.cnf
vi /etc/my.cnf.d/client.cnf
在[client]中添加
default-character-set=utf8
文件/etc/my.cnf.d/mysql-clients.cnf
vi /etc/my.cnf.d/mysql-clients.cnf
在[mysql]中添加
default-character-set=utf8
 全部配置完成,重启mariadb
systemctl restart mariadb
之后进入MariaDB查看字符集
mysql> show variables like " % character % ";show variables like " % collation % ";
显示为

+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client    | utf8                      |
| character_set_connection | utf8                      |
| character_set_database  | utf8                      |
| character_set_filesystem | binary                    |
| character_set_results    | utf8                      |
| character_set_server    | utf8                      |
| character_set_system    | utf8                      |
| character_sets_dir      | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
+----------------------+-----------------+
| Variable_name        | Value          |
+----------------------+-----------------+
| collation_connection | utf8_unicode_ci |
| collation_database  | utf8_unicode_ci |
| collation_server    | utf8_unicode_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)
字符集配置完成。
 
3、添加用户,设置权限
创建用户命令
mysql > create user username @localhost identified by 'password' ;
直接创建用户并授权的命令
mysql > grant all on * . * to username @localhost indentified by 'password' ;
授予外网登陆权限 
mysql > grant all privileges on * . * to username@ '%' identified by 'password' ;
授予权限并且可以授权
mysql > grant all privileges on * . * to username@ 'hostname' identified by 'password' with grant option ;


centos7 系统 库中默认是没有nginx的rpm包的,所以我们自己需要先更新下rpm依赖库
 
(1)使用yum安装nginx需要包括Nginx的库,安装Nginx的库
#rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
(2)使用下面命令安装nginx
#yum install nginx
(3)启动Nginx
#service nginx start
#systemctl start nginx.service


配置yum源
追加CentOS 6.5的epel及remi源。
# rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
以下是CentOS 7.0的源。
# yum install epel-release# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
使用yum list命令查看可安装的包(Packege)。
# yum list --enablerepo=remi --enablerepo=remi-php56 | grep php
安装PHP5.6
yum源配置好了,下一步就安装PHP5.6。
# yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof
用PHP命令查看版本。
# php --version




安装php
rpm 安装 Php7 相应的 yum源
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
  • 1
  • 2
安装php7.0
yum install -y php70w
  • 1
安装php扩展
yum install -y php70w-mysql . x86_64 php70w-gd . x86_64 php70w-ldap . x86_64 php70w-mbstring . x86_64 php70w-mcrypt . x86_64
  • 1
安装PHP FPM
​ yum install -y php70w-fpm



3. 修改配置文件
3.1修改Nginx配置文件
nginx配置文件位置:(/etc/nginx/conf.d/default.conf)
vim /etc/nginx/conf.d/ default .conf
  • 1
​ 修改 root目录,可自定义:
root /forest/nginxDir/html;
  • 1
​ 配置php解析,修改 下面代码中黑色加粗部分:
location ~.php $ { root /forest/nginxDir/html;​ fastcgi_pass 127.0 . 0 . 1 : 9000 ;​ fastcgi_index index.php;​fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name ;​ include fastcgi_params;​ }


3.2 修改php-fpm配置文件

php-fpm配置文件位置:(/etc/php-fpm.d/www.conf) 
​ 修改

user =nginx
​ group=nginx
按照上面方法装完lnmp环境 使用localhost访问 报 No input file specified","File not found 错误


vi /etc/nginx/conf.d/default.conf
   # fastcgi_param  SCRIPT_FILENAME          script$fastcgi_script_name
          改为:
     fastcgi_param  SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;  #指定路径

/usr/share/nginx/html   这个是你自己的服务路径


猜你喜欢

转载自blog.csdn.net/sunsijia21983/article/details/80137555