本文以Centos 7.1+Php 7.1.3+Mysql5.7.17为例,介绍Centos7+Php7+Mysql5.7+Nginx 1.10.3源码安装实战部署的过程。
一.准备工作
软件获取
二.安装Mysql
安装目录/usr/local/mysql
数据库目录/data/mysqldb
1.安装编译工具
yum -y install cmake gcc-c++ ncurses-devel perl-Data-Dumper boost boost-doc boost-devel
2.安装boost库
mysql5.7需要boost库支持,目前不支持1.5.9以上版本
解压到/usr/local/boost
3.Cmake & install
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLAT
ION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/data/mysqldb -DMYSQL_TCP_POR
T=3306 -DENABLE_DOWNLOADS=1 -DWITH_BOOST=/usr/local/boost
make && make install
4.目录权限
mkdir -p /data/mysqldb
cd /usr/local/mysql
chown -R mysql:mysql .
cd /data/mysqldb
chown -R mysql:mysql .
cd /usr/local/mysql
5.数据库初始化
cd /usr/local/mysql/bin
mysqld –initialize-insecure –user=mysql –basedir=/usr/local/mysql –datadir=/data/mysqldb
ls -lrt /data/mysqldb
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
6.开机启动
cp support-files/mysql.server /etc/init.d/mysqld
添加环境变量
echo -e ‘\n\nexport PATH=/usr/local/mysql/bin:$PATH\n’ >> /etc/profile && source /etc/profile
service mysqld start
chkconfig –level 35 mysqld on
netstat -tulnp | grep 3306
7.测试并修改root密码
mysql -u root -p
mysqladmin -u root password ‘xxxxxx’
mysql_secure_installation //设置root安全密码
三、安装nginx
1.安装pcre
yum -y install pcre-devel
2.编译安装nginx
./configure –prefix=/usr/local/nginx –with-pcre
make
make install
3.设置开机自启动
vi /etc/rc.d/init.d/nginx
加入启动脚本,可参考官方文档
chmod 775 /etc/rc.d/init.d/nginx #赋予文件执行权限
chkconfig nginx on #设置开机启动
四、安装Php
1、安装支持文件库
sudo yum install git gcc gcc-c++ libxml2-devel pkgconfig openssl-devel bzIP2-devel curl-devel libpng-devel libjpeg-devel libXpm-devel freetype-devel gmp-devel libmcrypt-devel mariadb-devel aspell-devel recode-devel autoconf bison re2c libicu-devel
2.下载php
sudo mkdir /usr/local/php7
cd php-src
git checkout PHP
3.安装libmcrypt
mv libmcrypt-2.5.8.tar.gz /usr/local/libmcrypt/
cd /usr/local/libmcrypt/
tar vxfz libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make && make install
4.编译安装php7
cd php-src
./buildconf –force
./configure –prefix=/usr/local/php7 –with-config-file-path=/usr/local/php7/etc –with-config-file-scan-dir=/usr/local/php7/etc/conf.d –enable-bcmath –with-bz2 –with-curl –enable-filter –enable-fpm –with-gd –enable-gd-native-ttf –with-freetype-dir –with-jpeg-dir –with-png-dir –enable-intl –enable-mbstring –with-mcrypt –enable-mysqlnd –with-mysql-sock=/var/lib/mysql/mysql.sock –with-mysqli=mysqlnd –with-pdo-mysql=mysqlnd –with-pdo-sqlite –disable-phpdbg –disable-phpdbg-webhelper –enable-opcache –with-openssl –enable-simplexml –with-sqlite3 –enable-xmlreader –enable-xmlwriter –enable-zip –with-zlib
make -j2
make test
make install
5.复制配置文件
sudo mkdir /usr/local/php7/etc/conf.d
sudo cp -v ./php.ini-production /usr/local/php7/lib/php.ini
sudo cp -v ./sapi/fpm/www.conf /usr/local/php7/etc/php-fpm.d/www.conf
sudo cp -v ./sapi/fpm/php-fpm.conf /usr/local/php7/etc/php-fpm.conf
sudo cp -v ./php.ini-production /usr/local/php7/lib/php.ini