一、準備
正式開始前,編譯環境gcc、g++等開發庫需要提前安裝。
nginx依賴以下模塊:
gzip模塊需要 zlib 庫
rewrite模塊需要 pcre 庫
ssl 功能需要openssl庫
源碼目錄為:/usr/local/src
1、安裝make
yum -y install gcc automake autoconf libtool make
2、安裝g++
yum install gcc gcc-c++
3、安裝PCRE庫
cd /usr/local/src
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.42.tar.gz
tar -zxvf pcre-8.42.tar.gz
cd pcre-8.42/
./configure
make && make install
出現如下報錯:
make[2]: *** [install-libLTLIBRARIES] Error 1
make[2]: Leaving directory `/usr/local/src/pcre-8.42'
make[1]: *** [install-am] Error 2
make[1]: Leaving directory `/usr/local/src/pcre-8.42'
make: *** [install] Error 2
權限不夠,切換到root,重新make install即可。
4、安裝zlib庫
cd /usr/local/src
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11/
./configure
make && make install
5、安裝OpenSSL庫
cd /usr/local/src
wget http://www.openssl.org/source/openssl-1.1.0h.tar.gz
tar -zxvf openssl-fips-2.0.16.tar.gz
cd openssl-fips-2.0.16/
./config
make && make install
編譯安裝 Openssl 1.1.1 支持國密標準
https://blog.51cto.com/1012682/2380553
6、創建用戶及用戶組
一般為了服務器安全,會指定一個普通用戶權限的賬號做為Nginx的運行角色,這里使用www用戶做為Nginx工作進程的用戶。后續安裝的PHP也以www用戶作為工作進程用戶。
groupadd -r www
useradd -r -g www www
二、NGINX
1、下載
cd /usr/local/src
wget http://nginx.org/download/nginx-1.14.0.tar.gz
tar –zxvf nginx-1.14.0.tar.gz
cd nginx-1.14.0
2、配置
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_mp4_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi
make && make install
nginx編譯選項說明:
--prefix表示nginx要安裝到哪個路徑下,這里指定剛才新建好的/alidata/server目錄下的nginx-1.12.2;
--sbin-path表示nginx的可執行文件存放路徑
--conf-path表示nginx的主配置文件存放路徑,nginx允許使用不同的配置文件啟動,通過命令行中的-c選項
--pid-path表示nginx.pid文件的存放路徑,將存儲的主進程的進程號。安裝完成后,可以隨時改變的文件名 , 在nginx.conf配置文件中使用 PID指令。默認情況下,文件名 為prefix/logs/nginx.pid
--error-log-path表示nginx的主錯誤、警告、和診斷文件存放路徑
--http-log-path表示nginx的主請求的HTTP服務器的日志文件的存放路徑
--user表示nginx工作進程的用戶
--group表示nginx工作進程的用戶組
--with-select_module或--without-select_module表示啟用或禁用構建一個模塊來允許服務器使用select()方法
--with-poll_module或--without-poll_module表示啟用或禁用構建一個模塊來允許服務器使用poll()方法
--with-http_ssl_module表示使用https協議模塊。默認情況下,該模塊沒有被構建。建立并運行此模塊的OpenSSL庫是必需的
--with-pcre表示pcre的源碼路徑,因為解壓后的pcre是放在root目錄下的,所以是/root/pcre-8.41;
--with-zlib表示zlib的源碼路徑,這里因為解壓后的zlib是放在root目錄下的,所以是/root/zlib-1.2.11
--with-openssl表示openssl庫的源碼路徑
配置OK:
Configuration summary
+ using PCRE library: /usr/local/src/pcre-8.42
+ using OpenSSL library: /usr/local/src/openssl-1.1.0h
+ using zlib library: /usr/local/src/zlib-1.2.11
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx"
nginx configuration file: "/usr/local/nginx/nginx.conf"
nginx pid file: "/usr/local/nginx/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "/var/tmp/nginx/client/"
nginx http proxy temporary files: "/var/tmp/nginx/proxy/"
nginx http fastcgi temporary files: "/var/tmp/nginx/fcgi/"
nginx http uwsgi temporary files: "/var/tmp/nginx/uwsgi"
nginx http scgi temporary files: "/var/tmp/nginx/scgi"
3、安裝
make && make install
4、啟動
/usr/local/nginx/sbin/nginx
啟動時報錯:
nginx: [emerg] mkdir() "/var/tmp/nginx/client/" failed (2: No such file or directory)
手動創建該目錄即可:mkdir -p /var/tmp/nginx/client
再次啟動,打開瀏覽器訪問此機器的IP,瀏覽器出現Welcome to nginx! 則表示 Nginx 已經安裝并運行成功。
5、設置軟連接
ln -sf /usr/local/nginx/sbin/nginx /usr/sbin
這樣就可以直接執行nginx來啟動了。
6、檢測nginx
nginx -t
顯示:
nginx: the configuration file /usr/local/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/nginx.conf test is successful
三、PHP
1、安裝PHP需要的常用庫
yum -y install libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel
2、下載
cd /usr/local/src
wget http://cn2.php.net/downloads.php/php-7.2.5.tar.gz
tar -zxvf php-7.2.5.tar.gz
3、配置
./configure --prefix=/usr/local/php \
--with-mysql=mysqlnd \
--enable-mysqlnd \
--with-gd \
--enable-gd-jis-conv \
--enable-fpm
4、安裝
make && make install
安裝信息如下:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/
Installing PHP CLI binary: /usr/local/php/bin/
Installing PHP CLI man page: /usr/local/php/php/man/man1/
Installing PHP FPM binary: /usr/local/php/sbin/
Installing PHP FPM defconfig: /usr/local/php/etc/
Installing PHP FPM man page: /usr/local/php/php/man/man8/
Installing PHP FPM status page: /usr/local/php/php/php/fpm/
Installing phpdbg binary: /usr/local/php/bin/
Installing phpdbg man page: /usr/local/php/php/man/man1/
Installing PHP CGI binary: /usr/local/php/bin/
Installing PHP CGI man page: /usr/local/php/php/man/man1/
Installing build environment: /usr/local/php/lib/php/build/
Installing header files: /usr/local/php/include/php/
Installing helper programs: /usr/local/php/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /usr/local/php/lib/php/
[PEAR] Archive_Tar: upgrade to a newer version (1.4.3 is not newer than 1.4.3)
[PEAR] Console_Getopt: upgrade to a newer version (1.4.1 is not newer than 1.4.1)
[PEAR] Structures_Graph: upgrade to a newer version (1.1.1 is not newer than 1.1.1)
[PEAR] XML_Util: upgrade to a newer version (1.4.2 is not newer than 1.4.2)
[PEAR] PEAR: upgrade to a newer version (1.10.5 is not newer than 1.10.5)
/usr/local/src/php-7.2.5/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers: /usr/local/php/include/php/ext/pdo/
5、添加環境變量
vim /etc/profile
在末尾加入
export PHP_HOME=/usr/local/php
export PATH=/bin:/usr/bin:/usr/sbin:/sbin:$PATH:PHP_HOME/bin:$PHP_HOME/sbin
保存修改后,使用source命令重新加載配置文件:
source /etc/profile
查看環境變量:
echo $PATH
6、配置php-fpm
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
cd php-fpm.d/
cp www.conf.default www.conf
使用vim命令對php-fpm.conf的內容進行如下修改:
pid = /usr/local/php/var/run/php-fpm.pid
使用vim命令對php-fpm.conf的內容進行如下修改:
user = www
group = www
其他配置可根據需求進行修改,比如pm.max_children(php-fpm 能啟動的子進程的最大數量)、pm.start_servers(php啟動時,開啟的子進程的數量)、pm.min_spare_servers(動態方式空閑狀態下的最小php-fpm進程數量)、pm.max_spare_servers(動態方式空閑狀態下的最大php-fpm進程數量)等。
7、啟動php-fpm
/usr/local/php/sbin/php-fpm
可以通過ps aux | grep php查看php進程。
https://www.cnblogs.com/sunshineliulu/p/8991957.html
三、MySQL
https://blog.csdn.net/weixin_33859844/article/details/90948191
https://www.cnblogs.com/yangchunlong/p/8477743.html