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
  • 编译和安装
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

相关推荐