1. lnmp组成
2. lnmp安装
2.1 nginx安装
//创建系统用户nginx
[root@localhost ~]
//安装依赖环境
[root@localhost ~]
安装过程略....
[root@localhost ~]
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Marked install: Development Tools
//创建日志存放目录
[root@localhost ~]
[root@localhost ~]
//下载nginx
[root@localhost ~]
[root@localhost src]
--2018-08-20 11:19:09-- http://nginx.org/download/nginx-1.12.0.tar.gz
Resolving nginx.org (nginx.org)... 95.211.80.227, 206.251.255.63, 2606:7100:1:69::3f, ...
Connecting to nginx.org (nginx.org)|95.211.80.227|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 980831 (958K) [application/octet-stream]
Saving to: ‘nginx-1.12.0.tar.gz’
100%[======================================================>] 980,831 15.9KB/s in 43s
2018-08-20 11:19:52 (22.3 KB/s) - ‘nginx-1.12.0.tar.gz’ saved [980831/980831]
//编译安装
[root@localhost src]
debug kernels nginx-1.12.0.tar.gz
[root@localhost src]
[root@localhost src]
[root@localhost nginx-1.12.0]
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-debug \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log
[root@localhost nginx-1.12.0]
[root@localhost nginx-1.12.0]
nginx nginx.old
[root@localhost nginx-1.12.0]
[root@localhost nginx-1.12.0]
[root@localhost nginx-1.12.0]
[root@localhost nginx-1.12.0]
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
2.2 MySQL安装
[root@localhost ~]
//创建用户和组
[root@localhost src]
[root@localhost src]
//下载二进制格式的mysql软件包
[root@localhost ~]
[root@localhost src]
//解压软件至/usr/local/
[root@localhost src]
debug kernels mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
[root@localhost src]
[root@localhost ~]
bin games lib libexec sbin src
etc include lib64 mysql-5.7.22-linux-glibc2.12-x86_64 share
[root@localhost ~]
[root@localhost local]
‘mysql’ -> ‘mysql-5.7.22-linux-glibc2.12-x86_64/’
[root@localhost local]
total 0
drwxr-xr-x. 2 root root 6 Mar 10 2016 bin
drwxr-xr-x. 2 root root 6 Mar 10 2016 etc
drwxr-xr-x. 2 root root 6 Mar 10 2016 games
drwxr-xr-x. 2 root root 6 Mar 10 2016 include
drwxr-xr-x. 2 root root 6 Mar 10 2016 lib
drwxr-xr-x. 2 root root 6 Mar 10 2016 lib64
drwxr-xr-x. 2 root root 6 Mar 10 2016 libexec
lrwxrwxrwx 1 root root 36 Aug 14 16:00 mysql -> mysql-5.7.22-linux-glibc2.12-x86_64/
drwxr-xr-x 9 root root 129 Aug 14 00:16 mysql-5.7.22-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 6 Mar 10 2016 sbin
drwxr-xr-x. 5 root root 49 Jun 13 19:03 share
drwxr-xr-x. 2 root root 6 Mar 10 2016 src
//修改目录/usr/local/mysql的属主属组
[root@localhost ~]
[root@localhost ~]
lrwxrwxrwx 1 mysql mysql 36 Aug 14 16:00 /usr/local/mysql -> mysql-5.7.22-linux-glibc2.12-x86_64/
//添加环境变量
[root@localhost ~]
bin COPYING docs include lib man README share support-files
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
//建立数据存放目录
[root@localhost mysql]
[root@localhost mysql]
[root@localhost mysql]
total 0
drwxr-xr-x 2 mysql mysql 6 Aug 14 16:54 data
//初始化数据库
[root@localhost ~]
2018-08-15T07:57:46.168380Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-08-15T07:57:50.542516Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-08-15T07:57:50.927286Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-08-15T07:57:51.071260Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: e8600890-a060-11e8-b1a2-000c294c50b4.
2018-08-15T07:57:51.074566Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-08-15T07:57:51.078089Z 1 [Note] A temporary password is generatedfor root@localhost: jtBzkkb=r5ik
//请注意,这个命令的最后会生成一个临时密码,此处密码是jtBzkkb=r5ik
//再次注意,这个密码是随机的,你的不会跟我一样,一定要记住这个密码,因为一会登录时会用到
//配置mysql
[root@localhost ~]
‘/usr/local/include/mysql’ -> ‘/usr/local/mysql/include/’
[root@localhost ~]
[root@localhost ~]
//生成配置文件
[root@localhost ~]
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
EOF
//配置服务启动脚本
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
//启动mysql
[root@localhost ~]
Starting MySQL.. SUCCESS!
[root@localhost ~]
root 1521 1 0 01:58 pts/0 00:00:00 /bin/sh /usr/local/mysql/binmysqld_safe --datadir=/opt/data --pid-file=/opt/data/mysql.pid
mysql 1699 1521 0 01:58 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=localhost.localdomain.err --pid-file=/opt/data/mysql.pid --socket=/tmp/mysql.sock --port=3306
root 1734 1301 0 01:59 pts/0 00:00:00 grep --color=auto mysql
[root@localhost ~]
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
//修改密码
//使用临时密码登录
[root@localhost ~]
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
//设置新密码
mysql> set password = password('wangqing123!');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit
Bye
2.3 php安装
//配置yum源
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
//安装依赖包
[root@localhost ~]
安装过程略....
//下载php
[root@localhost ~]
[root@localhost src]
下载过程略....
//编译安装php
[root@localhost src]
[root@localhost src]
[root@localhost php-7.2.8]
--with-config-file-path=/etc \
--enable-fpm \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-openssl \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--enable-exif \
--enable-ftp \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--with-gettext \
--enable-json \
--enable-mbstring \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-readline \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-pcntl \
--enable-posix
[root@localhost php-7.2.8]
编译过程略
[root@localhost php-7.2.8]
安装过程略
//安装后配置
[root@localhost ~]
[root@localhost ~]
[root@localhost php-7.2.8]
/usr/local/php7/bin/php
[root@localhost php-7.2.8]
PHP 7.2.8 (cli) (built: Aug 16 2018 13:27:30) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
//配置php-fpm
[root@localhost php-7.2.8]
[root@localhost php-7.2.8]
[root@localhost php-7.2.8]
[root@localhost php-7.2.8]
[root@localhost php-7.2.8]
//编辑php-fpm的配置文件(/usr/local/php7/etc/php-fpm.conf):
//配置fpm的相关选项为你所需要的值:
[root@localhost ~]
.....
.....
pm.max_children = 50 ;最多同时提供50个进程提供50个并发服务
pm.start_servers = 5 ;启动时启动5个进程
pm.min_spare_servers = 2 ;最小空闲进程数
pm.max_spare_servers = 8 ;最大空闲进程数
[root@localhost ~]
; file.
; Relative path can also be used. They will be prefixed by:
; - the global prefix if it's been set (-p argument)
; - /usr/local/php7 otherwise
include=/usr/local/php7/etc/php-fpm.d/*.conf
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
//启动php-fpm
[root@localhost ~]
Starting php-fpm done
//默认情况下,fpm监听在127.0.0.1的9000端口,也可以使用如下命令验证其是否已经监听在相应的套接字
[root@localhost ~]
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
[root@localhost ~]
root 81070 1 0 14:13 ? 00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nobody 81071 81070 0 14:13 ? 00:00:00 php-fpm: pool www
nobody 81072 81070 0 14:13 ? 00:00:00 php-fpm: pool www
nobody 81073 81070 0 14:13 ? 00:00:00 php-fpm: pool www
nobody 81074 81070 0 14:13 ? 00:00:00 php-fpm: pool www
nobody 81075 81070 0 14:13 ? 00:00:00 php-fpm: pool www
root 81079 83354 0 14:15 pts/1 00:00:00 grep --color=auto php
3. php启用fpm模型
[root@130 nginx]
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000; //定义反向代理
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
4.配置测试网页
[root@130 html]
> <?php
> phpinfo();
> ?>
> EOF
[root@130 nginx]
location / {
root html;
index index.php index.html;
}
[root@130 nginx]
[root@130 nginx]
[root@130 nginx]
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*