技术宅改变世界 技术宅改变世界

Centos7.2配置LNMP

in Dev read (1387) 文章转载请注明来源!

0、配置yum代理(正式环境无视)

因为是在虚拟机里面配置,网络环境在国内,yum安装软件的速度真心感人,所以先配置个代理

echo "proxy=http://172.16.254.1:1087" >> /etc/yum.conf
#172.16.254.1是本机的IP,本机开着S%S共享给虚拟机用的

1、设置时区

timedatectl set-timezone Asia/Shanghai

2、安装一些常用的包

yum install net-tools vim

3、安装nginx

vi /etc/yum.repos.d/nginx.repo
#增加nginx包

按i进入编辑模式,将下面的内容拷贝上去,按esc键退出编辑模式,按住shift再按二下z(或者输入:wq)保存文件。

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
yum install nginx
#安装nginx

4、安装mariadb

yum install mariadb-server mariadb-client
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation 
#配置mariadb,默认密码为空,直接回车,接着按照提示设置,可以配上翻译。

5、安装php7

yum install epel-release
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install php70w-mysql php70w-xml php70w-soap php70w-xmlrpc
yum install php70w-mbstring php70w-json php70w-gd php70w-mcrypt
#PHP7效率真高了很多,如果在程序兼容的情况下,强烈建议升级。

6、安装php-fpm

yum install php70w-fpm
systemctl restart php-fpm.service
systemctl enable php-fpm.service
#更改PHP运行用户
vi /etc/php-fpm.d/www.conf
#找到user = apache 修改成 user = nginx
#找到group = nginx 修改成 group = nginx

7、配置nginx、php

cd /etc/nginx
vi enable-php.conf

按i进入编辑模式,将下面的内容拷贝上去,按esc键退出编辑模式,按住shift再按二下z(或者输入:wq)保存文件。

location ~ [^/]\.php(/|$)
{
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
vi nginx.conf
#找到'worker_processes',按i进入编辑模式,将值修改为CPU核心数*2,避免IO带来的影响。
#按esc键退出编辑模式,按住shift再按二下z(或者输入:wq)保存文件。

8、增加网站

vi conf.d/run.la.conf
#run.la可以替换成自己喜欢的名字

按i进入编辑模式,将下面的内容拷贝上去,按esc键退出编辑模式,按住shift再按二下z(或者输入:wq)保存文件。

server
{
listen [::]:80;
server_name run.la; #域名
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/run.la; #网站目录
include enable-php.conf; #引用php
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
access_log /home/wwwlogs/run.la.log; #日志目录
}
mkdir /home
mkdir /home/wwwroot
mkdir /home/wwwlogs
mkdir /home/wwwroot/run.la
#创建网站目录
chown -R nginx:nginx wwwroot wwwlogs
#将文件所有者所有组修改成nginx

9、配置防火墙,CentOS 7 引入了一个新的服务firewall。

yum install firewalld
#安装防火墙
systemctl restart firewalld.service 
#启动防火墙 
systemctl enable firewalld.service 
#将防火墙加到开机启动 
firewall-cmd --zone=public --add-service=http --permanent
#开启tcp80端口
firewall-cmd --zone=public --add-service=https --permanent
#开启tcp443端口

10、更改SSH端口

vi /etc/ssh/ssh_config
#找到#Port 22,按i进入编辑模式,改成Port 22,并在下面一行增加Port 1000
#不直接删除#Port22是为了临时保留22端口,避免防火墙屏蔽了1000端口,导致无法访问
systemctl restart sshd.service
#重启ssh服务
firewall-cmd --zone=public --add-port=1000/tcp --permanent
#将tcp1000端口加入到firewall允许列表
firewall-cmd --reload
#重启firewall防火墙使规则生效
#使用1000端口重新连接ssh,如果连接成功,则将/etc/ssh/ssh_config文件的Port 22重新加上#(或者删除整行),保证安全。
firewall-cmd --zone=public --remove-service=ssh --permanent
#删除22端口,请一定要先保证1000端口可以SSH连接上后再删除
firewall-cmd --reload

11、拓展:yum mysql 源

有些人估计更喜欢原生的mysql,所以帖一下mysql的rpm,点我点我!

rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

具体配置跟mariadb一样。

yum install mysql-community-server
systemctl start mysqld
systemctl enable mysqld
mysql_secure_installation

如果默认密码不为空,可以在mysql日志中查看是否有设置密码

grep "A temporary password" /var/log/mysqld.log


#2016-11-11T11:11:11.111111Z 1 [Note] A temporary password is generated for root@localhost: hfPSyo/P4sE!
#hfPSyo/P4sE! 就是密码。

 

phpmysqlnginxcentoslnmp
发表新评论
博客已萌萌哒运行
© 2024 • Powered by Typecho • Theme for yotu
PREVIOUS NEXT
雷姆
拉姆