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=<path> 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=<path> 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 是环境变量生效

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,125评论 6 498
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,293评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,054评论 0 351
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,077评论 1 291
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,096评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,062评论 1 295
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,988评论 3 417
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,817评论 0 273
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,266评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,486评论 2 331
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,646评论 1 347
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,375评论 5 342
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,974评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,621评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,796评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,642评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,538评论 2 352

推荐阅读更多精彩内容