ubuntu 20.04上搭建LNMP环境的方法步骤

简单说明

由于之前是用Centos7搭建的,后来使用ubuntu 20.04的系统做为个人开发环境,所以想在ubuntu上也搭建一下环境,和Centos有一些小区别所以记录一下仅供学习。

安装前准备

下载软件:
php:7.3.18
nginx:1.18.0
mariadb:10.5.4

解压文件:

tar zxf php-7.3.18.tar.gz
tar zxf mariadb-10.5.4.tar.gz
tar zxf nginx-1.18.0.tar.gz

ubuntu 20.04上搭建LNMP环境的方法步骤

安装Nginx

sudo groupadd -r nginx && sudo useradd -r -g nginx -s /sbin/nologin -d /usr/local/nginx nginx
sudo apt install -y libpcre3-dev zlib1g-dev
cd /home/allen/下载/nginx-1.18.0
./configure --user=nginx --group=nginx
make -j 4 && sudo make install
sudo /usr/local/nginx/sbin/nginx -t
#nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
#nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
sudo mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.back
sudo vim /usr/local/nginx/conf/nginx.conf

user nginx;
worker_processes 4;
events {
  worker_connections 1024;
}
http {
  include    mime.types;
  default_type application/octet-stream;
  sendfile  >ubuntu 20.04上搭建LNMP环境的方法步骤

安装Mariadb

sudo rm -rf /etc/mysql
sudo apt remove -y mysql-common
sudo apt autoremove -y
sudo apt install -y cmake libncurses5-dev libgnutls28-dev
sudo groupadd -r mysql && sudo useradd -r -g mysql -s /sbin/nologin -d /usr/local/mariadb mysql
sudo mkdir -p /data/db /var/log/mariadb
cd /home/allen/下载/mariadb-10.5.4/
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb -DMYSQL_DATADIR=/data/db -DSYSCONFDIR=/etc -DWITHOUT_TOKUDB=1 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci
make -j 4 && sudo make install
sudo /usr/local/mariadb/scripts/mysql_install_db --user=mysql --datadir=/data/db
sudo vim /etc/my.cnf

[mysqld]
datadir = /data/db
socket = /tmp/mysql.sock
# 建议禁用符号链接,防止各类安全风险
symbolic-links = 0
collation-server = utf8mb4_general_ci
init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4

[mysql]
default-character-set = utf8mb4

[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4

[mysqld_safe]
log-error = /var/log/mariadb/mariadb.log
pid-file = /var/run/mariadb/mariadb.pid

sudo cp /usr/local/mariadb/support-files/mysql.server /etc/init.d/mariadb

sudo vim /etc/profile.d/mariadb.sh
export PATH=$PATH:/usr/local/mariadb/bin/

sudo chmod 0777 /etc/profile.d/mariadb.sh
source /etc/profile.d/mariadb.sh

sudo /etc/init.d/mariadb start
#Starting mariadb (via systemctl): mariadb.service.

sudo /usr/local/mariadb/bin/mysql_secure_installation 	 

#NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
#   SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

#In order to log into MariaDB to secure it, we'll need the current
#password for the root user. If you've just installed MariaDB, and
#haven't set the root password yet, you should just press enter here.

#Enter current password for root (enter for none): 
#OK, successfully used password, moving>ubuntu 20.04上搭建LNMP环境的方法步骤

安装PHP

sudo apt install -y libxml2-dev libssl-dev libbz2-dev libcurl4-gnutls-dev libjpeg-dev libpng-dev pkg-config libxslt1-dev libzip-dev libfreetype6-dev libfontconfig1-dev autoconf
sudo groupadd -r php && sudo useradd -r -g php -s /sbin/nologin -d /usr/local/php php
sudo vim /etc/sudoers
php   ALL=(ALL:ALL) ALL
cd /home/allen/下载/php-7.3.18/


./configure --prefix=/usr/local/php \--exec-prefix=/usr/local/php --with-fpm-user=php --with-fpm-group=php --enable-zip --with-curl --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-mysqli --with-openssl --with-pdo-mysql --with-pdo-sqlite --with-pear --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-bcmath --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-fpm --with-freetype-dir --with-gd --with-libxml-dir --with-pcre-regex --enable-libxml --enable-zip --with-png-dir --with-jpeg-dir

ubuntu 20.04上搭建LNMP环境的方法步骤

扫一扫手机访问