LNMP环境搭建

LNMP环境搭建

1.nginx的安装

创建系统用户nginx

[root@localhost ~]# useradd -r -M -s /sbin/nologin nginx

安装依赖环境

[root@localhost ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++
[root@localhost ~]# yum -y groups mark install 'Development Tools'

创建日志存放目录

[root@localhost ~]# mkdir -p /var/log/nginx
[root@localhost ~]# chown -R nginx.nginx /var/log/nginx

下载nginx

[root@localhost ~]# wget http://nginx.org/download/nginx-1.12.0.tar.gz

编译安装

[root@localhost ~]# cd nginx-1.12.0
[root@localhost nginx-1.12.0]# ./configure \
--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]# make && make Install

修改配置文件(把下面的代码取消注释)

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }
2 安装mysql

安装依赖包

[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel

创建用户和组

[root@localhost ~]# groupadd -r -g 306 mysql
[root@localhost ~]# useradd -r -M -s /sbin/nologin -g 306 -u 306 mysql

下载二进制格式的mysql软件包并解压

[root@localhost ~]# cd /usr/local/
[root@localhost local]# wget https://downloads.mysql.com/archives/get/file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
[root@localhost local]# tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
[root@localhost local]# ln -sv mysql-5.7.22-linux-glibc2.12-x86_64/ mysql
"mysql" -> "mysql-5.7.22-linux-glibc2.12-x86_64/"

修改目录/usr/local/mysql的属主属组

[root@localhost local]# chown -R mysql.mysql mysql*
[root@localhost local]# chown -R mysql.mysql mysql*
[root@localhost local]# ll
总用量 628704
drwxr-xr-x. 2 root  root          6 3月  10 2016 debug
drwxr-xr-x. 2 root  root          6 3月  10 2016 kernels
lrwxrwxrwx. 1 mysql mysql        36 12月 30 10:28 mysql -> mysql-5.7.22-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 mysql mysql       129 12月 30 10:23 mysql-5.7.22-linux-glibc2.12-x86_64

添加环境变量

[root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost local]# . /etc/profile.d/mysql.sh
[root@localhost local]# echo $PATH
/usr/local/mysql/bin:/usr/local/nginx/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

建立数据存放目录

[root@localhost local]# mkdir /opt/data
[root@localhost src]#  chown -R mysql.mysql /opt/data/

初始化数据库 rDPRdlyr6N,h

[root@localhost local]# mysqld --initialize --user=mysql --datadir=/opt/data/

配置mysql

[root@localhost local]# ln -s /usr/local/mysql/include/ /usr/local/include/mysql
[root@localhost local]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@localhost local]# ldconfig 

生成配置文件

[root@localhost local]# cat > /etc/my.cnf <<EOF
> [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 local]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost local]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@localhost local]# sed -ri 's#^(datadir=).*#\1/opt/data#g' /etc/init.d/mysqld

启动mysql

[root@localhost local]#  service mysqld start
Starting MySQL.Logging to '/opt/data/localhost.localdomain.err'.
 SUCCESS! 

修改mysql密码

安装php

配置yum源

[root@localhost ~]# wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
[root@localhost ~]# rpm -Uvh remi-release-7.rpm
[root@localhost ~]# yum makecache --enablerepo=remi

安装依赖包

[root@localhost ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel  pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel php72-php-mysqlnd

下载php

[root@localhost ~]# cd /usr/local/
[root@localhost local]# wget http://cn.php.net/distributions/php-7.2.8.tar.xz

编译安装php

[root@localhost php-7.2.8]# ./configure --prefix=/usr/local/php7  \
--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]# make && make install

修改环境变量

[root@localhost ~]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[root@localhost ~]# source /etc/profile.d/php7.sh

配置php-fpm

[root@localhost php-7.2.8]# source /etc/profile.d/php7.sh
[root@localhost php-7.2.8]# cp php.ini-production /etc/php.ini
cp:是否覆盖"/etc/php.ini"? yes
[root@localhost php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-7.2.8]# chmod +x /etc/rc.d/init.d/php-fpm
[root@localhost php-7.2.8]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@localhost php-7.2.8]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf

编辑php-fpm的配置文件

(/usr/local/php7/etc/php-fpm.conf)
[root@localhost ~]# vim /usr/local/php7/etc/php-fpm.conf
在最后面添加以下代码
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8

启动php-fpm

[root@localhost ~]# service php-fpm start
Starting php-fpm  done

创建虚拟主机目录并生成php测试页面

[root@localhost html]# cat > /usr/local/nginx/html/index/php <<EOF
<?php
   phpinfo();
?>
EOF

验证
在浏览器上使用IP访问,出现下面页面表示成功
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值