centos7安装lnmp环境

全新安装lnmp环境,nginx和mysql采用yum的方式安装,php采用编译安装

mysql8+nginx1.14+php7.2.12

一、首先是nginx的安装,centos默认不带nginx rpm源,更新一下nginx的rpm源

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm 

然后安装nginx

yum -y install nginx

安装完成后查看nginx版本 nginx -v

nginx version: nginx/1.14.2

然后设置nginx开机启动

systemctl enable nginx

输出结果

Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

然后启动nginx,并查看nginx的状态

启动nginx:
systemctl start nginx
查看nginx状态:     
systemctl status nginx
重载nginx:
systemctl reload nginx
重启nginx:
systemctl restart nginx

输出如下

● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since 二 2018-12-04 15:34:16 CST; 30min ago
 Main PID: 6166 (nginx)
   CGroup: /system.slice/nginx.service
           ├─6166 nginx: master process /usr/sbin/nginx
           └─6167 nginx: worker process

12月 04 15:34:16 VM_0_15_centos systemd[1]: Stopped The nginx HTTP and reverse proxy server.
12月 04 15:34:16 VM_0_15_centos systemd[1]: Starting The nginx HTTP and reverse proxy server...
12月 04 15:34:16 VM_0_15_centos nginx[6161]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
12月 04 15:34:16 VM_0_15_centos nginx[6161]: nginx: configuration file /etc/nginx/nginx.conf test is successful
12月 04 15:34:16 VM_0_15_centos systemd[1]: Failed to read PID from file /run/nginx.pid: Invalid argument
12月 04 15:34:16 VM_0_15_centos systemd[1]: Started The nginx HTTP and reverse proxy server.

二、接下来是MySQL的安装,先更新yum源

rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm

然后安装mysql,默认安装的是最新版本8.0,如果要安装其它版本,根据官方文档进行配置官方文档

yum -y install mysql-community-server mysql-community-devel 

设置mysql开启启动

systemctl enable mysqld        

启动mysql

systemctl start mysqld

然后查看mysql状态

systemctl status mysqld

输出如下:

● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 二 2018-12-04 14:32:23 CST; 1h 37min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 5010 (mysqld)
   Status: "SERVER_OPERATING"
   CGroup: /system.slice/mysqld.service
           └─5010 /usr/sbin/mysqld

12月 04 14:32:12 VM_0_15_centos systemd[1]: Starting MySQL Server...
12月 04 14:32:23 VM_0_15_centos systemd[1]: Started MySQL Server.

新版MySQL会随机生成一个root密码,查看MySQL临时密码

grep 'temporary password' /var/log/mysqld.log 

输出如下:

2018-12-04T06:32:17.156844Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: fL%:oOG;y4oM

fL%:oOG;y4oM 就是临时密码,修改临时密码

mysql -uroot -p  // 根据提示输入数据库临时密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码'; 
update mysql.user set Host='%' where HOST='localhost' and User='root'; // 允许远程登录
flush privileges; // 刷新权限
quit; // 退出

三、然后是安装php7
首先安装php依赖

yum -y install gcc gcc-c++ libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel curl curl-devel openssl openssl-devel  

下载php包

官方网站:http://www.php.net/downloads.php

wget http://am1.php.net/distributions/php-7.2.12.tar.gz

解压并编译安装

tar zxf php-7.2.12.tar.gz
cd php-7.2.12
./configure --prefix=/usr/local/php --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-openssl --enable-mbstring --enable-xml --enable-session --enable-ftp --enable-tokenizer --enable-zip --enable-pcntl --enable-sockets --with-gettext --with-pear --enable-cli --enable-soap

如果configure成功应该能看到下面的字样

+--------------------------------------------------------------------+        
| License:                                                           |        
| This software is subject to the PHP License, available in this     |        
| distribution in the file LICENSE.  By continuing this installation |        
| process, you are bound by the terms of this license agreement.     |        
| If you do not agree with the terms of this license, you must abort |        
| the installation process at this point.                            |        
+--------------------------------------------------------------------+        

Thank you for using PHP.

然后执行安装

make && make install 

需要等待一段时间……

完成之后配置php.ini

cp php.ini-development /usr/local/php/lib/php.ini 

需要在php.ini配置下mysql.sock

mysqli.default_socket = /var/lib/mysql/mysql.sock

创建软链接

ln -s /usr/local/php/bin/php /usr/bin/php

查看php的版本

php -v

输出如下:

PHP 7.2.12 (cli) (built: Dec  4 2018 15:22:07) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

接下来配置 php-fpm

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf        
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

配置 php-fpm 启动脚本

 cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
重新载入 systemd
systemctl daemon-reload 

设置php-fpm开机启动
systemctl enable php-fpm 
       
启动
systemctl start php-fpm
        
查看状态
systemctl status php-fpm  

然后测试一下是否安装成功

mkdir /home/www/html        
cd /home/www/html        
vim index.php

输入下面的内容

<?php
	phpinfo();  

然后创建一个nginx站点的配置文件

cd /etc/nginx/conf.d/        

新建一个配置文件test.conf并写入下面的内容

server {        
    listen       80;        
    server_name  localhost;        
    root         /home/www/html;        
    location / {        
        index  index.php index.html index.htm;        
    }        
    location ~ \.php$ {        
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;       
    }        
}

重载nginx使设置生效

systemctl reload nginx 

然后打开浏览器查看效果~~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhangatle

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值