本文檔請用於學習,生產環境謹慎使用php
網絡上有不少關於Windows
或者Linux
下面安裝LNMP
的教程,很是多。可是我仍是選擇本身去一步一步實現,即便我已經按照網上的教程在不一樣系統中裝了N
屢次。爲何?由於不懂。不懂爲何須要那些系統軟件,不懂那些編譯項爲何要加?有何做用?html
幾點建議:vue
咱們把 Laravel
跑起來!mysql
此處文檔是基礎軟件文檔,不是很全,一部分軟件文檔在內容中。linux
# 查看CentOS版本 [root@bogon source]# cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core) [root@bogon source]# cat /proc/version Linux version 3.10.0-957.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) ) #1 SMP Thu Nov 8 23:39:32 UTC 2018
mysql-8.0.17.tar.gz nginx-1.16.1.tar.gz php-7.3.9.tar.gz redis-5.0.5.tar.gz swoole-4.4.4.tgz
系統內置 CURL 命令,因此咱們選擇CURL
下載軟件curl -O xxx
,若是軟件包出現解壓問題,不是由於tar -zxf
解壓不了這個包。而是說明這個包下載的不完整,或者說由於網絡緣由只是一個空包,解決辦法是刪除後從新下載。另外防止資源網站遷移,請使用curl -OL
參數.-L
:跟蹤重定向
國外資源下載太慢,請使用迅雷下載,而後經過scp
上傳到服務器,經常使用參數:nginx
-r
傳輸的對象是目錄-p
指定端口,默認 22使用場景:laravel
scp -p <server port> <server user>@<server ip>:<server path>/<server file> <local path>
這是下載服務器資源,資源將被保存到 <local path>
。scp -p <server port> <local path>/<local file> <server user>@<server ip>:<server path>
這是上傳本地文件到服務器指定路徑。爲何先說這個,爲了給你們提供一個不須要關注 lnmp
系統依賴,而只是編譯安裝 lnmp
的方法。c++
咱們通常裝完軟件,都會設置環境變量,以便咱們能愉快方便的使用這款軟件,若是咱們不使用環境變量,咱們就會到安裝目錄找到可執行文件,執行命令。web
若是一款軟件有多個版本,咱們會把它們安裝到不一樣的路徑,這樣咱們就能夠分別到不一樣版本的目錄,啓動它們。若是你對php進行過多版本的安裝和使用那將會很是熟悉。scl
會經過動態加載環境變量實現按需加載。redis
固然 scl
和 yum groupinstall Development tools
它們兩做用一致,可是 scl
能夠按需加載是它不能比擬的。
你們能夠看一下 enable
(工具包安裝完後生成的全局變量文件) 文件內容:
[root@bogon bld]# cat /opt/rh/devtoolset-8/enable # General environment variables export PATH=/opt/rh/devtoolset-8/root/usr/bin${PATH:+:${PATH}} export MANPATH=/opt/rh/devtoolset- ...
Software Collections give you the power to build, install, and use multiple versions of software on the same system, without affecting system-wide installed packages.
yum install centos-release-scl
scl --list
啓用軟件集合: 四種方式(文檔中三種,其它一種)
scl action software_collection_1 software_collection_2 'command --argument'
scl enable software_collection_1 software_collection_2 bash
。就是給你從新打開了一個子 shell
,給你加載了他安裝的軟件的環境變量。scl enable software_collection_1 'perl --version'
永久性地將 DTS
添加到您的開發環境中
使用首選文本編輯器,將如下行添加到如下結尾 ~/.bashrc: source scl_source enable devtoolset-8 註銷並從新登陸後,您能夠經過運行which g++ 或 驗證DTS GCC是否在您的路徑中 g++ --version
scl
儘管有三種不一樣的使用方式,原理基本一致。
這款管理工具剛開始是不知道的,爲了解決mysql
編譯時gcc
版本過低才知道。只在mysql
編譯時使用了,在其它地方都沒有使用。不是說這工具很差用,只是爲了給大家多看看咱們用yum
,scl
時看不到的依賴問題,使用後你會發現這工具真香!當系統須要任何這個工具包中須要的依賴時,你均可以經過上述四種使用方式,來解決依賴。
推薦使用,尤爲是安裝大家不太瞭解的依賴軟件時,比方說:gcc
,後面有使用scl升級gcc的過程
在安裝開始以前,咱們先建立三個用戶: www
web
mysql
和對應的用戶組,分別給php-fpm
nginx
mysql
使用
在Linux
中安裝服務的時候,儘量的爲服務建立用戶和用戶組,方便管理這些服務,比方說:設置服務能夠訪問的目錄權限,文件權限等
groupadd www groupadd web groupadd mysql useradd -r -g mysql -s /bin/false mysql useradd -r -g www -s /bin/false www useradd -r -g web -s /bin/false web
參數解釋:
-g
指定組-s
設置 shell
/bin/false
指的是不能用這個用戶訪問系統資源,包括login
,sftp
,ftp
等等/usr/sbin/nologin
僅僅限制用戶登錄-r
系統帳戶:默認沒有家目錄,UID 不會大於1000 也就是 0-999。不加 -r
就會建立用戶帳戶,UID
默認從1000
開始,默認有家目錄,能夠經過 -M
禁止建立家目錄友情提示:下列安裝的全部服務,在安裝完以後先不要急着啓動,先修改配置,而後啓動。否則你若是啓動後再修改,你可能還須要清理服務默認生成的文件。LNMP
通常默認須要生成文件的配置項不是日誌目錄就是數據存儲目錄。
咱們先練個手按照安裝文檔上的示例來安裝,命令以下:
./configure --sbin-path=/usr/local/nginx/nginx \ --conf-path=/usr/local/nginx/nginx.conf \ --pid-path=/usr/local/nginx/nginx.pid \ --with-http_ssl_module \ --with-pcre=../pcre-8.43 \ --with-zlib=../zlib-1.2.11
PCRE 做用說明(來自官網)
sets the path to the sources of the PCRE library. The library distribution (version 4.4 — 8.43) needs to be downloaded from the PCRE site and extracted. The rest is done by nginx’s ./configure and make. The library is required for regular expressions support in the location directive and for the ngx_http_rewrite_module module.
ZLIB 做用說明(來自官網)
sets the path to the sources of the zlib library. The library distribution (version 1.1.3 — 1.2.11) needs to be downloaded from the zlib site and extracted. The rest is done by nginx’s ./configure and make. The library is required for the ngx_http_gzip_module module.
下載時注意nginx
要求的版本
# 解壓並進入 tar -zxf nginx-1.16.1.tar.gz tar -zxf pcre-8.43.tar.gz tar -zxf zlib-1.2.11.tar.gz cd nginx-1.16.1 # 執行編譯 [root@bogon nginx-1.16.1]# ./configure --sbin-path=/usr/local/nginx/nginx \ --conf-path=/usr/local/nginx/nginx.conf \ --pid-path=/usr/local/nginx/nginx.pid \ --with-http_ssl_module \ --with-pcre=../pcre-8.43 \ --with-zlib=../zlib-1.2.11 # 查看 NGINX_ERROR_1 checking for OS '+' Linux 3.10.0-957.el7.x86_64 x86_64 # + 號有排版問題用雙引號引發來 checking for C compiler ... not found ./configure: error: C compiler cc is not found # 從新執行編譯 # 查看 NGINX_ERROR_2 ./configure: error: SSL modules require the OpenSSL library. You can either do not enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using --with-openssl=<path> option. # 從新執行編譯 # 執行 make && make install [root@bogon nginx-1.16.1]# make && make install # 出現這個說明安裝沒問題: make[1]: Leaving directory `/root/source/nginx-1.16.1'
至此咱們就Nginx
編譯安裝完成,示例編譯參數不是很符合咱們生產環境,由於全部的東西都設置到一個目錄下。咱們在生產環境部署時,儘量區分目錄,方便維護,因此咱們使用Nginx
默認編譯參數。
默認編譯,配置一下安裝目錄便可(指定一下用戶和用戶組):
./configure --prefix=/usr/local/nginx --user=web --group=web --with-http_ssl_module --with-pcre=../pcre-8.43 --with-zlib=../zlib-1.2.11 make && make install # 安裝完文件目錄 drwxr-xr-x. 2 root root 4096 Sep 2 23:04 conf drwxr-xr-x. 2 root root 40 Sep 2 23:04 html drwxr-xr-x. 2 root root 6 Sep 2 23:04 logs drwxr-xr-x. 2 root root 19 Sep 2 23:04 sbin
更多編譯參數咱們能夠經過 ./configure --help
查看
由於一些緣由,好比: 開啓其餘nginx
功能,咱們須要從新編譯,步驟以下:
make clean
./configure xxx
make && make install
nginx
服務啓動命令,請自行了解: /usr/local/nginx/sbin/nginx -h
NGINX_ERROR_1./configure: error: C compiler cc is not found
yum install -y gcc-c++
這個包支持編譯C
和C++
程序,防止代碼中有C++
代碼
維基百科:
NGINX_ERROR_2
./configure: error: SSL modules require the OpenSSL library. You can either do not enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using --with-openssl=<path> option.
Nginx
開啓了openssl
可是這個須要系統安裝openssl
執行yum install -y openssl openssl-devel
維基百科:
devel 包主要是供開發用,至少包括如下2個東西:
- 頭文件
- 連接庫
有的還含有開發文檔或演示代碼。
以glib
和glib-devel
爲例:
若是你安裝基於glib
開發的程序,只須要安裝glib
包就好了
可是若是你要編譯使用了glib
的源代碼(也就是咱們常見的依賴XXX
),則須要安裝glib-devel
(XXX-devel
)
通常咱們不是用軟件而只是安裝依賴的話,咱們儘可能直接安裝XXX-devel
基於默認編譯安裝(feiyanshi )
啓動
/usr/local/nginx/sbin/nginx
默認讀取編譯時指定的Nginx
配置文件,沒指定配置文件路徑默認讀取安裝目錄下的conf/nginx.conf
文件,若是想修改配置文件請使用 -c
參數: /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
[root@bogon nginx]# /usr/local/nginx/nginx [root@bogon nginx]# ps -ef | grep nginx root 32167 1 0 12:45 ? 00:00:00 nginx: master process /usr/local/nginx/nginx nobody 32168 32167 0 12:45 ? 00:00:00 nginx: worker process root 32170 11602 0 12:45 pts/0 00:00:00 grep --color=auto nginx
經過服務器IP訪問,出現訪問拒絕問題,處理方式以下:
查看防火牆狀態:
[root@bogon nginx]# firewall-cmd --state running
關掉:systemctl stop firewalld.service
(生產環境上注意,你應該選擇開啓 80
端口)
再次訪問!
php-fpm
php
,因此建立安裝目錄時,通常指定版本做爲安裝目錄,好比: /usr/local/php/7.3/
[root@bogon source]# tar -zxf php-7.3.9.tar.gz [root@bogon source]# cd php-7.3.9 [root@bogon php-7.3.9]# ./configure --prefix=/usr/local/php/7.3 --enable-fpm --with-fpm-user=www --with-fpm-group=www [root@bogon php-7.3.9]# make && make install # PHP_ERROR_1 configure: error: libxml2 not found. Please check your libxml2 installation. # 從新執行編譯 # 出現 Thank you for using PHP. 說明編譯沒有問題繼續... make && make install # 出現 Installing PDO headers: /usr/local/php/7.3/include/php/ext/pdo/ 說明安裝成功
configure: error: libxml2 not found. Please check your libxml2 installation.
yum install -y libxml2 libxml2-devel
libxml2
時,系統提示我已經存在,但php
編譯時還報錯,說明編譯安裝時的依賴包須要安裝devel
版本 咱們依次解決以下問題:
解決PHP_FPM
可執行文件找不到
--sbindir=/usr/local/php/7.3/sbin
或者 --sbindir=/usr/local/php/7.3/bin
(統一管理)[root@bogon bin]# pwd /usr/local/php/7.3/bin [root@bogon bin]# cp /root/source/php-7.3.9/sapi/fpm/php-fpm ./
解決PHP_FPM
只能經過 kill 命令關閉(建議你們瞭解一下進程管理),重啓
[root@bogon php-7.3.9]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [root@bogon php-7.3.9]# chmod 755 /etc/init.d/php-fpm [root@bogon etc]# /etc/init.d/php-fpm -h Usage: /etc/init.d/php-fpm {start|stop|force-quit|restart|reload|status|configtest}
php.ini
--with-config-file-path
,那麼就複製解壓後的軟件包中的php.ini-development || php.ini-production
到php
默認配置文件所在路徑,可經過 php --ini
查看.ini
文件的區別,在配置文件中有說明,關鍵詞:About this file
php-fpm.conf
/usr/local/php/7.3/etc/
下有個php-fpm.conf.default
複製一份,更名爲php-fpm.conf
cp php-fpm.conf.default php-fpm.conf
www.conf
/usr/local/php/7.3/etc/php-fpm.d/
下有個www.conf.default
複製一份,更名爲www.conf
cp www.conf.default www.conf
簡單說一下,由於要存放代碼
不少人喜歡把代碼放到家目錄,這樣很很差,一我的用無所謂,可是服務器由於有不少人管理,因此,咱們通常建立一個單獨的文件進行存放,還有一點,這個文件最好掛載到一個單獨的磁盤,方便說句備份,不要和系統文件打交道。
# 查看一下有無空閒磁盤 [root@bogon conf]# fdisk -l Disk /dev/sda: 549.8 GB, 549755813888 bytes, 1073741824 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x0000e7dc Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 1073741823 535821312 8e Linux LVM Disk /dev/sdb: 549.8 GB, 549755813888 bytes, 1073741824 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/centos-swap: 4294 MB, 4294967296 bytes, 8388608 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/centos-home: 490.7 GB, 490695819264 bytes, 958390272 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes
能夠看到個人/dev/sdb
沒有掛載使用,咱們來掛載一下:
分區我就不說了,本身找教程搞進行了
mkdir /data
mkfs.ext4 /dev/sdb
格式化mount /dev/sdb /data
掛載查看UUID
[root@bogon data]# blkid /dev/mapper/centos-root: UUID="4ea36a4c-e3b5-4872-acbd-b874dc8a984f" TYPE="xfs" /dev/sda2: UUID="6Rgi32-MsJD-akY4-4LwU-cILp-cxgM-resSuQ" TYPE="LVM2_member" /dev/sda1: UUID="751824de-225b-44d7-8e1f-8349e189b665" TYPE="xfs" /dev/mapper/centos-swap: UUID="70e13f7a-c6b5-4b79-af93-2bd5ecdb1d3c" TYPE="swap" /dev/sr0: UUID="2018-11-25-23-54-16-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" /dev/sdb: UUID="86e8ad23-b083-4749-98d4-6baaf231af56" TYPE="ext4" /dev/mapper/centos-home: UUID="317e45d6-c7c9-476a-84c3-eadca5133e21" TYPE="xfs"
修改/etc/fstab
,在最後增長以下內容,開機自動掛載
# 具體的參數本身看一下手冊 UUID=86e8ad23-b083-4749-98d4-6baaf231af56 /data ext4 defaults 0 0
目錄建立
[root@bogon data]# tree . ├── logs │ ├── mysql │ ├── nginx │ └── php ├── lost+found └── website └── nginx-php └── index.php
index.php
文件中寫入<?php phpinfo();
安裝測試
[root@bogon php-7.3.9]# /usr/local/php/7.3/bin/php -v PHP 7.3.9 (cli) (built: Sep 2 2019 23:31:10) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.9, Copyright (c) 1998-2018 Zend Technologies
啓動php-fpm
測試
[root@bogon php-fpm.d]# /etc/init.d/php-fpm start Starting php-fpm done [root@bogon php-fpm.d]# ps -ef | grep php-fpm root 3540 1 0 03:20 ? 00:00:00 php-fpm: master process (/usr/local/php/7.3/etc/php-fpm.conf) www 3541 3540 0 03:20 ? 00:00:00 php-fpm: pool www www 3542 3540 0 03:20 ? 00:00:00 php-fpm: pool www root 3567 11602 0 03:21 pts/0 00:00:00 grep --color=auto php-fpm
nginx && php-fpm
測試
配置一個server
,配置文件使用laradock
中的laravel.conf.example
server { listen 80; listen [::]:80; # For https # listen 443 ssl; # listen [::]:443 ssl ipv6only=on; # ssl_certificate /etc/nginx/ssl/default.crt; # ssl_certificate_key /etc/nginx/ssl/default.key; server_name nginx_php.test; root /data/website/nginx-php; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php$is_args$args; } location ~ \.php$ { try_files $uri /index.php =404; fastcgi_pass php-upstream; fastcgi_index index.php; fastcgi_buffers 16 16k; fastcgi_buffer_size 32k; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #fixes timeouts fastcgi_read_timeout 600; include fastcgi_params; } location ~ /\.ht { deny all; } location /.well-known/acme-challenge/ { root /var/www/letsencrypt/; log_not_found off; } # 改一下日至存放目錄,順便改一下 nginx.conf 中的Nginx日誌存放目錄 error_log /data/logs/nginx/nginx_php_error.log; access_log /data/logs/nginx/nginx_php_access.log; }
接下來:
建立一個upstream.conf
文件,用以統一管理php-fpm
連接,負載均衡
[root@bogon conf]# pwd /usr/local/nginx/conf [root@bogon conf]# cat upstream.conf upstream php-upstream { server 127.0.0.1:9000; }
建立vhost
目錄,並修改nginx.conf
,在http {}
模塊中最下面增長以下配置
vim /usr/local/nginx/nginx.conf; include upstream.conf; include vhost/*.conf;
vhost
文件夾中建立nginx_php_test.conf
文件,上面的nginx
配置粘貼進去hosts
ip server_name
,好比:192.168.2.41 nginx_php.test
nginx_php.test
查看日誌
[root@bogon nginx]# tree . ├── access.log ├── error.log ├── nginx_php_access.log └── nginx_php_error.log '0' directories, 4 files # 格式問題 0 引號引發來 [root@bogon nginx]# pwd /data/logs/nginx
至此,測試完畢
redis
安裝比較簡單,直接按照下載頁面的說明安裝便可
[root@bogon redis-5.0.5]# make test cd src && make test make[1]: Entering directory `/root/source/redis-5.0.5/src' CC Makefile.dep make[1]: Leaving directory `/root/source/redis-5.0.5/src' make[1]: Entering directory `/root/source/redis-5.0.5/src' You need tcl 8.5 or newer in order to run the Redis test make[1]: *** [test] Error 1 make[1]: Leaving directory `/root/source/redis-5.0.5/src' make: *** [test] Error 2 yum install -y tcl
想了解TCL的,請點擊此連接
注意點:
README.md
文件,文檔中有不少安裝的注意事項,和教程。redis
編譯時若是想指定安裝目錄,請執行 make PREFIX=/some/other/directory install
redis
有一個安裝腳本,文檔解釋的也很清楚
Make install will just install binaries in your system, but will not configure
init scripts and configuration files in the appropriate place. This is not
needed if you want just to play a bit with Redis, but if you are installing
it the proper way for a production system, we have a script doing this
for Ubuntu and Debian systems:
% cd utils % ./install_server.sh
The script will ask you a few questions and will setup everything you need
to run Redis properly as a background daemon that will start again on
system reboots.c
啥做用呢,我替大家提早執行了一下(網上一堆 新建 etc 複製 redis.conf 到 etc 安裝教程,不想說啥):
[root@bogon redis-5.0.5]# cd utils/ [root@bogon utils]# ./install_server.sh Welcome to the redis service installer This script will help you easily set up a running redis server Please select the redis port for this instance: [6379] Selecting default: 6379 # 指定端口,默認 6379 Please select the redis config file name [/etc/redis/6379.conf] Selected default - /etc/redis/6379.conf # 指定配置文件,默認就是這個 Please select the redis log file name [/var/log/redis_6379.log] /data/logs/redis/redis_6379.log # 日誌文件 Please select the data directory for this instance [/var/lib/redis/6379] /data/redis/7379 # 數據持久化 Please select the redis executable path [/usr/local/bin/redis-server] /usr/local/redis/bin/redis-server Selected config: Port : 6379 Config file : /etc/redis/6379.conf Log file : /data/logs/redis/redis_6379.log Data dir : /data/redis/7379 Executable : /usr/local/redis/bin/redis-server Cli Executable : /usr/local/bin/redis-cli Is this ok? Then press ENTER to go on or Ctrl-C to abort. Copied /tmp/6379.conf => /etc/init.d/redis_6379 # 幫你建立了服務器啓動腳本 Installing service... Successfully added to chkconfig! Successfully added to runlevels 345! Starting Redis server... # 幫你啓動了 redis 服務 Installation successful!
redis
服務的啓動和中止
[root@bogon utils]# /etc/init.d/redis_6379 -h Please use start, stop, restart or status as first argument
下載地址
爲啥要選這個?由於咱們要從源碼編譯安裝。Centos
又不在列表中,因此選擇通用。最後篩選出來兩個包,一個包包含了咱們不知道的東西,一個純淨版,下載純淨版。
Mysql 源安裝官網安裝教程,建議你們讀一遍,由於在百度的時候,發現一個無奈的事情:
The InnoDB, MyISAM, MERGE, MEMORY, and CSV engines are mandatory (always compiled into the server) and need not be installed explicitly.
文檔中明確說,這幾個數據庫引擎是強制安裝的,網上一大堆設置cmake
參數開啓這四個引擎的安裝教程。若是你須要關閉默認引擎或者安裝新引擎,我以爲能夠設置參數。
就是Mysql官網的先決條件,在這裏簡單說一下。
GNU make
對應的命令是 gmake
編譯。感興趣的能夠了解一下 cmake make gmake
他們的歷史,不一樣,使用場景(這裏有個坑,下文有說明)。CMake has bootstrapped. Now run gmake.
推薦使用的是 gmake
cmake
時設置cmake
參數 -DWITH_BOOST=<指定解壓後目錄>
cmake
時設置cmake
參數-DDOWNLOAD_BOOST=1 -DWITH_BOOST=<指定自動下載後存儲路徑>
ncurses-devel
,命令:yum install -y ncurses-devel
mysql
的編譯安裝參數文檔 tar -zxf mysql-8.0.17.tar.gz cd mysql-8.0.17 mkdir bld # 建一個編譯文件存儲目錄(剛開始不信邪,確實挺多文件的) cd bld # 這裏咱們能夠再加一個編譯參數 MYSQLX_UNIX_ADDR & MYSQL_UNIX_ADDR # 由於 mysql 默認的 socket file 位置在 /tmp/ 目錄下,可是 mysql 配置文件中倒是在 /var/lib/mysql/ 目錄下爲了保持一致。固然你也能夠修改配置文件。 # 關於 mysqlx 是個什麼鬼,你們在編譯參數頁面搜索一下 -DWITH_MYSQLX 關鍵詞,下面有說明。 cmake .. -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<指定自動下載後存儲路徑> -DMYSQLX_UNIX_ADDR=file_name -DMYSQL_UNIX_ADDR=file_name make && make install # 強烈建議使用 -j 參數,否則很慢 # 來自官方文檔 # Postinstallation setup shell> cd /usr/local/mysql shell> mkdir mysql-files shell> chown mysql:mysql mysql-files shell> chmod 750 mysql-files shell> bin/mysqld --initialize --user=mysql shell> bin/mysql_ssl_rsa_setup shell> bin/mysqld_safe --user=mysql & # Next command is optional shell> cp support-files/mysql.server /etc/init.d/mysql.server
cmake 沒裝 依賴安裝中已解釋
[root@bogon bld]# cmake .. -- Running cmake version 2.8.12.2 CMake Warning at CMakeLists.txt:43 (MESSAGE): Please use cmake3 rather than cmake on this platform -- Please install cmake3 (yum install cmake3) CMake Error at CMakeLists.txt:73 (CMAKE_MINIMUM_REQUIRED): CMake 3.5.1 or higher is required. You are running version 2.8.12.2 -- Configuring incomplete, errors occurred!
ncurses 沒裝 依賴安裝中已解釋
-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
GCC
版本過低
CMake Error at cmake/os/Linux.cmake:59 (MESSAGE): GCC 5.3 or newer is required (-dumpversion says 4.8.5) Call Stack (most recent call first): CMakeLists.txt:424 (INCLUDE) -- Configuring incomplete, errors occurred! See also "/root/source/mysql-8.0.17/bld/CMakeFiles/CMakeOutput.log".
思考:
GCC
版本過高的話,以前使用低版本GCC
編譯的軟件是否會存在問題?有興趣的能夠測試一下GCC
瞭解的不多人,編譯安裝我以爲有不少隱患,因此不建議編譯安裝。有興趣的能夠研究一下這個 Software Collections 再次提醒,編譯本身不熟悉的軟件有風險,請謹慎
SCL(Software Collections)
升級 gcc gcc
在這個開發者軟件工具集中,若是你不想爲了裝個gcc而把整個工具集都裝上,請使用 yum search devtoolset-8
而後將列出來的包安裝上便可,例如:
yum search devtoolset-8 devtoolset-8-gcc.x86_64 : GCC version 8 devtoolset-8-gcc-c++.x86_64 : C++ support for GCC version 8 yum install devtoolset-8-gcc-c++ devtoolset-8-gcc
這裏有一篇文章,講了什麼是軟件集合,以及怎麼使用
# 下面這個命令就別敲了,人家都明說了,ON RHEL,網上又是一堆互相抄襲,不知道看一下文檔會不會死 yum-config-manager --enable rhel-server-rhscl-7-rpms # 要在系統上啓用對軟件集的支持,以便啓用和構建軟件集,您須要安裝軟件包scl-utils和scl-utils-build yum install scl-utils scl-utils-build yum install devtoolset-7 scl enable devtoolset-7 bash # 測試 [root@bogon source]# gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-7/root/usr --mandir=/opt/rh/devtoolset-7/root/usr/share/man --infodir=/opt/rh/devtoolset-7/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-plugin --with-linker-hash-style=gnu --enable-initfini-array --with-default-libstdcxx-abi=gcc4-compatible --with-isl=/builddir/build/BUILD/gcc-7.3.1-20180303/obj-x86_64-redhat-linux/isl-install --enable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux Thread model: posix gcc version 7.3.1 20180303 (Red Hat 7.3.1-5) (GCC) # 執行 Mysql 的編譯安裝
編譯安裝 官方文檔,文檔中有五個步驟你們仔細看
9.2
(生產環境請注意)。執行./contrib/download_prerequisites
下載依賴包,就是官方文檔中提到的幾個依賴庫:
MPFR Library version 2.4.2 (or later)
MPC Library version 0.8.1 (or later)
isl Library version 0.15 or later.
zstd Library.
mkdir gcc-build
&& cd gcc-build
../configure --prefix=/usr/local/gcc/9.2.0 --enable-checking=release --enable-languages=c,c++ --disable-multilib
–enable-checking=release
增長一些檢查,也能夠–disable-checking
生成的編譯器在編譯過程當中不作額外檢查 –enable-languages=c,c++
設置gcc
支持的編程語言–disable-multilib
取消多目標庫編譯(取消32位庫編譯)prefix
參數建議加上,否則你都不知道編譯安裝完的路徑make && make install
建議增長 -j
參數 否則真的很慢升級gcc動態庫(生產環境請備份)動態鏈接器維基百科 ldconfig詳解
# 備份,沒有對應的二進制可執行文件就跳過 mv /usr/bin/gcc /usr/bin/gcc.old mv /usr/bin/g++ /usr/bin/g++.old mv /usr/bin/c++ /usr/bin/c++.old mv /usr/bin/cpp /usr/bin/cpp.old mv /usr/bin/gcov /usr/bin/gcov.old # 將新的二進制文件連接過去 ln -sf /usr/local/gcc/9.2.0/bin/* /usr/bin/ ldconfig # 將新的動態庫路徑寫入到 ld.so.conf [root@localhost gcc-build-9.2.0]# echo /usr/local/gcc/9.2.0/lib64 >> /etc/ld.so.conf # 執行 [root@localhost gcc-build-9.2.0]# ldconfig ldconfig: /usr/local/gcc/9.2.0/lib64/libstdc++.so.6.0.27-gdb.py is not an ELF file - it has the wrong magic bytes at the start. # 刪除 libstdc++.so.6.0.27-gdb.py [root@localhost gcc-build-9.2.0]# rm -rf /usr/local/gcc/9.2.0/lib64/libstdc++.so.6.0.27-gdb.py [root@localhost gcc-build-9.2.0]# ldconfig [root@localhost gcc-build-9.2.0]# cp /usr/local/gcc/9.2.0/lib64/libstdc++.so.6.0.27 /lib64/ [root@localhost gcc-build-9.2.0]# cd /lib64/ [root@localhost lib64]# ln -sf libstdc++.so.6.0.27 libstdc++.so.6
可能的報錯
# 1 [root@bogon gcc-9.2.0]# ./contrib/download_prerequisites gmp-6.1.0.tar.bz2: OK mpfr-3.1.4.tar.bz2: OK mpc-1.0.3.tar.gz: OK isl-0.18.tar.bz2: OK tar (child): lbzip2: Cannot exec: No such file or directory tar (child): Error is not recoverable: exiting now tar: Child returned status 2 tar: Error is not recoverable: exiting now error: Cannot extract package from gmp-6.1.0.tar.bz2 # 解決辦法:`yum install -y bzip2` # 2 -- Running cmake version 3.15.2 -- Could NOT find Git (missing: GIT_EXECUTABLE) -- MySQL 8.0.17 -- The C compiler identification is unknown CMake Error at CMakeLists.txt:310 (PROJECT): The CMAKE_C_COMPILER: /usr/bin/cc is not a full path to an existing compiler tool. Tell CMake where to find the compiler by setting either the environment variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to the compiler, or to the compiler name if it is in the PATH. # 解決辦法 [root@bogon bld]# whereis gcc gcc: /usr/lib/gcc /usr/local/bin/gcc /usr/local/lib/gcc /usr/libexec/gcc [root@bogon bld]# ln -s /usr/local/bin/gcc /usr/bin/cc # 3 configure: error: no acceptable C compiler found in $PATH # 解決辦法 [root@localhost gcc-build-9.2.0]# yum install -y gcc-c++
gcc
命令時請退出終端從新登錄或者直接經過執行 source ~/.bashrc 二者原理一致make install
錯誤:
查了官方論壇有這個問題的描述,可是沒有解決方法:
/root/source/mysql-8.0.17/storage/innobase/buf/buf0buf.cc: In function ‘void buf_pool_create(buf_pool_t*, ulint, ulint, std::mutex*, dberr_t&)’: /root/source/mysql-8.0.17/storage/innobase/buf/buf0buf.cc:1220:44: error: ‘SYS_gettid’ was not declared in this scope 1220 | setpriority(PRIO_PROCESS, (pid_t)syscall(SYS_gettid), -20); | ^~~~~~~~~~ [ 95%] Building CXX object storage/innobase/CMakeFiles/innobase.dir/data/data0type.cc.o [ 95%] Building CXX object storage/innobase/CMakeFiles/innobase.dir/dict/dict0boot.cc.o [ 95%] Building CXX object storage/innobase/CMakeFiles/innobase.dir/dict/dict0crea.cc.o make[2]: *** [storage/innobase/CMakeFiles/innobase.dir/buf/buf0buf.cc.o] Error 1 make[2]: *** Waiting for unfinished jobs.... make[1]: *** [storage/innobase/CMakeFiles/innobase.dir/all] Error 2 make: *** [all] Error 2
通過測試發現不是版本的問題,這個問題產生的緣由是沒有更新動態連接庫。
登錄錯誤 Segmentation fault
這個錯誤是這樣產生的:
官方提示咱們用 GUN make
A good make program. Although some platforms come with their own make implementations, it is highly recommended that you use GNU make 3.75 or higher. It may already be available on your system as gmake. GNU make is available from http://www.gnu.org/software/m...
而後查找資料發現,在centos7
中 GNU make
就是gmake
,因此我用 gmake
進行了編譯,最後在執行mysql -uroot -p
時報錯了。後來用 make
編譯就沒這個錯了
可是我看了 gmake 和make的版本信息,一毛同樣,使人困惑:
[root@bogon mysql]# make -v GNU Make 4.2.1 Built for x86_64-redhat-linux-gnu Copyright (C) 1988-2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. [root@bogon mysql]# gmake -v GNU Make 4.2.1 Built for x86_64-redhat-linux-gnu Copyright (C) 1988-2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
根據需求修改 /etc/my.cnf
。強調一點,只要是mysql
服務可能用到的文件或者目錄,請設置用戶用戶組爲mysql
,否則可能會致使mysql
執行失敗
chown mysql:mysql mysql-files chmod 750 mysql-files
數據目錄初始化bin/mysqld --initialize --user=mysql
建議你們仔細讀一下文檔, 要了解:初始化過程當中mysql
作了哪些工做?默認的賬號密碼是什麼?初始化都有那些參數?爲何初始化失敗了?
友情提示:初始化後的密碼在日誌中,具體文檔
2019-09-06T03:29:36.109917Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release. 2019-09-06T03:29:36.110151Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.17) initializing of server in progress as process 11886 2019-09-06T03:29:38.652784Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: MppJU;a1Yh;t # password 2019-09-06T03:29:40.142765Z 0 [System] [MY-013170] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.17) initializing of server has completed
啓動
cp support-files/mysql.server /etc/init.d/mysql.server /etc/init.d/mysql.server start
登錄數據庫
[root@bogon mysql]# /usr/local/mysql/bin/mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.17 Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> exit Bye
修改默認密碼
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root-password';
[root@bogon mysql]# ps -ef | grep mysql root 12396 1 0 Sep05 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/bogon.pid
到此,mysql
安裝完畢
Laravel
跑起來composer
# 要嫌絕對路徑煩人,大家能夠把`php`可執行文件連接到`/usr/local/bin`,或者本身把`php`可執行文件路徑添加到環境變量 # 下面的報錯可能都是 XX 功能沒開啓,XX擴展沒裝。我就不解釋了。 # 命令中沒有 cd 命令,bash 名稱後的路徑變化 [root@bogon website]# /usr/local/php/7.3/bin/php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');" Warning: copy(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in Command line code on line 1 Warning: copy(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in Command line code on line 1 Warning: copy(https://install.phpcomposer.com/installer): failed to open stream: No such file or directory in Command line code on line 1 [root@bogon php-7.3.9]# make clean find . -name \*.gcno -o -name \*.gcda | xargs rm -f find . -name \*.lo -o -name \*.o | xargs rm -f find . -name \*.la -o -name \*.a | xargs rm -f find . -name \*.so | xargs rm -f find . -name .libs -a -type d|xargs rm -rf rm -f libphp7.la sapi/cli/php sapi/cgi/php-cgi sapi/fpm/php-fpm modules/* libs/* # openssl Nginx 編譯的時候已經講了,這裏就很少說了 [root@bogon php-7.3.9]# ./configure --prefix=/usr/local/php/7.3 --enable-fpm --with-fpm-user=www --with-fpm-group=www --sbindir=/usr/local/php/7.3/bin --with-config-file-path=/usr/local/php/7.3/etc --with-openssl [root@bogon php-7.3.9]# make && make install [root@bogon website]# /usr/local/php/7.3/bin/php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');" [root@bogon website]# /usr/local/php/7.3/bin/php composer-setup.php Downloading... Composer (version 1.9.0) successfully installed to: /data/website/composer.phar Use it: php composer.phar Some settings on your machine may cause stability issues with Composer. If you encounter issues, try to change the following: The zlib extension is not loaded, this can slow down Composer a lot. If possible, install it or recompile php with --with-zlib A php.ini file does not exist. You will have to create one. If you can not modify the ini file, you can also run `php -d option=value` to modify ini values on the fly. You can use -d multiple times. # 缺乏 zlib,編譯項上增長 --with-zlib。zlib 上文有維基百科連接 [root@bogon php-7.3.9]# make clean [root@bogon php-7.3.9]# ./configure --prefix=/usr/local/php/7.3 --enable-fpm --with-fpm-user=www --with-fpm-group=www --sbindir=/usr/local/php/7.3/bin --with-config-file-path=/usr/local/php/7.3/etc --with-openssl --with-zlib [root@bogon php-7.3.9]# make && make install [root@bogon website]# /usr/local/php/7.3/bin/php composer-setup.php All settings correct for using Composer Downloading... Composer (version 1.9.0) successfully installed to: /data/website/composer.phar Use it: php composer.phar [root@bogon website]# /usr/local/php/7.3/bin/php -r "unlink('composer-setup.php');" # 全局安裝,意思就是添加到環境變量下,就能夠全系統使用 [root@bogon website]# mv composer.phar /usr/local/bin/composer [root@bogon website]# composer -v Do not run Composer as root/super user! See https://getcomposer.org/root for details ______ / ____/___ ____ ___ ____ ____ ________ _____ / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/ / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ / \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/ /_/ Composer version 1.9.0 2019-08-02 20:55:32
Laravel
[root@bogon website]# composer config -g repo.packagist composer https://packagist.phpcomposer.com [root@bogon website]# composer create-project --prefer-dist laravel/laravel blog Installing laravel/laravel (v6.0.1) - Installing laravel/laravel (v6.0.1): Loading from cache Created project in blog > @php -r "file_exists('.env') || copy('.env.example', '.env');" Loading composer repositories with package information Updating dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages. Problem 1 - laravel/framework v6.0.1 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system. - laravel/framework v6.0.0 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system. - laravel/framework 6.x-dev requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system. - Installation request for laravel/framework ^6.0 -> satisfiable by laravel/framework[6.x-dev, v6.0.0, v6.0.1]. # 缺乏 mbstring擴展 [root@bogon php-7.3.9]# ./configure --prefix=/usr/local/php/7.3 --enable-fpm --with-fpm-user=www --with-fpm-group=www --sbindir=/usr/local/php/7.3/bin --with-config-file-path=/usr/local/php/7.3/etc --with-openssl --with-zlib --enable-mbstring [root@bogon php-7.3.9]# make clean [root@bogon php-7.3.9]# make && make install [root@bogon website]# rm -rf blog/ [root@bogon website]# composer create-project --prefer-dist laravel/laravel blog # Laravel 6.0 如下的版本在這個階段可能會報 curl 找不到的問題,不急,往下看 # 在 nginx vhost目錄下建立一個 server(也就是增長一個XX.conf文件),修改 server_name self_laravel.test # 注意命名:通常格式,<企業名|項目名><_><框架名稱><_><開發環境>.conf,比方說:self_laravel_test.conf 這樣方便管理。隨後的日誌,數據庫名稱等也但願以一樣的命名方式命名。server_name 我建議按照 <企業名|項目名><_><框架名稱><.><開發環境> 命名。 # 連接 mysql, 建立一個數據庫 CREATE DATABASE self_laravel_test CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci 這個數據庫的命名呢,我建議仍是按照 nginx conf 文件的命名來,已有項目就不要求了。 # 修改 .env 文件 # laravel 6.0 之後沒有 make:auth 命令,請執行 composer require laravel/ui && php artisan ui vue --auth 這兩個命令 # php artisan migrate 執行數據遷移 [root@bogon blog]# php artisan migrate Illuminate\Database\QueryException : could not find driver (SQL: select * from information_schema.tables where table_schema = alone_laravel_test and table_name = migrations and table_type = 'BASE TABLE')
pdo-mysql
驅動沒裝:
在這裏我簡要說明一下 php
數據庫驅動:pdo
是 php
數據庫抽象層,讓你可使用一套代碼鏈接不一樣的數據庫,也能夠理解爲,有了pdo
你就能夠經過pdo
函數鏈接pdo
支持的數據庫,可是你仍是須要有項目所需的數據庫驅動。比方說mysql
,你須要安裝mysql
的驅動,你才能經過pdo
函數鏈接mysql
。固然,你能夠不是用pdo
,而是經過mysql
驅動提供的方法鏈接mysql
。php
默認安裝了pdo
和pdo-sqlite
因此咱們按需安裝。
相關文檔在這裏:數據庫擴展
在該項目中,咱們須要安裝mysql
的擴展和pdo-mysql
擴展,php關於mysql
的擴展也有不少,咱們選擇php
官方編寫的mysql
擴展mysqlnd。pdo-mysql
是pdo
對mysql
的抽象。詳細信息請多查看文檔。
[root@bogon php-7.3.9]# ./configure --prefix=/usr/local/php/7.3 --enable-fpm --with-fpm-user=www --with-fpm-group=www --sbindir=/usr/local/php/7.3/bin --with-config-file-path=/usr/local/php/7.3/etc --with-openssl --with-zlib --enable-mysqlnd --with-pdo-mysql=mysqlnd [root@bogon php-7.3.9]# make clean [root@bogon php-7.3.9]# make && make install [root@bogon php-7.3.9]# php -m | grep pdo pdo_mysql pdo_sqlite [root@bogon blog]# php artisan migrate Illuminate\Database\QueryException : SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from information_schema.tables where table_schema = alone_laravel_test and table_name = migrations and table_type = 'BASE TABLE')
關於這個錯誤,Changes in MySQL 8.0.4 (2018-01-23, Release Candidate) 文章中有明確的說明。
簡單來講就是身份驗證插件更新了,可是 mysqlnd
這個擴展尚未更新。
因此咱們選擇設置mysql
的身份驗證插件爲老插件(全局方式),固然咱們也能夠在建立新用戶時,指定身份驗證插件IDENTIFIED WITH mysql_native_password
(局部),固然也可使用其餘支持新身份驗證的mysql
驅動,它是誰呢?mysqli
。mysqli
是mysql
的加強版(加強了啥,本身google
一下)。它們兩個是mysql
官方給php
寫的api
(這是文檔:MySQL PHP API ),上面用的mysqlnd
是php
官方用C
寫的api
。至於mysqlnd
和mysqli
還有啥區別,本身研究吧。
咱們選用第一種方式:
vi /etc/my.cnf # 在[mysqld]標籤下,增長以下內容: default_authentication_plugin=mysql_native_password [root@bogon blog]# /etc/init.d/mysql.server restart Shutting down MySQL. SUCCESS! Starting MySQL.. SUCCESS! # 是否是還報錯?爲啥?由於 root 帳戶的 身份驗證插件默認是 caching_sha2_password mysql> select plugin from user where user = 'root'; +-----------------------+ | plugin | +-----------------------+ | caching_sha2_password | +-----------------------+ 1 row in set (0.00 sec) mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH 'mysql_native_password'; Query OK, 0 rows affected (0.01 sec) mysql> select plugin from user where user = 'root'; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root'; Query OK, 0 rows affected (0.00 sec) mysql> select plugin from user where user = 'root'; +-----------------------+ | plugin | +-----------------------+ | mysql_native_password | +-----------------------+ 1 row in set (0.00 sec) mysql> exit Bye [root@bogon blog]# php artisan migrate Migration table created successfully. Migrating: 2014_10_12_000000_create_users_table Migrated: 2014_10_12_000000_create_users_table (0.12 seconds) Migrating: 2014_10_12_100000_create_password_resets_table Migrated: 2014_10_12_100000_create_password_resets_table (0.02 seconds) Migrating: 2019_08_19_000000_create_failed_jobs_table Migrated: 2019_08_19_000000_create_failed_jobs_table (0.01 seconds)
curl
擴展安裝(此次沒遇見curl擴展問題,但也是常用的擴展):
# 首先,安裝 curl-devel yum install -y curl-devel # 找到 libcurl 位置 whereis curl # 而後增長 --with-curl ./configure --prefix=/usr/local/php/7.3 --enable-fpm --with-fpm-user=www --with-fpm-group=www --sbindir=/usr/local/php/7.3/bin --with-config-file-path=/usr/local/php/7.3/etc --with-openssl --with-zlib --enable-mysqlnd --with-pdo-mysql=mysqlnd --with-curl=/usr/include/curl make clean make && make install php -m | grep curl
根據不一樣的業務,會安裝不一樣的擴展,官方擴展 php
給出了編譯參數,經常使用擴展 php
軟件包中有個ext
目錄,所有在裏面,省去了下載的步驟,和一些非官方的擴展安裝方式一致。非官方擴展沒法經過編譯參數安裝,例如: swoole
。接下來咱們看看這類擴展如何安裝:swoole
擴展安裝( 官方文檔 ):
[root@bogon source]# tar -zxf swoole-4.4.5.tgz [root@bogon source]# cd swoole-4.4.5 [root@bogon swoole-4.4.5]# /usr/local/php/7.3/bin/phpize Configuring for: PHP Api Version: 20180731 Zend Module Api No: 20180731 Zend Extension Api No: 320180731 Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script. # 上文已經給出維基百科,這裏咱們用 yum 安裝一下,感興趣的 本身去編譯安裝 [root@bogon php-7.3.9]# yum install -y autoconf [root@bogon swoole-4.4.5]# /usr/local/php/7.3/bin/phpize Configuring for: PHP Api Version: 20180731 Zend Module Api No: 20180731 Zend Extension Api No: 320180731 [root@bogon swoole-4.4.5]# ./configure --with-php-config=/usr/local/php/7.3/bin/php-config [root@bogon swoole-4.4.5]# make && make install # 將 extension=swoole.so 添加到 php.ini 最後一行,最好給個標籤 [swoole] [root@bogon php-7.3.9]# vi /usr/local/php/7.3/etc/php.ini [root@bogon php-7.3.9]# php -m | grep swoole swoole [root@bogon php-7.3.9]# php -i | grep swoole swoole Author => Swoole Team <team@swoole.com> swoole.display_errors => On => On swoole.enable_coroutine => On => On swoole.enable_library => On => On swoole.enable_preemptive_scheduler => Off => Off swoole.unixsock_buffer_size => 8388608 => 8388608 swoole.use_shortname => On => On OLDPWD => /root/source/swoole-4.4.5 $_SERVER['OLDPWD'] => /root/source/swoole-4.4.5
確保咱們的服務已經所有啓動: php
, mysql
, nginx
, redis
[root@bogon utils]# ps -ef | grep nginx && ps -ef | grep php && ps -ef | grep redis && ps -ef | grep mysql root 5546 2417 0 03:17 pts/1 00:00:00 grep --color=auto nginx root 15038 1 0 02:06 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx web 15039 15038 0 02:06 ? 00:00:00 nginx: worker process root 5548 2417 0 03:17 pts/1 00:00:00 grep --color=auto php root 27051 1 0 02:15 ? 00:00:00 php-fpm: master process (/usr/local/php/7.3/etc/php-fpm.conf) www 27052 27051 0 02:15 ? 00:00:00 php-fpm: pool www www 27053 27051 0 02:15 ? 00:00:00 php-fpm: pool www root 5508 1 0 02:59 ? 00:00:01 /usr/local/redis/bin/redis-server 127.0.0.1:6379 root 5550 2417 0 03:17 pts/1 00:00:00 grep --color=auto redis root 5552 2417 0 03:17 pts/1 00:00:00 grep --color=auto mysql root 20299 1 0 Sep06 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/bogon.pid mysql 20466 20299 0 Sep06 ? 00:19:53 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/logs/mariadb/mariadb.log --pid-file=/data/mysql/bogon.pid --socket=/tmp/mysql.sock
有點醜,哈哈。應該是沒執行npm
相關命令。
一直很想寫這麼一篇文章或者說一直想把複製粘貼的命令弄懂。歷時五天,所有實踐了一遍,大體瞭解了一遍,我以爲很好。寫這篇文章不是爲了讓大家複製粘貼,而是順着這一條線,好好研究一翻。文中給出了不少文檔連接,但願你們在以後的工做中,學會查閱文檔,不要一味的百度,google
。
最後,還有一些東西沒寫,還有不少東西不是很清楚,比方說:各類優化參數,各類編譯參數,各類依賴等等。還有一些話來不及說,還有一些擔憂,還有不少說得不對的地方,不可能十全十美,但願你們見諒,歡迎提出意見和建議。
祝君:不要放棄一顆追求真相的心。
不喜勿噴,轉載請標明出處。