下載安裝包:
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
升級(jí)apt庫(kù): 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
可能出現(xiàn)的錯(cuò)誤
./configure: error: C compiler cc is not found
解決方案:
sudo apt install build-essential 該命令將安裝包括gcc,g ++和make碑韵。gcc --version 驗(yàn)證是否安裝成功
./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] 錯(cuò)誤 1
make[1]: 離開目錄“/home/yinhuakai/soft/nginx-1.9.9”
make: *** [Makefile:8:build] 錯(cuò)誤 2
解決方案:vim objs/Makefile叁怪,去掉CFLAGS中的-Werror,再重新make森缠。(Werror 要求gcc將所有的警告當(dāng)成錯(cuò)誤進(jìn)行處理)
解決方案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 啟動(dòng)
./nginx -s stop 關(guān)閉
./nginx -s quit 優(yōu)雅不安比
./nginx -s reload 重新加載配置文件
./nginx -s reopen 重新打開日志
./nginx -t 檢查nginx配置文件是否報(bào)錯(cuò)
在/etc/init.d/中創(chuàng)建nginx腳本(代碼如下) 使用sysv-rc-conf --add nginx (添加到服務(wù)列表);sysv-rc-conf nginx on;(開啟自動(dòng)啟動(dòng))
#! /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 加入到服務(wù)列表
6瓷马、sysv-rc-conf on nginx 設(shè)置nginx開機(jī)啟動(dòng)
mysql安裝:
安裝前準(zhǔn)備
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 設(shè)置安裝目錄
-DMYSQL_DATADIR=/home/mysqlData 設(shè)置數(shù)據(jù)庫(kù)存放目錄
-DMYSQL_UNIX_ADDR=/home/mysqlData/mysql.sock 設(shè)置UNIX socket 目錄
-DMYSQL_USER=mysql 設(shè)置運(yùn)行用戶
-DDEFAULT_CHARSET=utf8 設(shè)置默認(rèn)字符集,默認(rèn)latin1
-DEFAULT_COLLATION=utf8_general_ci 設(shè)置默認(rèn)校對(duì)規(guī)則端盆,默認(rèn)latin1_general_ci
-DWITH_INNOBASE_STORAGE_ENGINE=1 添加InnoDB引擎支持
-DENABLE_DOWNLOADS=1 自動(dòng)下載可選文件怀骤,比如自動(dòng)下載谷歌的測(cè)試包
-DMYSQL_TCP_PORT=3306 設(shè)置服務(wù)器監(jiān)聽端口费封,默認(rèn)3306
-DSYSCONFDIR=/etc/mysql/conf 設(shè)置my.cnf所在目錄,默認(rèn)為安裝目錄
4蒋伦、make && make install
5弓摘、 groupadd mysql 創(chuàng)建用戶組
6、 useradd -r -g mysql -s /bin/false mysql 創(chuàng)建用戶 且設(shè)置為非登錄用戶
7痕届、初始化數(shù)據(jù)庫(kù)
/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 添加到服務(wù)列表
10研叫、sysv-rc-conf mysqld on 開啟啟動(dòng)
添加到環(huán)境變量
vim /etc/profile.d/mysql.sh 寫入:export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile 是環(huán)境變量生效
PHP安裝:
安裝前準(zhǔn)備
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锈至、重載進(jìn)程 systemctl daemon-reload
8奔穿、加到服務(wù)列表且設(shè)置開啟自啟∩茸 :sysv-rc-conf php-fpm74 》炱洹& sysv-rc-conf php-fpm74 on
9、設(shè)置環(huán)境變量
添加到環(huán)境變量
vim /etc/profile.d/php.sh 寫入:export PATH=$PATH:/usr/local/php74/bin
source /etc/profile 是環(huán)境變量生效