nginx php7 mysql_Centos7编译安装NGINX+MYSQL+PHP7

修改默认主机名称[root@iZuf60c5bxd15kr9gycvv6Z~]# hostnamectl set-hostname centos7

[root@iZuf60c5bxd15kr9gycvv6Z~]# reboot

[root@iZuf60c5bxd15kr9gycvv6Z~]# yum update

安装依赖库[root@centos7~]# yum -y install 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 screen

删除系统默认数据库配置文件

查询[root@centos7 ~]# find -H /etc/ | grep my.c

显示如下:

/etc/my.cnf

/etc/my.cnf.d

/etc/my.cnf.d/mysql-clients.cnf

/etc/pki/tls/certs/renew-dummy-cert

/etc/pki/tls/certs/make-dummy-cert

删除[root@centos7 ~]# rm -rf /etc/my.cnf /etc/my.cnf.d /etc/my.cnf.d/mysql-clients.cnf

确认[root@centos7 ~]# find -H /etc/ | grep my.c

显示如下:

/etc/pki/tls/certs/renew-dummy-cert

/etc/pki/tls/certs/make-dummy-cert

卸载系统自带mariadb-libs

查询[root@centos7 ~]# rpm -qa|grep mariadb-libs

显示如下:

mariadb-libs-5.5.52-1.el7.x86_64

删除[root@centos7 ~]#rpm -e mariadb-libs-5.5.52-1.el7.x86_64--nodeps

rpm -e --nodeps mariadb-libs-5.5.35-3.el7.x86_64

一、安装NGINX

-下载安装包并解压[root@localhost ~]# cd /usr/local/src

[root@localhost src]# wget http://nginx.org/download/nginx-1.12.1.tar.gz

[root@localhost src]# tar -zxvf nginx-1.12.1.tar.gz

创建NGINX安装目录,WEB存放目录,以及用户组、用户

# 创建nginx用户组[root@centos7 src]# groupadd -r www

# 创建nginx用户[root@centos7 src]# useradd -r -g www -s /sbin/nologin -d /usr/local/nginx -M www

# 创建安装目录[root@centos7 src]# mkdir -p /usr/local/nginx

# 创建数据存放目录[root@centos7 src]# mkdir -p /data/web

# 赋以mysql用户读写权限[root@centos7 src]# chown -R www:www /data/web

-编译安装[root@localhost src]#cd nginx-1.12.1

# 输入以下参数./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module

如果看到以下说明则编译成功

dc975c573a23

# 开始安装[root@localhost nginx-1.12.1]#make && make install

尝试启动[root@centos7 nginx-1.12.1]# /usr/local/nginx/sbin/nginx

# 如果未提示错误即代表安装成功

编写快捷启动脚本[root@centos7 nginx-1.12.1]# vi /lib/systemd/system/nginx.service

输入以下代码[Unit]

Description=nginx

After=network.target

[Service]

Type=forking

PIDFile=/usr/local/nginx/logs/nginx.pid

ExecStart=/usr/local/nginx/sbin/nginx

ExecReload=/usr/local/nginx/sbin/nginx -s reload

ExecStop=/usr/local/nginx/sbin/nginx -s quit

PrivateTmp=true

[Install]

WantedBy=multi-user.target

设置开机启动[root@centos7nginx-1.12.1]# systemctl enable nginx.service

其它命令说明# 启动nginx

[root@centos7 nginx-1.12.1]# systemctl start nginx.service

# 停止nginx

[root@centos7 nginx-1.12.1]# systemctl stop nginx.service

# 重启nginx

[root@centos7 nginx-1.12.1]# systemctl restart nginx.service

# 如果提示

Job for nginx.service failed because the control process exited with error code. See"systemctl status nginx.service"and"journalctl -xe"for details.

# 请选结束nginx进程后再尝试执行上面的快捷操作

[root@centos7 nginx-1.12.1]# pkill -9 nginx

修改配NGINX配制文件[root@centos7 php-7.1.10]# cd /usr/local/nginx/conf

[root@centos7 conf]# vi nginx.conf

# 修改如下代码#

dc975c573a23

dc975c573a23

二、安装MYSQL5.7

开始安装[root@centos7 src]# rpm -ivh http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm[root@centos7 src]# yum install -y mysql-server

设置开机启动Mysql[root@centos7 src]# systemctl enable mysqld.service

开启服务[root@centos7 src]# systemctl start mysqld.service

查看Mysql5.7默认密码[root@centos7 src]# grep 'temporary password' /var/log/mysqld.log

k-Lo1whpOt/!

tips报错1:SQLSTATE[HY000] [2002] No such file or directory

解决:config文件中的    ‘DB_HOST’ => 'localhost'     改成      '127.0.0.1'报错2:_STORAGE_WRITE_ERROR_:./Application/Runtime/Cache/User/........

解决:找到runtime位置  chmod -R 777 runtime

安装pdo_mysql

find / -name pdo_mysql

cd /usr/local/src/php-7.1.10/ext/pdo_mysql

执行 :/usr/local/php/bin/phpize (若不是该路径,也可以查找 find / -name phpize)

报错:Cannot find autoconf. Please check your autoconf installation and the$PHP_AUTOCONF environment variable. Then, rerun this script.

执行:yum install m4yum install autoconf

再次/usr/local/php/bin/phpize正确

./configure --with-php-config=/usr/local/php/bin/php-config

make && make install

cd /usr/local/php/lib/php/extensions/no-debug-zts-20160303

会出现pdo_mysql.so

打开PHP.ini

添加 extension="/usr/local/php/lib/php/extensions/no-debug-zts-20160303/pdo_mysql.so"

重启PHP-fpm

其他

*grep 'temporary password' /var/log/mysqld.log 查看临时密码

mysql -uroot -p

修改密码

ALTER USER 'root'@'localhost' IDENTIFIED BY 'your password';

三、安装PHP7

下载安装包并解压[root@centos7 nginx-1.12.1]# cd /usr/local/src

[root@centos7 src]# wget -O php-7.2.6.tar.gz http://cn2.php.net/get/php-7.2.6.tar.gz/from/this/mirror

[root@centos7 src]# tar -zxvf php-7.2.6.tar.gz

安装必要的相关扩展[root@centos7src]# yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel

编译安装[root@localhost src]# cd php-7.2.6

# 输入以下参数./configure --prefix=/usr/local/php \--with-openssl \--with-pcre-regex \--with-kerberos \--with-libdir=lib \--with-libxml-dir \--with-mysqli=shared,mysqlnd \--with-pdo-mysql=shared,mysqlnd \--with-pdo-sqlite \--with-gd \--with-iconv \--with-zlib \--with-xmlrpc \--with-xsl \--with-pear \--with-gettext \--with-curl \--with-png-dir \--with-jpeg-dir \--with-freetype-dir \--with-fpm-user=nginx \--with-fpm-group=nginx \--enable-mysqlnd \--enable-zip \--enable-inline-optimization \--enable-shared \--enable-libxml \--enable-xml \--enable-bcmath \--enable-shmop \--enable-sysvsem \--enable-mbregex \--enable-mbstring \--enable-ftp \--enable-gd-native-ttf \--enable-pcntl \--enable-sockets \--enable-soap \--enable-session \--enable-opcache \--enable-fpm \--enable-maintainer-zts \--enable-fileinfo

开始安装[root@localhost php-7.2.6]# make && make install

配制php.ini[root@centos7 php-7.2.6]# cp php.ini-production /usr/local/php/etc/php.ini

或cp php.ini-production /usr/local/php/lib/php.ini

[root@centos7 php-7.2.6]# vi /usr/local/php/etc/php.ini

# 做以下修改(时区,不显示版本号,开启opcache缓存加速PHP)#找到:;date.timezone=                              修改为:date.timezone= PRC.

找到:expose_php= On                            修改为:expose_php= Off.

找到:opcache.enable=0                          修改为:opcache.enable=1.

在 Dynamic Extensions 代码块中添加zend_extension=opcache.so

配置php-fpm[root@centos7 php-7.2.6]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

[root@centos7 php-7.2.6]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

[root@centos7 php-7.2.6]# cp /usr/local/src/php-7.2.6/sapi/fpm/init.d.php-fpm /usr/local/php/bin/php-fpm

[root@centos7 php-7.2.6]# chmod 777 /usr/local/php/bin/php-fpm

尝试启动[root@centos7php-7.2.6]# /usr/local/php/bin/php-fpm start

# 如提示''Starting php-fpm  done''即表示安装成功

# ERROR: [pool www] cannot get uid for user 'www'

vi /usr/local/php/etc/php-fpm.d/www.conf 改成www www

编写快捷启动脚本[root@centos7 php-7.2.6]# vi /lib/systemd/system/php-fpm.service

输入以下代码[Unit]

Description=php-fpm

After=network.target

[Service]

Type=forking

PIDFile=/usr/local/php/var/run/php-fpm.pid

ExecStart=/usr/local/php/bin/php-fpm start

ExecReload=/usr/local/php/bin/php-fpm restart

ExecStop=/usr/local/php/bin/php-fpm stop

PrivateTmp=true

[Install]

WantedBy=multi-user.target

设置开机启动[root@centos7 php-7.2.6]# systemctl enable php-fpm.service

其它命令说明# 启动php-fpm

[root@centos7 php-7.2.6]# systemctl start php-fpm.service

# 停止php-fpm

[root@centos7 php-7.2.6]# systemctl stop php-fpm.service

#重启php-fpm

[root@centos7 php-7.2.6]# systemctl restart php-fpm.service

# 如果提示:Job for php-fpm.service failed because the control process exited with error code. See "systemctl status php-fpm.service" and "journalctl -xe" for details.

# 请选结束php-fpm进程后再尝试执行上面的快捷操作

[root@centos7 php-7.2.6]# pkill -9 php-fpm

#php加入环境变量

[root@centos7 php-7.2.6]#PATH=$PATH:/usr/local/php/bin

[root@centos7 php-7.2.6]#export $PATH

[root@centos7 php-7.2.6]#source /etc/profile

echo PATH=$PATH:/usr/local/php/bin/:/root/.composer/vendor/bin >> /etc/profile

# 查看引用php.ini路径

php -i |grep php.ini

NGINX虚拟主机配制

打开配制文件[root@centos7 php-7.2.6]# vi /usr/local/nginx/conf/nginx.conf

在http{}节点尾加入以下代码server {

listen          80;

server_name    *.demo.com;

root            /data/web/demo/www;

access_log      /data/web/demo/log/access.log  main;

error_log      /data/web/demo/log/error.log error;

index          index.php;

#THINKPHP伪静态

location / {

if (!-e $request_filename) {

rewrite ^(.*)$ /index.php?s=$1 last;

break;

}

}

#解析PHP代码

location ~ \.php$ {

fastcgi_pass  127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;

include        fastcgi_params;

}

#静态资源缓存1天

location ~ .*\.(gif|jpg|jpeg|png|bmp|ico|swf|js|css)$ {

expires    1d;

access_log  off;

}

#字体文件跨域问题

location ~ .*\.(eof|ttf|ttc|otf|eof|woff|woff2|svg)(.*){

add_header Access-Control-Allow-Origin *;

}

}

GIT

安装了git 记得设置git密码

passwd git

设置钩子post-receive

设置钩子指向的web目录 777

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值