当前位置: 首页 > 工具软件 > NSS-MySQL > 使用案例 >

php7.1和mysql5.6_lnmp安装部署-mysql5.6+centos6.8+php7.1+nginx1.9

夹谷鸿福
2023-12-01

1.准备工作:

1)把所有的软件安装在/Data/apps/,源码包放在/Data/tgz/,数据放在/Data/data,日志文件放在/Data/logs,项目放在/Data/webapps,

mkdir -p /Data/apps/

mkdir -p /Data/tgz/

mkdir -p /Data/data/

mkdir -p /Data/logs/

mkdir -p /Data/webapps/

2)安装源码包所需要的依赖包

yum -y install wget openssl* gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers make gd gd2 gd-devel gd2-devel libaio

1

3)创建www所属组及用户

/usr/sbin/groupadd www

/usr/sbin/useradd -g www www

4) 设置系统资源限制

ulimit -SHn 65535

1

2.Nginx安装:

1)pcre源码安装

cd /Data/tgz/

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz

tar zxvf pcre-8.38.tar.gz

cd pcre-8.38

./configure --prefix=/Data/apps/pcre

make && make install

2)nginx源码安装:

cd /Data/tgz/

wget http://nginx.org/download/nginx-1.9.9.tar.gz

tar zxvf nginx-1.9.9.tar.gz

cd nginx-1.9.9

./configure --user=www --group=www --prefix=/Data/apps/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/Data/tgz/pcre-8.38 --with-http_realip_module --with-http_image_filter_module

make && make install

3.Mysql安装:

1)mysql源码安装:

cd /Data/tgz/

wget http://downloads.mysql.com/archives/mysql-5.6/mysql-5.6.12-linux-glibc2.5-x86_64.tar.gz

tar zxvf mysql-5.6.12-linux-glibc2.5-x86_64.tar.gz

mv mysql-5.6.12-linux-glibc2.5-x86_64 /Data/apps/mysql

2)创建mysql所属组及用户:

groupadd mysql

useradd -r -g mysql mysql

1

2

3)改变mysql软件所属组:

cd /Data/apps

chown -R mysql:mysql mysql

4)初始化数据库:

mkdir -p /Data/data/mysql/data

cd /Data/data

chown -R mysql:mysql mysql

su mysql

/Data/apps/mysql/scripts/mysql_install_db --user=mysql --basedir=/Data/apps/mysql --datadir=/Data/data/mysql/data

exit

5)数据库配置文件:

cp /Data/apps/mysql/support-files/my-default.cnf /etc/my.cnf

cp /Data/apps/mysql/support-files/mysql.server /etc/init.d/mysql

vi /etc/init.d/mysql

#修改文件中的两个变更值

basedir=/Data/apps/mysql

datadir=/Data/data/mysql/data

6)添加mysql环境变量

vi /etc/profile

#最后一行添加以下两行:

export MYSQL_HOME="/Data/apps/mysql"

export PATH="$PATH:$MYSQL_HOME/bin"

#保存退出

source /etc/profile

7)添加自启动服务

chkconfig --add mysql

chkconfig mysql on

1

2

8)启动mysql

service mysql start

#会提示:Starting MySQL.. SUCCESS!

#查看mysql服务:

ps aux|grep mysql

9)登录mysql及改密码与配置远程访问

#修改root用户密码

/Data/apps/mysql/bin/mysqladmin -u root password 'your_password'

#登录mysql,需要输入密码

/Data/apps/mysql/bin/mysql -u root -p

#允许root用户远程访问

mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your_password' WITH GRANT OPTION;

mysql>FLUSH PRIVILEGES;#刷新权限

mysql>exit

10)忘记root密码后,如何找回密码

/Data/apps/mysql/bin/bin/mysqld_safe --basedir=/Data/apps/mysql --datadir=/Data/data/mysql/data --skip-grant-tables &

/Data/apps/mysql/bin/bin/mysql -u root mysql

UPDATE user SET password=PASSWORD("new_password") WHERE user='root';

FLUSH PRIVILEGES;

4.Php安装:

1)php依赖安装,顺序执行:

a)创建目录

mkdir -p /Data/apps/libs/

1

b)jpeg源码安装

cd /Data/tgz/

wget http://www.ijg.org/files/jpegsrc.v9.tar.gz

tar zxvf jpegsrc.v9.tar.gz

cd jpeg-9/

./configure --prefix=/Data/apps/libs --enable-shared --enable-static

make && make install

c)libpng源码安装

cd /Data/tgz/

wget http://prdownloads.sourceforge.net/libpng/libpng-1.6.2.tar.gz

tar zxvf libpng-1.6.2.tar.gz

cd libpng-1.6.2/

./configure --prefix=/Data/apps/libs

make && make install

d)freetype源码安装

cd /Data/tgz/

wget http://download.savannah.gnu.org/releases/freetype/freetype-2.4.12.tar.gz

tar zxvf freetype-2.4.12.tar.gz

cd freetype-2.4.12/

./configure --prefix=/Data/apps/libs

make && make install

e)libmcrypt源码安装

cd /Data/tgz/

wget http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz

tar zxvf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8/

./configure --prefix=/Data/apps/libs

make && make install

cd libltdl/

./configure --prefix=/Data/apps/libs --enable-ltdl-install

make && make install

f)mhash源码安装

cd /Data/tgz/

wget http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz

tar zxvf mhash-0.9.9.9.tar.gz

cd mhash-0.9.9.9/

./configure --prefix=/Data/apps/libs

make && make install

g)libiconv源码安装

cd /Data/tgz/

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

tar -zxvf libiconv-1.14.tar.gz

cd libiconv-1.14

./configure --prefix=/Data/apps/libs

make && make install

#解决./stdio.h:1010:1: 错误:‘gets’未声明(不在函数内) 的问题

cd srclib/

sed -i -e '/gets is a security/d' ./stdio.in.h

cd ../

make && make install

h)添加编译时使用的动态链接库的路径

vi /etc/ld.so.conf

#添加一行

/Data/apps/libs/lib

#生效

ldconfig

i)mcrypt源码安装

cd /Data/tgz/

wget http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz

tar zxvf mcrypt-2.6.8.tar.gz

cd mcrypt-2.6.8/

export LDFLAGS="-L/Data/apps/libs/lib -L/usr/lib"

export CFLAGS="-I/Data/apps/libs/include -I/usr/include"

touch malloc.h

./configure --prefix=/Data/apps/libs --with-libmcrypt-prefix=/Data/apps/libs

make && make install

2)php编译安装:

a)php7源码安装

cd /Data/tgz

wget http://cn2.php.net/distributions/php-7.0.6.tar.gz

tar xzvf php-7.1.9.tar.gz

cd php-7.1.9

#./configure --help

./configure --prefix=/Data/apps/php7 --with-config-file-path=/Data/apps/php7/etc --with-mysqli=/Data/apps/mysql/bin/mysql_config --with-iconv=/Data/apps/libs/ --with-freetype-dir=/Data/apps/libs --with-jpeg-dir=/Data/apps/libs --with-png-dir=/Data/apps/libs --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt=/Data/apps/libs --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --with-bz2 --enable-soap --enable-opcache --with-pdo-mysql --enable-maintainer-zts --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --without-pear --with-gettext --enable-fpm --enable-opcache=no

#备注:较之前的版本,去除的选项(不全)

--with-mysql

--with-mime-magic

--enable-fastcgi

--enable-force-CGI-redirect

make && make install

cp php.ini-development /Data/apps/php7/etc/php.ini

cp ./sapi/fpm/php-fpm.conf /Data/apps/php7/etc/php-fpm.conf

cp /Data/apps/php7/etc/php-fpm.d/www.conf.default /Data/apps/php7/etc/php-fpm.d/www.conf

#下面是为了php-fpm随系统自启动。

cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

#更改php-fpm启动用户

vi /Data/apps/php7/etc/php-fpm.d/www.conf

#把下面两行

user = nobody

group = nobody

#改为:

user = www

group = www

#启动php

/Data/apps/php7/sbin/php-fpm

#查看进程

ps aux|grep php-fpm

3)php扩展安装:

a)yaf扩展安装yaf.so

cd /Data/tgz

wget http://pecl.php.net/get/yaf-3.0.2.tgz

tar zxvf yaf-3.0.2.tgz

cd yaf-3.0.2

/Data/apps/php7/bin/phpize

./configure --with-php-config=/Data/apps/php7/bin/php-config

make && make install

b)redis扩展安装redis.so

cd /Data/tgz

wget https://github.com/edtechd/phpredis/archive/php7.zip

unzip php7.zip

cd phpredis-php7

/Data/apps/php7/bin/phpize

./configure --with-php-config=/Data/apps/php7/bin/php-config

make && make install

c)msgpack扩展安装msgpack.so

cd /Data/tgz

wget http://pecl.php.net/get/msgpack-2.0.1.tgz

tar zxvf msgpack-2.0.1.tgz

cd msgpack-2.0.1

/Data/apps/php7/bin/phpize

./configure --with-php-config=/Data/apps/php7/bin/php-config

make && make install

d)swoole扩展安装swoole.so

swoole扩展安装swoole.so

cd /Data/tgz

wget http://pecl.php.net/get/swoole-1.8.4.tgz

tar zxvf swoole-1.8.4.tgz

cd swoole-1.8.4

/Data/apps/php7/bin/phpize

./configure --with-php-config=/Data/apps/php7/bin/php-config

make && make install

e)使扩展生效:

vi /Data/apps/php7/etc/php.ini

#打开 /Data/apps/php7/etc/php.ini 查找 ; extension_dir = "ext"

#更改extension_dir的值,此值视具体情况而定

extension_dir = "/Data/apps/php7/lib/php/extensions/no-debug-zts-20151012/"

#在其后增加一行:

extension = "yaf.so"

extension = "swoole.so"

extension = "redis.so"

extension = "msgpack.so"

 类似资料: