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

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


# 开始安装

[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

# 修改如下代码#

二、安装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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,015评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,262评论 1 292
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,727评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,986评论 0 205
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,363评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,610评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,871评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,582评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,297评论 1 242
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,551评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,053评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,385评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,035评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,079评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,841评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,648评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,550评论 2 270

推荐阅读更多精彩内容