linux安装lnmp

配置说明:

CentOS Linux release 7.6.1810

nginx/1.16.0

php/php-7.2.18

mysql/5.7.26,

 

Nginx 安装

这里将用 yum 来安装 Nginx。首先更新一下 yum repo, 以便可以安装到对应的最新版本 nginx。
http://nginx.org/packages/centos/7/noarch/RPMS/
可以通过变换上面的地址找到和自己服务器对应版本的 repo 的 rpm。

[root@localhost ~]# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

安装好 yum repo 之后,接下来用 yum 安装 nginx

[root@localhost ~]# yum -y install nginx

好了,Nginx 已经安装完成,版本是 1.16.0

[root@localhost ~]# nginx -v
nginx version: nginx/1.16.0

现在设置让 Nginx 在随开机自动启动

[root@localhost ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

Centos 7启动服务命令(启动Nginx)

[root@localhost ~]# systemctl start nginx

查看Nignx 状态

[root@localhost ~]# systemctl status nginx

 

php

官网下载地址, 有最新的版本: https://www.php.net/downloads.php

mkdir ~/download
wget https://www.php.net/distributions/php-7.2.18.tar.gz
tar -zxvf php-7.2.18.tar.gz
cd php-7.2.18

查看PHP安装是具体有有些扩展和选项

./configure --help

安装之前要先安装那些准备装的扩展要用到的软件模块

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

执行configure

./configure --prefix=/usr/local/php7 --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx \
--with-mysqli --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-pdo -enable-tokenizer --enable-zip

成功后有提示, 及表示成功, 最后执行make && make install ( 漫长的过程 耐心等待)

+--------------------------------------------------------------------+
| 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-fpm

cp ~/download/php-7.2.18/sapi/fpm/php-fpm.service /usr/lib/systemd/system/

查看默认pid文件路径, fpm.conf路径

grep -E 'PIDFile|ExecStart' /usr/lib/systemd/system/php-fpm.service
PIDFile=/usr/local/php7/var/run/php-fpm.pid
ExecStart=/usr/local/php7/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php7/etc/php-fpm.conf

修改启动脚本,把里边 prefix 相关的内容用实际路径代替

[root@localhost php-7.1.4]# vim /usr/lib/systemd/system/php-fpm.service
将
PIDFile=${prefix}/var/run/php-fpm.pid
ExecStart=${exec_prefix}/sbin/php-fpm --nodaemonize --fpm-config ${prefix}/etc/php-fpm.conf
修改成
PIDFile=/usr/local/php7/var/run/php-fpm.pid
ExecStart=/usr/local/php7/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php7/etc/php-fpm.conf

重新载入 systemd

systemctl daemon-reload

让 php-fpm 随机启动

systemctl enable php-fpm
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.

立即启动 php-fpm

systemctl start php-fpm

查看状态

systemctl status php-fpm

注意

要php-7.1.4根目录的 php.ini.product 复制到  php –ini 目录下 (改名 php.ini)

遇到的问题, 新增一个 pcntl扩展, 是编译成 pcntl.so 文件. 配置都是.dll 文件, 这个后面可以了解下!

extension=pcntl.so
//重启fpm
systemctl restart php-fpm
//workman 验证环境
curl -Ss http://www.workerman.net/check.php | php

 

启fpm进程(复制配置文件)

/usr/local/php7/etc/php-fpm.conf.default    (php-fpm.conf复制一份)

/usr/local/php7/etc/php-fpm.d/www.conf.default      (www.conf.default复制一份)

cp ~/download/php-7.1.32/php.ini-production /usr/local/php7/lib/php.ini    (php.ini 复制一份)

启动

/usr/local/php7/sbin/php-fpm

 

安装mysql

下载地址
https://dev.mysql.com/downloads/repo/yum/

官方说明文档
https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

摘录
https://www.cnblogs.com/piperck/p/9768024.html

Adding the MySQL Yum Repository

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

查看版本
yum repolist all | grep mysql
默认安装最新的8.0
yum repolist enabled | grep mysql

安装其他版本

用yum-config-manager

shell> sudo yum-config-manager --disable mysql80-community
shell> sudo yum-config-manager --enable mysql57-community

dnf config-manager

shell> sudo dnf config-manager --disable mysql80-community
shell> sudo dnf config-manager --enable mysql57-community

直接修改文件 /etc/yum.repos.d/mysql-community.repo   , enabled=1 修改为0, 需要的版本修改为1

[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

安装

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

起动

systemctl start mysqld

MySQL 5.7 和之前版本很大区别是在安装后会自动为 root@localhost 用户设置一个随机初始密码,之前的版本密码为空的。那如何找到这个初始密码呢?网上很多文章说初始密码在这个文件中 /root/.mysql_secret 我不清楚早前的版本是不是这样,但 MySQL 5.7.11 并不然,而是保持到 error log 文件中。可以通过下面方法找到 MySQL 5.7 root 的初始密码

grep 'temporary password' /var/log/mysqld.log
2019-05-28T03:22:25.390771Z 1 [Note] A temporary password is generated for root@localhost: ECoqT)ask0#b

ECoqT)ask0#b 就是初始密码

修改密码

MySQL 5.7 版本对密码的安全性要求很严格,必须至少包含1个大写字母、1个小写字母、1个数字和1个特殊字符,长度不得小于8个字符

mysql -uroot -p

ALTER USER 'root'@'localhost' IDENTIFIED BY 'Kiwi2019.';  
update mysql.user set Host='%' where HOST='localhost' and User='root';
flush privileges;
SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;

 

—收工!

 

注意:配置ngixn一直无法访问

关闭防火墙

查看防火墙

firewall-cmd --state
not running / running

或者
systemctl status firewalld.service

centos7 关闭防火墙

systemctl stop firewalld.service  //执行关闭命令
systemctl disable firewalld.service   //执行开机禁用防火墙自启命令

 

 

mark:

https://www.jianshu.com/p/1e51985b46dd?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation