搭建环LNMP
准备工作
首先,准备好一台有公网ip的云Linux CentOS7服务器。个人原因:切换网络会使得IP地址频繁变动,使用云服务器可以大大降低这种影响。
开始搭建
安装 php+nginx+mysql
首先,打开CentOS环境的虚拟机,查看IP地址。

安装php
-- remi源安装php yum remove -y epel-release.noarch yum install -y epel-release
-- 到清华源去下载 yum install -y https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm
-- 更新依赖 yum --enablerepo=remi-php71 install -y php php-cli php-common php-devel php-embedded php-gd php-mbstring php-pdo php-xml php-fpm php-mysqlnd php-opcache php-mcrypt php-pecl-memcached php-pecl-mongodb php-pecl-redis
-- 编写配置文件(24/26行),创建一个syw用户 vim /etc/php-fpm.d/www.conf user = syw group = syw 注意:这里是真的要创建一个名为syw的用户的! useradd syw passwd syw
-- 启动php服务(一行执行比较方便) systemctl start php-fpm.service;systemctl enable php-fpm.service;systemctl status php-fpm.service
|
为了启动方便,我把启动部分装在shell脚本当中。
-- 先执行命令打开文件 # vi runPHP.sh
-- 再写入文件内容 #! /bin/bash systemctl start php-fpm.service systemctl enable php-fpm.service systemctl status php-fpm.service
-- 加上可执行权限 chmod u+x runPHP.sh
-- 运行脚本(注意:运行只需要使用绝对路径执行程序即可) ./home/syw/runPHP.sh
|
配置nginx
-- 安装依赖包 yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
-- 创建并且进入文件夹 cd /usr/local;mkdir nginx;cd nginx -- 下载且解压tar包 wget http://nginx.org/download/nginx-1.13.7.tar.gz tar -xvf nginx-1.13.7.tar.gz
-- 安装nginx cd /usr/local/nginx;cd nginx-1.13.7 -- 执行命令 考虑到后续安装ssl证书 添加两个模块 ./configure --with-http_stub_status_module --with-http_ssl_module -- 执行make命令 make -- 执行make install命令 make install
-- 启动nginx /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
-- 打开配置文件,配置端口和服务器IP地址 vi /usr/local/nginx/conf/nginx.conf
server { listen 8800; -- nginx的端口 server_name 192.168.140.12; -- nginx的IP地址,可以是本机IP地址 ...(省略)
-- 重启nginx /usr/local/nginx/sbin/nginx -s reload -- 查看进程是否启动 ps -ef | grep nginx
|

-- 关闭防火墙(不建议,建议放行端口) systemctl stop firewalld.service -- CentOS6的关闭防火墙 systemctl stop iptables.service
-- 放行端口8800 firewall-cmd --zone=public --add-port=8800/tcp --permanent -- 查询端口号80 是否开启 firewall-cmd --query-port=80/tcp -- 重启防火墙(重要!这一步不能忽略!) firewall-cmd --reload
-- 安装完成一般常用命令 # cd /usr/local/nginx/sbin
-- 启动,关闭,重启,命令: # ./nginx 启动 # ./nginx -s stop 关闭 # ./nginx -s reload 重启
|
访问 IP地址:端口 到默认网页

安装MySQL
-- 安装数据库软件 # yum install mariadb-server mariadb -y -- 启动数据库服务 # systemctl start mariadb.service # systemctl enable mariadb.service -- 创建数据库的用户和密码信息 # mysqladmin -u root password '123456' --密码登录mysql # mysql -u root -p123456
|
实现LNMP之间建立关系
等下一篇