lnmp安装,php针对7.2及以下适用

安装nginx

 1# 创建nginx  系统用户、用户组
 2groupadd  -r -g 108  nginx     # 组号 108
 3useradd -r  -g 108   nginx
 4# 安装常用的
 5yum -y install gcc gcc-c++ autoconf automake libtool make cmake
 6# 安装在这个目录下
 7cd    /usr/local/src/
 8# 安装  nginx  需要的
 9yum -y install zlib zlib-devel openssl openssl-devel pcre-devel
10# 下载稳定版的nginx
11wget http://nginx.org/download/nginx-1.10.0.tar.gz
12tar -zxvf    nginx-1.10.0.tar.gz
13cd  nginx-1.10.0
14./configure  \
15--prefix=/usr/local/nginx \
16--sbin-path=/usr/sbin/nginx \
17--conf-path=/etc/nginx/nginx.conf \
18--error-log-path=/var/log/nginx/error.log \
19--http-log-path=/var/log/nginx/access.log \
20--pid-path=/var/run/nginx/nginx.pid \
21--lock-path=/var/lock/nginx.lock \
22--user=nginx \
23--group=nginx \
24--with-http_stub_status_module \
25--with-http_ssl_module \
26--with-http_flv_module \
27--with-http_gzip_static_module \
28--http-client-body-temp-path=/var/tmp/nginx/client/ \
29--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
30--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
31--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
32--http-scgi-temp-path=/var/tmp/nginx/scgi \
33--with-pcre
34make && make install
35/usr/sbin/nginx  # 启动     我这里报错了说没这个目录
36mkdir    /var/tmp/nginx/client -p      #再次启动
37/usr/sbin/nginx
38ps -aux | grep nginx   #查看是否启动

安装php7

针对php7.2及以下版本适用

 1# 先安装一些常用的库
 2yum -y install libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel
 3libxml2 libxml2-devel  gd  gd-devel
 4yum -y install     zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel
 5yum -y install   ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel
 6yum -y install   krb5 krb5-devel libidn libidn-devel openssl openssl-devel   
 7wget http://cn2.php.net/get/php-*.tar.gz/from/this/mirror  
 8tar  -zxvf mirror  
 9cd  php-*
10# 编译配制
11./configure --prefix=/usr/local/php7.x \
12--enable-gd-jis-conv \
13--enable-mysqlnd \
14--with-curl \
15--with-freetype-dir \
16--with-gd \
17--with-gettext \
18--with-iconv-dir \
19--with-kerberos \
20--with-libdir=lib64 \
21--with-libxml-dir \
22--with-mysqli=mysqlnd \
23--with-pdo-mysql=mysqlnd \
24--with-openssl \
25--with-pcre-regex \
26--with-pear \
27--with-png-dir \
28--with-jpeg-dir \
29--with-xmlrpc \
30--with-xsl \
31--with-zlib \
32--enable-fpm \
33--enable-bcmath \
34--enable-libxml \
35--enable-mbregex \
36--enable-mbstring \
37--enable-opcache \
38--enable-pcntl \
39--enable-shmop \
40--enable-soap \
41--enable-sockets \
42--enable-sysvsem \
43--enable-xml \
44--enable-zip
45
46##  --with-mysqli=mysqlnd               mysql可以后面安装的意思
47make  && make install            # 如内存不足1mb,开启swap解决 ,阿里云默认不开启
48# 复制配置文件
49cp /usr/local/php/etc/php-fpm.conf.default     /usr/local/php/etc/php-fpm.conf
50cp  /usr/local/php/etc/php-fpm.d/www.conf.default  /usr/local/php/etc/php-fpm.d/www.conf
51cp  /usr/local/src/php7**/php.ini-production      /usr/local/php/lib/php.ini
52/usr/local/php/sbin/php-fpm   //开启php
53ps -aux | grep  php-fpm   //查看php-fpm 进程是否起来
54# 通过phpinfo, 发现,没有opcache
55#在php.ini  中 加入一行,
56zend_extension=opcache.so
57#并开启 opcache 选项

整合nginx 和php

nginx是把http请求变量(如get,user_agent等)转发给 php进程, 即php独立进程,与nginx进行通信. 称为 fastcgi运行方式.

vim /etc/nginx/nginx.conf

1   location ~ \.php$ {
2            root           html;
3            fastcgi_pass   127.0.0.1:9000;
4            fastcgi_index  index.php;
5            fastcgi_param  SCRIPT_FILENAME  $DOCUMENT_ROOT$fastcgi_script_name;
6            include        fastcgi_params;
7  }
8/usr/sbin/nginx  -s reload   

安装mysql

由于mysql 编译很费时间 ,于是我就用了二进制的包

我用的是 163源,直接用它编译好的二进制包,

在5.7之前初始化的方法是:bin/mysql_install_db –user=mysql

我下载的是的5.7版本初始化数据库不再使用mysql_install_db ,而且没有默认的数据库配置文件

 1yum install -y libaio
 2cd /usr/local/src
 3wget http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
 4tar  zxvf  mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
 5mv   mysql-5.7.22-linux-glibc2.12-x86_64   /usr/local/mysql
 6useradd -r -g mysql -s /bin/false mysql
 7mkdir  -pv /data/mysql
 8chown -R mysql.mysql /data/mysql   //存数据目录
 9cd /usr/local/mysql
10chown -R mysql .
11chgrp -R mysql .

修改 /etc/my.cnf

 1[mysqld]
 2pid-file=/data/mysql/mysql.pid
 3basedir=/usr/local/mysql
 4datadir=/data/mysql
 5socket=/tmp/mysql.sock
 6tmpdir=/tmp
 7# Disabling symbolic-links is recommended to prevent assorted security risks
 8symbolic-links=0
 9log-error=/data/mysql/mysqld.log
10language=/usr/local/mysql/share/english
11# Settings user and group are ignored when systemd is used.
12# If you need to run mysqld under a different user or group,
13# customize your systemd unit file for mariadb according to the
14# instructions in http://fedoraproject.org/wiki/Systemd
15[mysqld_safe]
16log-error=/data/mysql/mysql_error.log
17pid-file=/data/mysql/mysql.pid
18[mysql]
19default-character-set=utf8
20socket=/tmp/mysql.sock
21[client]
22default-character-set=utf8
23socket=/tmp/mysql.sock
24#
25# include all files from the config directory
26#
27!includedir /etc/my.cnf.d

初始化数据库

在5.7.6之前初始化的方法是:bin/mysql_install_db –user=mysql

我下载的是最新的5.7.17,5.7.6之后的版本初始化数据库不再使用mysql_install_db

1./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql  
2--innodb_undo_tablespaces=3 --explicit_defaults_for_timestamp

如果配置了my.cnf的log_error,那么初始密码在log_error文件中,否则会打印出来。

设置开启启动

1cp support-files/mysql.server /etc/init.d/mysqld
2chkconfig --add mysqld
3chkconfig mysqld on
4service mysqld start

配置环境变量

vim /etc/profile

1mysql_home=/usr/local/mysql
2PATH=$PATH:$mysql_home/bin
3export PATH
1source /etc/profile

修改密码

从log-error日志中找到密码后登陆进去,执行

1SET PASSWORD = PASSWORD('123456');
2flush privileges