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

源碼安裝

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
--with-fpm-user=nobody --with-fpm-group=nobody 設置爲www用戶也能夠
  • 編譯和安裝
make && make install
  • 複製配置文件到php的配置目錄
cp php.ini-development /usr/local/php72/lib/php.ini
注意目錄的對應,生產環境的爲php.ini-production

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組和用戶php

    groupadd -r www && useradd -r -g www -s /bin/false -M www
  • 建立緩存目錄html

    mkdir /var/tmp/nginx
  • 配置mysql

    ./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支持
  • 編譯安裝nginx

    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

輸出如下內容c++

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' git

Alternatively you can run:
'./bin/mysql_secure_installation' github

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.redis

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

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
相關文章
相關標籤/搜索