lnmp安装

下载安装包:
nginx: wget https://nginx.org/download/nginx-1.9.9.tar.gz
php: wget https://www.php.net/distributions/php-7.4.16.tar.gz
mysql: wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.33.tar.gz
升级apt库: apt-get update
nginx安装:
1、解压安装包 tar -xzvf nginx-1.9.9.tar.gz  &  cd nginx-1.9.9
2、./configure --prefix=/usr/local/nginx
3、make

可能出现的错误
./configure: error: C compiler cc is not found

解决方案:
sudo apt install build-essential  该命令将安装包括gcc,g ++和make。gcc --version 验证是否安装成功

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre= option.

解决方案:sudo apt install  libpcre3 libpcre3-dev

./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib= option.

 解决方案:
        wget http://www.zlib.net/zlib-1.2.11.tar.gz 
        tar -xzvf zlib-1.2.11.tar.gz
        cd zlib-1.2.11
        ./configure
        make && make install

src/core/ngx_murmurhash.c: In function ‘ngx_murmur_hash2’:
src/core/ngx_murmurhash.c:37:11: error: this statement may fall through [-Werror=implicit-fallthrough=]
37 | h ^= data[2] << 16;
| ~^~~~~~~~~~~~~~~
src/core/ngx_murmurhash.c:38:5: note: here
38 | case 2:
| ^~~~
src/core/ngx_murmurhash.c:39:11: error: this statement may fall through [-Werror=implicit-fallthrough=]
39 | h ^= data[1] << 8;
| ~^~~~~~~~~~~~~~
src/core/ngx_murmurhash.c:40:5: note: here
40 | case 1:
| ^~~~
cc1: all warnings being treated as errors
make[1]: *** [objs/Makefile:445:objs/src/core/ngx_murmurhash.o] 错误 1
make[1]: 离开目录“/home/yinhuakai/soft/nginx-1.9.9”
make: *** [Makefile:8:build] 错误 2

解决方案:vim objs/Makefile,去掉CFLAGS中的-Werror,再重新make。(Werror 要求gcc将所有的警告当成错误进行处理)
解决方案2:vim src/os/unix/ngx_user.c 注释该代码片段/* cd.current_salt[0] = ~salt[0];*/

4、make install

cd nginx(cd /usr/local/nginx/sbin )命令:
./nginx 启动
./nginx -s stop 关闭
./nginx -s quit 优雅不安比
./nginx -s reload 重新加载配置文件
./nginx -s reopen   重新打开日志
./nginx -t  检查nginx配置文件是否报错
在/etc/init.d/中创建nginx脚本(代码如下) 使用sysv-rc-conf --add nginx (添加到服务列表);sysv-rc-conf nginx on;(开启自动启动)

#! /bin/sh
###BEGIN INIT INFO
# Provides:     nginx
# Required-Start:  $all
# Required-Stop:   $all
# Default-Start:   2 3 4 5
# Default-Stop:   0 1 6
# Short-Description: starts the nginx web server
# Description:    starts nginx using start-stop-daemon
### END INIT INFO
  
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/nginx/sbin/nginx
NAME=nginx
DESC=nginx
  
test -x $DAEMON || exit 0
  
# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
  . /etc/default/nginx
#    . /usr/local/nginx/conf
fi
  
set -e
  
. /lib/lsb/init-functions
  
case "$1" in
 start)
  echo -n "Starting $DESC: "
  start-stop-daemon --start --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
    --exec $DAEMON -- $DAEMON_OPTS || true
  echo "$NAME."
  ;;
 stop)
  echo -n "Stopping $DESC: "
  start-stop-daemon --stop --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
    --exec $DAEMON || true
  echo "$NAME."
  ;;
 restart|force-reload)
  echo -n "Restarting $DESC: "
  start-stop-daemon --stop --quiet --pidfile \
    /usr/local/nginx/logs/$NAME.pid --exec $DAEMON || true
  sleep 1
  start-stop-daemon --start --quiet --pidfile \
    /usr/local/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
  echo "$NAME."
  ;;
 reload)
   echo -n "Reloading $DESC configuration: "
   start-stop-daemon --stop --signal HUP --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
     --exec $DAEMON || true
   echo "$NAME."
   ;;
 status)
   status_of_proc -p /usr/local/nginx/logs/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?
   ;;
 *)
  N=/etc/init.d/$NAME
  echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2
  exit 1
  ;;
esac
 ;
exit 0

sysv-rc-conf 命令安装:
1、 如果sysv-rc-conf安装失败,则 vim /etc/apt/sources.list 在文件末尾添加:deb http://archive.ubuntu.com/ubuntu/ trusty main universe restricted multiverse
2、apt-get update
3、apt-get install sysv-rc-conf

5、sysv-rc-conf nginx 将nginx 加入到服务列表
6、sysv-rc-conf on nginx   设置nginx开机启动
mysql安装:

安装前准备
apt install cmake
wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
tar -xzvf boost_1_59_0.tar.gz
mkdir -p /usr/local/boost
mv boost_1_59_0 /usr/local/boost/
apt install libssl-dev curl libcurl4-openssl-dev
apt install libncurses-dev
apt install pkg-config
apt-get install libaio-dev
apt-get install libboost-dev
apt-get install libboost-doc

1、 tar -xzvf mysql-5.7.33.tar.gz
2、cd mysql-5.7.33
3、cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/home/mysqlData -DSYSCONFDIR=/usr/local/mysql/conf -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_DEBUG=0 -DMYSQL_MAINTAINER_MODE=0 -DWITH_SSL:STRING=bundled -DWITH_ZLIB:STRING=bundled -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost -DWITH_SSL=system

注:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql 设置安装目录
-DMYSQL_DATADIR=/home/mysqlData 设置数据库存放目录
-DMYSQL_UNIX_ADDR=/home/mysqlData/mysql.sock 设置UNIX socket 目录
-DMYSQL_USER=mysql 设置运行用户
-DDEFAULT_CHARSET=utf8 设置默认字符集,默认latin1
-DEFAULT_COLLATION=utf8_general_ci 设置默认校对规则,默认latin1_general_ci
-DWITH_INNOBASE_STORAGE_ENGINE=1 添加InnoDB引擎支持
-DENABLE_DOWNLOADS=1 自动下载可选文件,比如自动下载谷歌的测试包
-DMYSQL_TCP_PORT=3306 设置服务器监听端口,默认3306
-DSYSCONFDIR=/etc/mysql/conf 设置my.cnf所在目录,默认为安装目录

4、make && make install
5、 groupadd mysql 创建用户组
6、 useradd -r -g mysql -s /bin/false mysql  创建用户 且设置为非登录用户
7、初始化数据库
/usr/local/mysql/bin/mysqld --initialize --user=mysql
/usr/local/mysql/bin/mysql_ssl_rsa_setup
8、cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

vim mysqld
basedir=/usr/local/mysql
datadir=/home/mysqlData

9、sysv-rc-conf  mysqld 添加到服务列表
10、sysv-rc-conf mysqld on 开启启动

添加到环境变量
vim /etc/profile.d/mysql.sh 写入:export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile 是环境变量生效

PHP安装:

安装前准备
groupadd www
useradd -r -g www -s /bin/false www
安装依赖:
apt install curl libcurl4-openssl-dev gcc make zip unzip tar openssl libssl-dev gcc libxml2 libxml2-dev libjpeg-dev libpng-dev lsof libpcre3 libpcre3-dev cron net-tools swig build-essential libffi-dev libbz2-dev libncurses-dev libsqlite3-dev libreadline-dev tk-dev libgdbm-dev libdb-dev libdb++-dev libpcap-dev xz-utils zlib1g zlib1g-dev
apt install libkrb5-dev
apt install libonig-dev
apt install libxslt-dev

1、tar -xzvf php-7.4.16.tar.gz && cd php-7.4.16.
2、./configure --prefix=/usr/local/php74 --with-config-file-path=/usr/local/php74/etc --with-fpm-user=www --with-fpm-group=www --with-curl --with-freetype-dir=/usr/lib --enable-gd --with-gettext --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli=mysqlnd --with-openssl --with-pcre-regex --with-pdo-mysql=mysqlnd --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-mysql=mysqlnd --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip --with-iconv-dir=/usr/local/lib

3、make && make install
4、cp php.ini-development /usr/local/php74/etc/php.ini
   cd /usr/local/php74/etc/
  cp php-fpm.conf.default php-fpm.conf
  cd php-fpm.d/
  cp www.conf.default www.conf

vim php-fpm.conf
去掉 pid = run/php-fpm.pid 之前的分好

5、vim /lib/systemd/system/php-fpm74.service 放入一下代码:

[Unit]
Description=php-fpm74
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/php74/sbin/php-fpm
ExecStop=/bin/pkill -9 php-fpm
PrivateTmp=true
[Install]
WantedBy=multi-user.target

6、vim /etc/init.d php-fpm74 放入一下代码:

#! /bin/sh
 
### BEGIN INIT INFO
# Provides:          php-fpm
# Required-Start:    $remote_fs $network
# Required-Stop:     $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts php-fpm
# Description:       starts the PHP FastCGI Process Manager daemon
### END INIT INFO
 
prefix=/usr/local/php74
exec_prefix=${prefix}
 
php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid
 
 
php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"
 
 
wait_for_pid () {
    try=0
 
    while test $try -lt 35 ; do
 
        case "$1" in
            'created')
            if [ -f "$2" ] ; then
                try=''
                break
            fi
            ;;
 
            'removed')
            if [ ! -f "$2" ] ; then
                try=''
                break
            fi
            ;;
        esac
 
        echo -n .
        try=`expr $try + 1`
        sleep 1
 
    done
 
}
 
case "$1" in
    start)
        echo -n "Starting php-fpm "
 
        $php_fpm_BIN --daemonize $php_opts
 
        if [ "$?" != 0 ] ; then
            echo " failed"
            exit 1
        fi
 
        wait_for_pid created $php_fpm_PID
 
        if [ -n "$try" ] ; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
    ;;
 
    stop)
        echo -n "Gracefully shutting down php-fpm "
 
        if [ ! -r $php_fpm_PID ] ; then
            echo "warning, no pid file found - php-fpm is not running ?"
            exit 1
        fi
 
        kill -QUIT `cat $php_fpm_PID`
 
        wait_for_pid removed $php_fpm_PID
 
        if [ -n "$try" ] ; then
            echo " failed. Use force-quit"
            exit 1
        else
            echo " done"
        fi
    ;;
 
    status)
        if [ ! -r $php_fpm_PID ] ; then
            echo "php-fpm is stopped"
            exit 0
        fi
 
        PID=`cat $php_fpm_PID`
        if ps -p $PID | grep -q $PID; then
            echo "php-fpm (pid $PID) is running..."
        else
            echo "php-fpm dead but pid file exists"
        fi
    ;;
 
    force-quit)
        echo -n "Terminating php-fpm "
 
        if [ ! -r $php_fpm_PID ] ; then
            echo "warning, no pid file found - php-fpm is not running ?"
            exit 1
        fi
 
        kill -TERM `cat $php_fpm_PID`
 
        wait_for_pid removed $php_fpm_PID
 
        if [ -n "$try" ] ; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
    ;;
 
    restart)
        $0 stop
        $0 start
    ;;
 
    reload)
 
        echo -n "Reload service php-fpm "
 
        if [ ! -r $php_fpm_PID ] ; then
            echo "warning, no pid file found - php-fpm is not running ?"
            exit 1
        fi
 
        kill -USR2 `cat $php_fpm_PID`
 
        echo " done"
    ;;
 
    configtest)
        $php_fpm_BIN -t
    ;;
 
    *)
        echo "Usage: $0 {start|stop|force-quit|restart|reload|status|configtest}"
        exit 1
    ;;
 
esac

7、重载进程 systemctl daemon-reload

8、加到服务列表且设置开启自启 :sysv-rc-conf php-fpm74  &  sysv-rc-conf php-fpm74 on
9、设置环境变量

添加到环境变量
vim /etc/profile.d/php.sh 写入:export PATH=$PATH:/usr/local/php74/bin
source /etc/profile 是环境变量生效

你可能感兴趣的:(lnmp安装)