学习是一个逐步发现自己无知的过程!

二进制搭建LNMP

配置阿里源

# 进入目录
cd /etc/yum.repos.d

# 备份
mv CentOS-Base.repo CentOS-Base.repo.bak

# 下载阿里源
wget http://mirrors.aliyun.com/repo/Centos-7.repo

# 更改名字
sudo mv Centos-7.repo ./CentOS-Base.repo


# yum clean all
# yum makecache
# yum update

关闭防火墙

systemctl stop firewalld.service
systemctl disable firewalld.service

关闭selinux

# 临时关闭
setenforce 0
sed 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config

安装Nginx步骤

安装GCC编译器

yum install gcc gcc-c++ -y

下载Nginx-1.12.2并创建www用户

wget http://nginx.org/download/nginx-1.12.2.tar.gz 
useradd -M -s /sbin/nologin www

安装Nginx支持包并解压

yum install -y pcre-devel zlib-devel openssl-devel
tar zxf nginx

编译Nginx

cd nginx-1.12.2
./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module   --with-http_addition_module --with-http_sub_module  --with-http_flv_module --with-http_mp4_module --with-pcre --with-http_ssl_module --with-http_gzip_static_module  --user=www ;make && make install

设置Nginx软连接

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

# 启动
nginx

# 检查服务
netstat -lntp |grep 80

升级到Nginx-1.18.0

wget  http://nginx.org/download/nginx-1.18.0.tar.gz
tar xvf nginx-1.18.0.tar.gz
# 升级前版本检查
nginx -V

编译安装更新

cd nginx-1.18.0

./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module   --with-http_addition_module --with-http_sub_module  --with-http_flv_module --with-http_mp4_module --with-pcre --with-http_ssl_module --with-http_gzip_static_module  --user=www ;make && make install

# 升级后版本检查
nginx -V

升级后检查服务是否正常

netstat -lntp |grep 80

安装Mysql

先删除系统自带的数据库

rpm -qa |grep mariadb
rpm -qa |grep mysql
# 删除
rpm -e mysql --nodeps
rmp -e mariadb --nodeps

下载二进制包

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
# 解压二进制包
tar zxf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz

安装前准备

创建工作目录

# 将解压的二进制包拷贝到/usr/local/mysql下
mv mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz  mkdir /usr/local/mysql
# 创建data目录与log目录
mkdir /usr/local/mysql/data 
mkdir /usr/local/mysql/log
chmod 755 /usr/local/mysql/data/

设置环境变量与创建用户组

# 设置环境变量
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile && source /etc/profile
# 创建用户组与用户
groupadd mysql && useradd -r -g mysql -s /bin/false mysql

创建Mysql主配置文件

# 备份原始主配置文件
cp /etc/my.cnf  /etc/my.cnf.bak

vim /etc/my.cnf
[client]  
socket=/usr/local/mysql/mysql.sock  
[mysqld]  
basedir=/usr/local/mysql  
datadir=/usr/local/mysql/data  
pid-file=/usr/local/mysql/data/mysqld.pid  
socket=/usr/local/mysql/mysql.sock  
log_error=/usr/local/mysql/log/mysql.err

设置权限并初始化Mysql

cd /usr/local/mysql
chmod 750 data/ && chown -R mysql . && chgrp -R mysql . && bin/mysqld --initialize --user=mysql

创建Mysql启动脚本

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld service mysqld start
# 检查启动
netstat -lntp |grep 3306

安装PHP

解决PHP依赖关系

yum -y install libxml2-devel libcurl-devel openssl-devel bzip2-devel

下载libmcrypt

# 下载
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
# 解压
tar zxf libmcrypt-2.5.7.tar.gz

编译安装

cd libmcrypt-2.5.7
./configure --prefix=/usr/local/libmcrypt && make && make install

下载并编译PHP

# 下载(官方提示:当前最稳定的版本)
wget https://www.php.net/distributions/php-7.4.13.tar.gz
# 解压
tar zxf php-7.4.13.tar.gz

解决安装依赖

yum -y install openssl-devel curl-devel db4-devel libjpeg-devel libpng-devel libXpm-devel gmp-devel libc-client-devel openldap-devel unixODBC-devel postgresql-devel sqlite-devel aspell-devel net-snmp-devel libxslt-devel pcre-devel mysql-devel net-snmp-devel libxslt-devel libacl-devel systemtap kernel-devel yum-utils systemtap-sdt-devel freetype freetype-devel mcrypt libmcrypt-devel mhash php-pgsql

开始编译

[liu@xin php-7.4.13]# ./configure --prefix=/usr/local/php7.4 --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-iconv-dir=/usr --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-pgsql=pgsqlnd --with-pgsql=pgsqlnd --with-curl --enable-gd --with-xpm --with-jpeg --with-png-dir --with-freetype --with-xmlrpc --with-fpm-user=www --with-fpm-group=www --with-fpm-acl --with-tsrm-pthreads --with-gettext --with-zlib --with-kerberos=/usr --with-openssl --with-mhash --enable-calendar --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-bcmath --enable-exif --enable-ftp --enable-mbstring --enable-shmop --enable-sockets --enable-dtrace --enable-soap --with-zip --enable-gd-native-ttf --enable-opcache --enable-xml --enable-mbregex --enable-inline-optimization --enable-pcntl --enable-pdo --enable-maintainer-zts --enable-fpm --disable-rpath --disable-fileinfo && make && make install
赞(0)
未经允许不得转载:劉大帥 » 二进制搭建LNMP

你的评论可能会一针见血! 抢沙发

登录

找回密码

注册