centos7安装部署lnmp

1. 安装依赖

导入阿里的epel源

wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo

#yum -y install make apr* autoconf automake curl-devel gcc gcc-c++ openssl openssl-devel gd kernel keyutils patch perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm* freetype libjpeg* libpng* libtool* libxml2 libxml2-devel patch libcurl-devel bzip2-devel freetype-devel pcre-devel curl libjpeg libjpeg-devel libpng libpng-devel freetype-devel zlib openldap openldap-devel sqlite-devel oniguruma-devel 

2. 安装nginx

创建安装用户 groupadd -r www && useradd -r -s /bin/false -g www -M www

#cd /usr/local/src

官网下载tar包       wget https://nginx.org/download/nginx-1.22.0.tar.gz

#tar zxf nginx-1.22.0.tar.gz

#cd nginx-1.22.0

编译 

#./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_realip_module --with-http_sub_module --with-http_flv_module --with-http_stub_status_module

安装

#make && make install

添加环境变量

cat /etc/profile

NGINX_HOME=/usr/local/nginx

export PATH=$NGINX_HOME/sbin:$PATH

source /etc/profile 

3. 安装mysql,我使用二进制的方式安装

先把mariadb卸载掉

rpm -e --nodeps mariadb-libs

在官网下载tar包

cd /usr/local/src

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz

tar zxf mysql-8.0.27-linux-glibc2.12-x86_64.tar.xz

重定向mysql

mv mysql-8.0.27-linux-glibc2.12-x86_64 /usr/local/mysql

创建用户

groupadd -r mysql && useradd -r -s /bin/false -g mysql -M mysql

创建数据文件目录

cd /usr/local/mysql

mkdir ./data

编辑主配置文件

vim /etc/my.cnf

[mysqld]

basedir=/usr/local/mysql/

datadir=/usr/local/mysql/data

pid-file=/usr/local/mysql/data/mysql.pid

log-error=/usr/local/mysql/data/mysql.log

socket=/tmp/mysql.sock

设置属主属组

chown -R mysql:mysql /usr/local/mysql

添加环境变量

cat /etc/profile

NGINX_HOME=/usr/local/nginx

MYSQL_HOME=/usr/local/mysql

export PATH=$NGINX_HOME/sbin:$MYSQL_HOME/bin:$PATH

 source /etc/profile

初始化

mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

查询mysql初始密码

#grep "password" /usr/local/mysql/data/mysql.log

2022-09-10T02:14:31.710378Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: O2EGsXmUFu%f

启动脚本

cp support-files/mysql.server /etc/init.d/mysqld

启动

service mysqld start

登录

mysql -uroot  -p

修改密码

alter user root@localhost identified by '123';

4. 安装php

cd /usr/local/src

上传tar包

wget https://www.php.net/distributions/php-7.4.30.tar.gz

解压

tar zxf php-7.4.30.tar.gz

cd php-7.4.30

groupadd -r php && useradd -r -s /bin/false -g php -M php

解决libzip版本不对 

如果报libzip就安装一下

wget https://libzip.org/download/libzip-1.3.2.tar.gz

tar xf libzip-1.3.2.tar.gz

cd libzip-1.3.2

./configure && make && make install

export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"

编译

./configure --prefix=/usr/local/php --with-config-file-path=/etc --with-mhash --with-openssl --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib --enable-bcmath  --enable-gd --with-jpeg --with-freetype  --enable-mbstring --enable-ftp --enable-sockets   --with-gettext --enable-session --with-curl   --enable-fpm --with-fpm-user=php --with-fpm-group=php   --enable-pdo -enable-tokenizer --with-zip

安装

make && make install

复制主配置文件

cp php.ini-production /etc/php.ini

修改配置文件名字

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

环境变量

vim /etc/profile

NGINX_HOME=/usr/local/nginx

MYSQL_HOME=/usr/local/mysql

PHP_HOME=/usr/local/php

export PATH=$NGINX_HOME/sbin:$MYSQL_HOME/bin:$PHP_HOME/bin:$PHP_HOME/sbin:$PATH

设置启动脚本

cd /usr/local/src/php-7.4.30/

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

chmod +x /etc/init.d/php-fpm

 5.编辑nginx配置文件使其支持nginx

vim /usr/local/nginx/conf/nginx.conf

location / {
            root   html;
            index  index.php index.html index.htm;
        }

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;
        }

 编写测试文件

cd /usr/local/nginx/html

看是否支持php

vim test.php

<?php

phpinfo();

?>

看是否支持mysql

vim test1.php

<?php
    $mysqli = new mysqli("localhost", "root", "12345678");
    if(!$mysqli)  {
        echo"database error";
    }else{
        echo"php env successful";
    }
    $mysqli->close();
?> 

浏览器访问 http://ip/test.php

http://ip/test1.php

至此全部完成 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值