centos8 源码部署LNMP

安装nginx1.18

安装依赖

#安装依赖
yum  install epel-release
yum -y update
yum -y install make gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl openssl-devel libxml2 libxslt-devel gd-devel libxml2-devel libpng-devel curl-devel numactl 
#关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
systemctl stop iptables
systemctl disable iptables
#关闭selinux
setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
#设置时区
timedatectl set-timezone Asia/Shanghai
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

开始安装

#创建软件包存放目录
mkdir -p /opt/tools && cd /opt/tools
#创建不能登录的用户
useradd -M -s /sbin/nologin nginx
wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar -xvf nginx-1.18.0.tar.gz
cd nginx-1.18.0
#配置
./configure \
--prefix=/usr/local/nginx \
--user=nginx --group=nginx \
--with-debug \
--with-pcre-jit \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_realip_module \
--with-http_auth_request_module \
--with-http_v2_module \
--with-http_dav_module \
--with-http_slice_module \
--with-threads \
--with-http_addition_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_image_filter_module=dynamic \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_sub_module \
--with-http_xslt_module=dynamic \
--with-stream=dynamic \
--with-stream_ssl_module \
--with-mail=dynamic \
--with-mail_ssl_module \
--with-stream_realip_module \
--with-stream
#编译安装
make -j4 && make install
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
#制作service
cat >>/usr/lib/systemd/system/nginx.service<<EOF
[Unit]                                          
Description=nginx 
After=network.target 

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/bin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP \$MAINPID
ExecStop=/bin/kill -s TERM \$MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF
#刷新文件
systemctl daemon-reload

安装mysql8.0.20

安装依赖

yum install -y cmake ncurses-devel libtirpc-devel
wget https://github.com/thkukuk/rpcsvc-proto/releases/download/v1.4/rpcsvc-proto-1.4.tar.gz
#mysql 下载的是带有boost库的版本
wget http://mirrors.sohu.com/mysql/MySQL-8.0/mysql-boost-8.0.20.tar.gz
#创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统
useradd -M -s /sbin/nologin mysql
mkdir -p /data/mysql 
chown -R mysql:mysql /data/mysql 
mkdir -p /usr/local/mysql 

开始安装

#先编译安装依赖插件 rpcsvc-proto
cd /opt/tools
tar -zxvf rpcsvc-proto-1.4.tar.gz
cd rpcsvc-proto-1.4/ && ./configure && make && make install
cd /opt/tools
#解压mysql
cd /opt/tools
tar -xvf mysql-boost-8.0.19.tar.gz
cd mysql-8.0.19
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DINSTALL_DATADIR=/data/mysql \
-DMYSQL_USER=mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DFORCE_INSOURCE_BUILD=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all \
-DWITH_BOOST=/opt/tools/mysql-8.0.19/boost

#编译安装,时间会等待较久
make -j 2 && make install

初始化mysql

#修改mysql目录权限
chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /usr/local/mysql
chown -R mysql:mysql /data/mysql
chmod -R 755 /data/mysql
#初始化mysql,记住初始化密码
cd /usr/local/mysql/
./bin/mysqld --initialize --user=mysql --datadir=/data/mysql --character-set-server=utf8
2021-04-23T22:28:10.503327Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.19) initializing of server in progress as process 73765
2021-04-23T22:28:10.505204Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2021-04-23T22:28:11.586518Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: P&eis&rt=1&&

创建my.cnf

#mysql 8.0.x默认没有配置文件,我们自己创建一个
cat >/usr/local/mysql/my.cnf <<EOF
[client]
port=3306
socket=/tmp/mysql.sock
[mysqld]
port=3306
user = mysql
socket=/tmp/mysql.sock
tmpdir = /tmp
basedir=/usr/local/mysql
datadir=/data/mysql
key_buffer_size=16M
max_allowed_packet=128M
default_authentication_plugin=mysql_native_password
open_files_limit = 60000
explicit_defaults_for_timestamp
server-id = 1
character-set-server = utf8
log-error=/var/log/mysqld.log
pid-file=/tmp/mysqld.pid
federated
max_connections = 1000
max_connect_errors = 100000
interactive_timeout = 86400
wait_timeout = 86400
sync_binlog=0
back_log=100
default-storage-engine = InnoDB
log_slave_updates = 1
[mysqldump]
quick
[client]
password="123456"
[mysqld-8.0]
sql_mode=TRADITIONAL
[mysqladmin]
force
[mysqld]
key_buffer_size=16M
EOF
ln -s /usr/local/mysql/my.cnf /etc/my.cnf

设置开机启动,创建远程用户

#把Mysql加入系统启动
cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
#增加执行权限
chmod 755 /etc/init.d/mysqld
#加入开机启动
chkconfig mysqld on
#编辑文件
sed -i "46s#basedir=#basedir=/usr/local/mysql#" /etc/init.d/mysqld 
sed -i "47s#datadir=#datadir=/data/mysql#" /etc/init.d/mysqld 

echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
#以下为把myslq的库文件链接到系统默认的位置
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
mkdir /var/lib/mysql
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock

#登录MySQL,修改密码,使用初始化的密码
mysql -uroot -pP&eis&rt=1&&
alter user 'root'@'localhost' identified by '123456';
create user yunwei@'%' identified by '123456';      #创建远程用户
grant all on *.* to yunwei@'%';     #授权
flush privileges;   #刷新

安装PHP7.4.16

安装依赖

yum -y install libtool sqlite-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel

cd /opt/tools  
wget https://www.php.net/distributions/php-7.4.16.tar.gz
#安装oniguruma-6.9.4
wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz
tar -xvf  oniguruma-6.9.4.tar.gz
cd oniguruma-6.9.4/
./autogen.sh && ./configure --prefix=/usr
make && make install

开始安装

cd /opt/tools
tar -xvf php-7.4.16.tar.gz
cd php-7.4.16
#编辑PHP的配置项
./configure --prefix=/usr/local/php \
--with-config-file-path=/etc \
--enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx \
--enable-inline-optimization --disable-debug --disable-rpath \
--enable-shared --enable-soap  --with-xmlrpc \
--with-openssl --with-mhash  --with-sqlite3 \
--with-zlib --enable-bcmath --with-iconv --with-bz2 \
--enable-calendar --with-curl --with-cdb --enable-dom \
--enable-exif --enable-fileinfo --enable-filter \
--enable-ftp  --with-openssl-dir --with-zlib-dir \
--enable-gd-jis-conv --with-gettext --with-gmp --with-mhash \
--enable-json --enable-mbstring --enable-mbregex  \
--enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \
--with-zlib-dir --with-pdo-sqlite --with-readline --enable-session \
--enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg \
--enable-sysvsem --enable-sysvshm --with-xsl  \
--enable-mysqlnd-compression-support --with-pear \
--enable-opcache --disable-fileinfo

#编译安装
make -j 3 && make install 

修改配置文件

#添加环境变量
echo "export PATH=$PATH:/usr/local/php/bin" >> /etc/profile
source /etc/profile
#准备配置文件
cp php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
ln -s /usr/local/php/etc/ /etc/php
#修改 /usr/local/php/etc/php-fpm.conf 运行用户和组改为nginx
chown nginx.nginx /usr/local/php/etc/php-fpm.conf
chown -R nginx.nginx /etc/php
#禁用PHP功能
sed -i "s#disable_functions =#disable_functions =\"passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,wnam,posix_getpwuid, posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname\"#" /etc/php/php.ini 
#支持mysql
sed -i "s#pdo_mysql.default_socket=#pdo_mysql.default_socket=/tmp/mysql.sock#" /etc/php/php.ini
sed -i "s#mysqli.default_socket =#mysqli.default_socket =/tmp/mysql.sock#" /etc/php/php.ini 

#设置开机自启,并启动
cp /opt/tools/php-7.4.16/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
chkconfig php-fpm on
systemctl start php-fpm

修改nginx支持php

#修改nginx
cp /usr/local/nginx/conf/nginx.conf{,.bak}
vim /usr/local/nginx/conf/nginx.conf
...
        location / {
            root   html;
            index  index.html index.htm index.php; #添加 index.php
        }
...
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #将/scripts$fastcgi_script_name修改为$document_root$fastcgi_script_name。
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
...
#检查配置
nginx -t 
systemctl start nginx   #启动nginx

确保服务都成功启动
在这里插入图片描述

测试

#测试
cat > /usr/local/nginx/html/index.php <<eof
<?php
 phpinfo();
 ?>
eof
curl http://localhost/index.php #浏览器访问

在这里插入图片描述

到此 centos8 LNMP 开发环境 到此部署完毕

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值