centos7.4原始碼安裝php,swoole,nginx,redis,mariadb

seeli發表於2019-01-19

原始碼安裝

1. 檔案下載

1.1 下載PHP原始碼

  • php.net
    下載 php-7.2.7.tar.gz

1.2 下載swoole原始碼

1.3 下載redis原始碼

1.4 下載hiredis原始碼

1.5 下載nginx原始碼

1.6 下載mariadb原始碼

1.7 zip包解壓命令

unzip packagename.zip -d ./dir 

1.8 tar.gz包解壓命令

tar -zxvf packagename.tar.gz

2. 安裝

2.1 安裝前的準備

  • 安裝GCC
yum install gcc
  • 安裝autoconf
yum install -y autoconf
  • 安裝pcre
yum install -y pcre pcre-devel
  • 安裝zlib
yum install -y zlib zlib-devel
  • 安裝需要的擴充套件
yum install libxml2 libxml2-devel openssl openssl-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libmcrypt libmcrypt-devel -y
  • 安裝swoole安裝時需要的擴充套件
yum install glibc-headers
yum install gcc-c++ 

2.2 安裝PHP

在php原始碼目錄中執行以下操作

  • 執行./configure 命令
./configure --prefix=/usr/local/php72 --with-mysqli --with-pdo-mysql --with-jpeg-dir --with-png-dir  --with-iconv-dir --with-freetype-dir --with-zlib --with-libxml-dir --with-gd --with-openssl --with-mhash --with-curl --with-pear --with-fpm-user=nobody --with-fpm-group=nobody --enable-bcmath --enable-soap --enable-zip --enable-fpm --enable-mbstring --enable-sockets --enable-opcache --enable-pcntl --enable-simplexml --enable-xml --disable-fileinfo --disable-rpath 
  • 編譯和安裝
make && make install
  • 複製配置檔案到php的配置目錄
cp php.ini-development /usr/local/php72/lib/php.ini

注意目錄的對應

2.3 安裝swoole

在swoole原始碼目錄中

  • 執行phpize
/usr/local/php72/bin/phpize 
  • 執行./configure
 ./configure 

如果提示:Cannot find php-config. Please use –with-php-config=PATH
則使用: ./configure –with-php-config=/usr/local/php72/bin/php-config

  • 編譯和安裝
make && make install

php開啟swoole擴充套件

vim /usr/local/php72/lib/php.ini

搜尋”;extension=”,在最後一個被搜尋到的地方新增extension=swoole.so

  • 檢查swoole擴充套件是否被安裝上
/usr/local/php72/bin/php -ir | grep swoole

輸出一下內容為正常:
swoole
swoole support => enabled
swoole.aio_thread_num => 2 => 2
swoole.display_errors => On => On
swoole.fast_serialize => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608
swoole.use_namespace => On => On
swoole.use_shortname => On => On
PWD => /root/swoole-src-4.0.1
$_SERVER[`PWD`] => /root/swoole-src-4.0.1

2.4 安裝redis

在redis原始碼目錄

  • 安裝到指定目錄
make PREFIX=/usr/local/redis install

2.5 安轉hiredis

在hiredis原始碼目錄中

  • 編譯和安裝
 make && make install

2.6 安裝nginx

  • 建立www組和使用者

    groupadd -r www && useradd -r -g www -s /bin/false -M www
  • 建立快取目錄

    mkdir /var/tmp/nginx
  • 配置

    ./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --pid-path=/usr/local/nginx/conf/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_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/fastcgi --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-http_stub_status_module --with-http_ssl_module --user=www --group=www

    2019.01.25 新增安裝時ssl支援

  • 編譯安裝

    make && make install

2.7 安裝mariadb

  • 安裝依賴
yum install -y libaio  libaio-devel  bison  bison-devel  zlib-devel  openssl openssl-devel  ncurses  ncurses-devel libcurl-devel libarchive-devel  boost  boost-devel  lsof  wget gcc  gcc-c++ make cmake perl kernel-headers kernel-devel  pcre-devel
  • 建立mysql組和使用者
groupadd -r mysql
useradd -r -g mysql -s /sbin/nologin -d /usr/local/mysql -M mysql
  • 建立安裝目錄
mkdir -p /usr/local/mysql
  • 建立資料存放目錄
mkdir -p /data/mysql
  • 修改資料存放目錄的所屬
chown -R mysql:mysql /data/mysql

在mariadb原始碼目錄

  • cmake
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql 
 -DMYSQL_DATADIR=/data/mysql 
 -DSYSCONFDIR=/etc 
 -DWITHOUT_TOKUDB=1 
 -DWITH_INNOBASE_STORAGE_ENGINE=1 
 -DWITH_ARCHIVE_STPRAGE_ENGINE=1 
 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 
 -DWIYH_READLINE=1 
 -DWIYH_SSL=system 
 -DVITH_ZLIB=system 
 -DWITH_LOBWRAP=0 
 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock 
 -DDEFAULT_CHARSET=utf8 
 -DDEFAULT_COLLATION=utf8_general_ci

重新執行cmake命令需要執行:rm -f CMakeCache.txt

  • 編譯安裝
make && make install

在mariadb的安裝目錄(cd /usr/local/mysql/)

  • 使用 mysql 使用者執行指令碼, 安裝資料庫到資料庫存放目錄
scripts/mysql_install_db --user=mysql --datadir=/data/mysql

輸出以下內容

Installing MariaDB/MySQL system tables in `/data/mysql` …
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !

To do so, start the server, then issue the following commands:
`./bin/mysqladmin` -u root password `new-password`
`./bin/mysqladmin` -u root -h VM_0_4_centos password `new-password`

Alternatively you can run:
`./bin/mysql_secure_installation`

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd `.` ; ./bin/mysqld_safe –datadir=`/data/mysql`

You can test the MariaDB daemon with mysql-test-run.pl
cd `./mysql-test` ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB`s strong and vibrant community:
https://mariadb.org/get-invol…

  • 初始化mysql
./bin/mysql_secure_installation
  • 檢視命令幫助
/usr/local/mysql/bin/mysqld --verbose --help
/usr/local/mysql/bin/mysql --help
  • 暫未解決my.cnf的預設配置檔案找不到的問題
  • 神奇的支援檔案
support-files/

可以用該資料夾中的檔案對mysql進行管理

2.8 debian發行版安裝PHP7

  • 安裝依賴
sudo apt-get install -y libxml2-dev build-essential openssl libssl-dev libcurl4-gnutls-dev libjpeg-dev libpng-dev libmcrypt-dev libreadline6 libreadline6-dev curl libfreetype6-dev
  • configure
./configure --prefix=/usr/local/php7.2 --with-mysqli --with-pdo-mysql --with-jpeg-dir --with-png-dir --with-iconv-dir --with-freetype-dir --with-zlib --with-libxml-dir --with-gd --with-openssl --with-mhash --with-curl --with-pear --with-fpm-user=nobody --with-fpm-group=nobody --enable-bcmath --enable-soap --enable-zip --enable-fpm --enable-mbstring --enable-sockets --enable-opcache --enable-pcntl --enable-simplexml --enable-xml --disable-fileinfo --disable-rpath
  • 編譯安裝
sudo make && sudo make install

相關文章