Centos7上安装nginx+mysql+php

linux admin 1972℃ 0评论

Centos7上安装nginx+mysql+php

 

一、    安装nginx

 

1.      添加用户组

groupadd www

useradd -g www www -s /bin/false

 

2.      安装依赖包

yum install -y gcc gcc-c++ zlib zlib-devel openssl openssl-devel pcre pcre-devel readline readline-devel

yum install -y libpng libjpeg libpng-devel libjpeg-devel ghostscript libtiff libtiff-devel freetype freetype-devel

3.      下载源码

源码下载存放路径:/usr/local/src

 

a)      基础包下载:

 

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

//可以不用安装,下面安装都是默认需要安装

wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz ### LuaJIT 

wget http://zlib.net/zlib-1.2.11.tar.gz

 

b)      nginx模块下载:【如果git没有安装,yum install git】

 

git clone https://github.com/alibaba/nginx-http-concat.git

git clone https://github.com/simpl/ngx_devel_kit.git

git clone https://github.com/openresty/echo-nginx-module.git

git clone https://github.com/openresty/lua-nginx-module.git

 

4.      解压安装包

tar -zxf nginx-1.15.2.tar.gz

tar -zxf LuaJIT-2.0.5.tar.gz

tar -zxf zlib-1.2.11.tar.gz

 

 

5.      安装LuaJIT【不需要的可以不用装】

cd LuaJIT-2.0.5

make install PREFIX=/usr/local/luajit

                   echo "/usr/local/luajit/lib" > /etc/ld.so.conf.d/usr_local_luajit_lib.conf

                   ldconfig

export LUAJIT_LIB=/usr/local/lib

export LUAJIT_INC=/usr/local/include/luajit-2.0

ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2

 

6.      安装nginx

7.       

cd nginx-1.15.2

 

./configure --prefix=/usr/local/nginx --user=www --group=www --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --error-log-path=/opt/logs/nginx/error.log --http-log-path=/opt/logs/nginx/access.log --with-http_ssl_module --with-http_realip_module --with-http_sub_module --with-http_flv_module --with-http_dav_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_addition_module --with-http_v2_module --with-pcre --with-zlib=../zlib-1.2.11 --add-module=../nginx-http-concat --add-module=../lua-nginx-module --add-module=../ngx_devel_kit 

make -j8

make install

 

 

二、    安装mysql

1.      下载mysql的repo源

  这个网站选择需要的版本:http://repo.mysql.com/


wget  http://repo.mysql.com/mysql57-community-release-el5-8.noarch.rpm

 

2.      安装mysql57-community-release-el5-8.noarch.rpm

 

卸载centos默认的mariadb

  image.png

上面提示卸载失败,先不管继续往下走


 rpm -ivh mysql57-community-release-el5-8.noarch.rpm

 

3.      安装mysql

 

yum install mysql-server


    如果出现  Package: 2:postfix-2.10.1-6.el7.x86_64 (@anaconda)            Requires: libmysqlclient.so.18()(64bit)            Removing: 1:mariadb-libs-5.5.56-2.el7.x86_64 (@anaconda)

   尝试卸载掉mysql依赖: yum remove mysql-libs ,再运行: yum install mysql-server

 

4.      启动mysql

 

 service mysqld start

  //查看临时生成的密码
  
  grep 'temporary password' /var/log/mysqld.log

5.      修改密码

 

a)      登录:mysql -uroot

b)       use mysql;

 update user set password=password(‘123456’) where user='root'

 如果是5.7及以上

 update user set authentication_string=password(‘123456’) where user='root'

 

如果报 mysql修改密码 Your password does not satisfy the current policy requirements

运行语句: set global validate_password_policy=0;


如果报 You must reset your password using ALTER USER statement before executing this statement.

运行语句:alter user user() identified by yourpassword;


6.      设置允许远程访问【如果不需要可以不需要做这步】

 

a)      mysql -u root

b)      GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION

 

 

 

7.      补充说明

 

你也可以指定mysql的数据存放位置,以及mysql用户组

a)      添加用户组

 

groupadd mysql

useradd -g mysql mysql -s /bin/false

 

b)      创建文件夹

 

 mkdir -p /usr/local/mysql/data

 mkdir -p /usr/local/mysql/log

chown -R mysql:mysql  /usr/local/mysql/

 

c)      修改配置文件

vi /etc/my.cnf

# 写入以下内容:

[mysqld]

user=mysql

datadir=/usr/local/mysql/data

socket=/tmp/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

init_connect='SET collation_connection = utf8_general_ci'

init_connect='SET NAMES utf8'

character-set-server=utf8

collation-server=utf8_general_ci

skip-character-set-client-handshake

max_connections=1000

sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" #5.6 mode

log-error=/usr/local/mysql/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

log-bin=mysql-bin

server-id=1

binlog-do-db=ckg          #需要记录进制日志的数据库.如果有多个数据库可用逗号分隔,或者使用多个binlog-do-db选项

binlog-ignore-db=information_schema,mysql,sys      #不需要记录进制日志的数据库.如果有多个数据库可用逗号分隔,或者使用多个binlog-do-db选项

replicate-do-db=ckg       #需要进行同步的数据库.如果有多个数据库可用逗号分隔,或者使用多个replicate-do-db选项

replicate-ignore-db=information_schema,mysql,sys     #不需要同步的数据库.如果有多个数据库可用逗号分隔,或者使用多个replicate-ignore-db选项

#同步参数:

##保证slave挂在任何一台master上都会接收到另一个master的写入信息

log-slave-updates

sync_binlog=1

auto_increment_offset=1

auto_increment_increment=2

slave-skip-errors=all             #过滤掉一些没啥大问题的错误

 

explicit_defaults_for_timestamp = 1

 

 

[mysqld_safe]

log-error=/usr/local/mysql/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

 

[client]

default-character-set=utf8

socket=/tmp/mysql.sock

 

[mysql]

default-character-set=utf8

socket=/tmp/mysql.sock

 

 

 如果mysql 运行命令提示You must reset your password using ALTER USER statement before executing this statement. 错误。运行下面步骤


set password = password('your new password');

flush privileges;


三、      安装php【php7.0.8】

1.      安装依赖包

 

                     yum install -y gcc gcc-c++  make cmake automake autoconf kernel-devel ncurses-devel libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel  pcre-devel libtool-libs freetype-devel gd zlib-devel file bison patch mlocate flex diffutils   readline-devel glibc-devel glib2-devel bzip2-devel gettext-devel libcap-devel libmcrypt-devel openldap openldap-devel libxslt-devel

 

yum install -y libpng libjpeg libpng-devel libjpeg-devel ghostscript libtiff libtiff-devel freetype freetype-devel

 

2.      下载安装包

 

 wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

wget    http://cn.php.net/distributions/php-7.1.11.tar.gz

 

3.      安装libmcrypt

tar -zxf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8

./configure --prefix=/usr

make -j8

make install

 

4.        安装php

           cd php-7.1.11 

 ./configure --prefix=/usr/local/php --sysconfdir=/etc --with-config-file-path=/usr/local/php/etc/ --with-openssl --with-kerberos --with-zlib --with-bz2 --with-curl --with-gd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql-sock=mysqlnd --with-mhash --with-mcrypt --with-iconv --with-xsl --with-xmlrpc --with-pcre-regex --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-cli --enable-calendar --enable-bcmath --enable-exif --enable-ftp --enable-gd-native-ttf --enable-mbstring --enable-mbregex --enable-json --enable-pdo --enable-dba --enable-shmop --enable-soap --enable-sockets --enable-wddx --enable-fpm --enable-zip --enable-dom --enable-posix --enable-fileinfo --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-xml --enable-xmlwriter --enable-xmlreader --enable-maintainer-zts --enable-opcache 

make -j16

make install

 

 

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

chmod +x /etc/init.d/php-fpm

chkconfig php-fpm on

\cp /etc/php-fpm.conf.default /etc/php-fpm.conf -Rf

mkdir /usr/local/php/etc/

cp php.ini-* /usr/local/php/etc/

cp php.ini-production /usr/local/php/etc/php.ini

ln -sf /usr/local/php/etc/php.ini /etc/

echo PATH=$PATH:/usr/local/php/bin/ >> /etc/profile

source /etc/profile

 

5.        启动php-fpm

 

cd  /etc/php-fpm.d/

cp  www.conf.default  www.conf

service php-fpm start

 

 

6.        补充说明

--with-mysql 在php7已经取消了


7.如果报:


            virtual memory exhausted: Cannot allocate memory

           make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1


           在./configure 的配置项种增加    --disable-fileinfo

 

 


加载中...