LNMP编译安装

环境

Linux版本:centos7.6 64位
db:192.128.90.171

安装前准备工作

1.关闭selinux

[root@db ~]# vim /etc/selinux/config 
SELINUX=disabled

2.关闭firewall,清空iptables

[root@db ~]# systemctl stop firewalld.service
[root@db ~]# systemctl disable firewalld.service
[root@db ~]# iptables -L
[root@db ~]# iptables -F

3.安装LNMP环境依赖软件包

[root@db ~]# yum -y install bzip2-devel curl-devel freetype-devel gcc libjpeg-devel libpng-devel libxslt-devel libxml2-devel openssl-devel pcre-devel pcre-devel zlib-devel

编译安装Nginx

1.下载Nginx-1.16.0.tar.gz

[root@db ~]# wget https://Nginx.org/download/Nginx-1.16.0.tar.gz

2.解压Nginx包并配置安装

[root@db ~]# tar -zxvf Nginx-1.16.0.tar.gz
[root@db ~]# cd Nginx-1.16.0
[root@db Nginx-1.16.0]# ./configure --prefix=/usr/local/Nginx
[root@db Nginx-1.16.0]# make
[root@db Nginx-1.16.0]# make install

3.测试是否安装成功

[root@db ~]# cd /usr/local/Nginx/
[root@db ~]# /usr/local/Nginx/sbin/Nginx -t
[root@db ~]# /usr/local/Nginx/sbin/Nginx

浏览器输入服务器的IP地址:192.168.90.171

nginx


4.修改网站的根目录为:/webapp/html

[root@db Nginx]# vim /usr/local/Nginx/conf/Nginx.conf
server {
        listen       80;
        server_name  192.168.90.171;
        root         /webapp/html;
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            #root   html;
            index  index.PHP index.html index.htm;
        }
[root@db ~]# mkdir -p /webapp/html
[root@db ~]# cd /webapp/html/
[root@db html]# vim index.html
<p1>welcome to Nginx</p1>
[root@db ~]# /usr/local/Nginx/sbin/Nginx -s reload

测试:
浏览器输入服务器的IP地址:192.168.90.171/index.html

test


5.添加Nginx到系统服务

[root@db ~]# /usr/local/Nginx/sbin/Nginx -s quit
[root@db ~]# vim /lib/systemd/system/Nginx.service
[Unit]
Description=Nginx service
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/Nginx/sbin/Nginx
ExecReload=/usr/local/Nginx/sbin/Nginx -s reload
ExecStop=/usr/local/Nginx/sbin/Nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

6.启动Nginx添加开机自启

[root@db ~]# systemctl start Nginx
[root@db ~]# systemctl enable Nginx

编译安装PHP

1.下载PHP-7.0.11.tar.gz
下载地址:http://PHP.net/get/PHP-7.0.11.tar.gz/from/a/mirror,下载在本地然后上传到服务器

[root@db ~]# rz

在这里插入图片描述


2.解压安装包并配置安装

[root@db ~]# tar -zxvf PHP-7.0.11.tar.gz
[root@db ~]# cd PHP-7.0.11
[root@db PHP-7.0.11]# ./configure --prefix=/usr/local/PHP --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-MysqLi --with-openssl --with-pcre-regex --with-pdo-MysqL --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip
[root@db PHP-7.0.11]# make
[root@db PHP-7.0.11]# make install

3.配置PHP

[root@db PHP-7.0.11]# cp PHP.ini-development /usr/local/PHP/PHP.ini
[root@db PHP-7.0.11]# cd /usr/local/PHP/
[root@db PHP]# cp etc/PHP-fpm.conf.default etc/PHP-fpm.conf
[root@db PHP]# cp etc/PHP-fpm.d/www.conf.default etc/PHP-fpm.d/www.conf
[root@db PHP]# vim PHP.ini
cgi.fix_pathinfo=0
[root@db PHP]# /usr/local/PHP/sbin/PHP-fpm
[root@db PHP]# netstat -nplt | grep 9000

4.配置Nginx联动PHP

[root@db ~]# vim /usr/local/Nginx/conf/Nginx.conf
server {
        listen       80;
        server_name  192.168.90.171;
        root         /webapp/html;
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            #root   html;
            #添加index.PHP
            index  index.PHP index.html index.htm; 
        }
location ~ \.PHP$ {
            root           /webapp/html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.PHP;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
[root@db ~]# vim /usr/local/Nginx/sbin/Nginx -s reload        

5.测试

[root@db ~]# vim /webapp/html/index.PHP
<?PHP
    PHPinfo();
?>

然后打开浏览器输入对应的地址进行访问:http://192.168.90.171/index.PHP

test02


6.添加PHP-fpm到系统服务

[root@db ~]# kill -INT `cat /usr/local/PHP/var/run/PHP-fpm.pid`
[root@db ~]# vim /lib/systemd/system/PHP-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/run/PHP-fpm.pid
ExecStart=/usr/local/PHP/sbin/PHP-fpm --nodaemonize --fpm-config /usr/local/PHP/etc/PHP-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID

[Install]
WantedBy=multi-user.target

7.启动PHP-fpm且添加开机自启

[root@db ~]# systemctl start PHP-fpm.service
[root@db ~]# systemctl enable PHP-fpm.service

MysqL5.7安装

使用MysqL Yum存储库的快速安装

1.将MysqL Yum存储库添加到系统的存储库列表中
a.访问https://dev.MysqL.com/downloads/repo/yum/上的MysqL Yum存储库下载页面

b.选择并下载适用于您的平台的发行包。

c.使用以下命令安装下载的发行包,替换 platform-and-version-specific-package-name 为下载的包的名称:

[root@db ~]# rpm -Uvh MysqL80-community-release-el7-3.noarch.rpm

2.选择MysqL5.7版本安装

[root@db ~]# yum repolist all | grep MysqL
[root@db ~]# yum-config-manager --disable MysqL80-community
[root@db ~]# yum-config-manager --enable MysqL57-community
[root@db ~]# yum repolist enabled | grep mysq

3.安装MysqL

[root@db ~]# yum -y install MysqL-community-server

4.启动MysqL并设置开机自启

[root@db ~]# systemctl start MysqLd.service
[root@db ~]# systemctl enable MysqLd.service

5.修改MysqL用户root密码

[root@db ~]# grep 'temporary password' /var/log/MysqLd.log
[root@db ~]# MysqL -u root -pG9U:=dfHK:u8
MysqL> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Hl_123456';
MysqL> flush privileges;

6.测试PHP连接MysqL

[root@db ~]# MysqL -u root -pHl_123456
MysqL> create database test;
MysqL> use test;
MysqL> create table tb_user( id int(10) not null auto_increment primary key, username varchar(64) default '' );
MysqL> insert into tb_user (id,username) values(1,'xiaohuang');
MysqL> insert into tb_user (id,username) values(2,'xiaodong'); 
MysqL> exit
[root@db ~]# vim /webapp/html/MysqLi.PHP
<?PHP
/*
 * MysqLi
 * 数据库地址,登陆账号,密码,数据库名称
 */
 $MysqLi = new MysqLi("127.0.0.1", "root", "Hl_123456", "test");
 if($MysqLi){
    echo 'Connected to MysqL Success.';
 }else{
    echo 'Connected to MysqL Fail.';
 }
 echo '<hr/>';

 $sql = "SELECT * FROM tb_user";
 $result = $MysqLi->query($sql);
 if ($result) {
   while ($row = $result->fetch_assoc()) {
       echo 'Username: '.$row['username']. '<br/>';
   }
}

/* free result set */
$result->free();

/* close connection */
$MysqLi->close();
?>

打开浏览器访问测试结果如下:http://192.168.90.171/MysqLi.PHP

test03

至此LNMP编译安装完毕!

相关文章

Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一...
本地项目配置 1 复制 luffy/settings/dev.py为prop.py 修改l...
nginx不仅可以隐藏版本信息,还支持自定义web服务器信息 先看...
一 、此次漏洞分析 1 nginx HTTP/2漏洞 [nginx-announce] ng...
###进入nginx 目录cd /usr/local/nginx###递归显示 2 级目录...
在cmd命令窗口输入下面命令进行查看 tasklist /fi "ima...