Linux下安装nginx+php+mysql+redis

常用命令

查看系统版本:

head -n 1 /etc/issue

lsb_release -a    (centos 7 )

查看系统位数

getconf LONG_BIT

lsof -i 8080  查看8080端口的访问详情

内核升级

[root@localhost ~]# uname -a   ##旧版

Linux localhost.localdomain 2.6.32-279.el6.i686 #1 SMP Fri Jun 22 10:59:55 UTC 2012 i686 i686 i386 GNU/Linux

[root@localhost ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

[root@localhost ~]# rpm -ivh http://www.elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm

[root@localhost ~]# yum --enablerepo=elrepo-kernel install kernel-lt -y  ##此步会有点慢

[root@localhost ~]# vim /etc/grub.conf default=1 改为 default=0  ##设置默认以3.10核心启动,默认是按照旧的核心启动

[root@localhost ~]# reboot

[root@localhost ~]# uname -a  ##升级后的版本

CentOS 6.x 安装 php7.0

一:检查当前是否有安装php

rpm -qa|grep php

如果有安装PHP,那么请先删除这些安装包:

 yum remove php*

2.安装php源

Centos 5 安装php源:

rpm -ivh http://mirror.webtatic.com/yum/el5/latest.rpm

CentOs 6 安装php源:

  rpm -ivh http://mirror.webtatic.com/yum/el6/latest.rpm

CentOs 7 安装php源和epel扩展源:

rpm -ivh https://mirror.webtatic.com/yum/el7/epel-release.rpm

rpm -ivh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

3.现在开始安装php

安装php5.5的基本安装包:

 yum install php55w php55w-gd php55w-mbstring php55w-mysql php55w-fpm

安装php5.6的基本安装包:

 yum install php56w php55w-gd php56w-mbstring php56w-mysql php56w-fpm

安装php7.0的基本安装包:

  yum install php70w php70w-gd php70w-mbstring php70w-mysql php70w-fpm

删除PHP:

#rpm -qa|grep php

删除依赖:

#rpm -e php-pdo-5.1.6-27.el5_5.3

二:nginx的yum在线安装

添加源

wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

安装源库

chmod +x nginx-release-centos-6-0.el6.ngx.noarch.rpm

rpm -i nginx-release-centos-6-0.el6.ngx.noarch.rpm

安装nginx

yum -y install nginx

安装完成后的默认配置文件路径

默认nginx配置文件: /etc/nginx/nginx.conf 【nginx主要的配置文件】

默认nginx的ssl配置文件: /etc/nginx/conf.d/ssl.conf 【配置SSL证书的,也可以并入到nginx.conf文件里】

默认nginx的虚拟主机配置文件: /etc/nginx/conf.d/virtual.conf 【如同Apache的虚拟主机配置,也可以并入到nginx.conf文件里】

默认的web_root文件夹路径: /usr/share/nginx/html 【web目录夹,放置Magento主程序】

配置iptables

iptables -I INPUT 5 -p tcp --dport 80 -j ACCEPT

(这个步骤,我之前机器上已经装过apache所以就忽略了)

安装后的目录:


配置目录:

/etc/nginx/

项目目录:

/usr/share/nginx/html/

安装Composer

CentOS下Composer的安装和使用

1. 下载composer.phar

curl -sS https://getcomposer.org/installer | php

2.把composer.phar移动到环境下让其变成可执行

mv composer.phar /usr/local/bin/composer

3.测试

composer -V

中国全量镜像

composer config -g repo.packagist composer https://packagist.phpcomposer.com

安装 php扩展

apt-get install php7.0-mbstring

apt-get install php7.0-dom

yum install -ylibtool-ltdl php70w-dom php70w-mbstring php70w-mcrypt

yum install php70w-pear php70w-devel

压缩命令

zip -r etm-m-om.zip etm-m-om

解压目录

unzip  mydata.zip   -d  mydatabak    #压缩mydata目录

rpm -qa|grep php

yum install update -y

rpm -ivh http://mirror.webtatic.com/yum/el6/latest.rpm

rpm -ivh http://mirror.webtatic.com/yum/el6/latest.rpm

安装php7.0的基本安装包:

yum install php70w php70w-gd php70w-mbstring php70w-mysql php70w-fpm

安装nginx

wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm  

安装源库

chmod +x nginx-release-centos-6-0.el6.ngx.noarch.rpm

rpm -i nginx-release-centos-6-0.el6.ngx.noarch.rpm

安装nginx

yum -y install nginx

配置iptables 80端口 ;

配置目录:

/etc/nginx/

项目目录:

/usr/share/nginx/html/

安装 php扩展

apt-get install php70w-mbstring

apt-get install php70w-dom

nginx 设置

vi /etc/nginx/conf.d/default

server {

    listen       80;

    server_name  10.207.21.113;

    #charset koi8-r;

    #access_log  /var/log/nginx/log/host.access.log  main;

    root /var/www/html/etm-m/public ;

    index index.php index.html index.htm;

gzip on;

gzip_min_length 1k;

gzip_buffers 4 16k;

#gzip_http_version 1.0;

gzip_comp_level 8;

gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;

gzip_vary off;

gzip_disable "MSIE [1-6]\.";

    location / {

       #root   /var/www/html/etm-m/public;

       #index  index.php index.html index.htm;

       try_files $uri $uri/ /index.php?$query_string ;

    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html

    #

    error_page   500 502 503 504  /50x.html;

    location = /50x.html {

        root   /usr/share/nginx/html;

    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80

    #

    #location ~ \.php$ {

        #proxy_pass   http://127.0.0.1;

   #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

    #

    location ~ \.php$ {

    #     root           /var/www/html/etm-m/public;

        fastcgi_pass   127.0.0.1:9000;

        try_files $uri /index.php=404 ;

        fastcgi_index  index.php;

        fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;

        include        fastcgi_params;

    }

    # deny access to .htaccess files, if Apache's document root

    # concurs with nginx's one

    #

    #location ~ /\.ht {

    #    deny  all;

    #}

}

部署负载

nginx:

user  nginx;

worker_processes  1;

error_log  /var/log/nginx/error.log warn;

pid        /var/run/nginx.pid;

events {

    worker_connections  1024;

}

http {

    include       /etc/nginx/mime.types;

    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    upstream myServer{

        ip_hash ;

        server  10.207.21.111:80;

        server  10.207.21.113:80;

   }

    server{

        listen 80;

        server_name etm ;

        location / {

           proxy_pass  http://myServer ;

           proxy_set_header Host  $host ;

           proxy_set_header X-Real-IP  $remote_addr ;

           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;

       }

   }

    sendfile        on;

    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;

}

~

负载的 conf

server {

    listen       80;

    server_name  localhost;

    #charset koi8-r;

    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {

        root   /usr/share/nginx/html;

        index  index.html index.htm;

    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html

    #

    error_page   500 502 503 504  /50x.html;

    location = /50x.html {

        root   /usr/share/nginx/html;

    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80

    #

    #location ~ \.php$ {

    #    proxy_pass   http://127.0.0.1;

    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

    #

    #location ~ \.php$ {

    #    root           html;

    #    fastcgi_pass   127.0.0.1:9000;

    #    fastcgi_index  index.php;

    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

    #    include        fastcgi_params;

    #}

    # deny access to .htaccess files, if Apache's document root

    # concurs with nginx's one

    #

    #location ~ /\.ht {

    #    deny  all;

    #}

}

上传项目赋予项目运行权限

chown -R :nginx etm-m-om

cd etm-m-om

chmod -R 777 public

chmod -R 777 storage

chmod -R 775 bootstrap/cache

php artisan config:cache

php artisan route:cache

r

php artisan session:table

composer dump-autoload

php artisan migrate

部署告警

启动命令

nohup php artisan redis:subscribe &

安装MySQL

Step1: 检测系统是否自带安装mysql

# yum list installed | grep mysql

Step2: 删除系统自带的mysql及其依赖命令:

要删除干净mysql

# yum -y remove mysql-libs.x86_64

Step3: 给CentOS添加rpm源,并且选择较新的源命令:

# wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm

# yum localinstall mysql-community-release-el6-5.noarch.rpm

# yum repolist all | grep mysql

# yum-config-manager --disable mysql55-community

# yum-config-manager --disable mysql56-community

# yum-config-manager --enable mysql57-community-dmr

# yum repolist enabled | grep mysql

Step4:安装mysql 服务器命令:

# yum install mysql-community-server

Step5: 启动mysql命令:

# service mysqld start

Step6: 查看mysql是否自启动,并且设置开启自启动命令:

# chkconfig --list | grep mysqld

# chkconfig mysqld on

Step7: mysql安全设置命令:

# mysql_secure_instalation

修改mysql初始密码:

IK290yd7Dx2

方法一:

# /etc/init.d/mysqld stop

# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

# mysql -u root mysql

mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';

mysql> FLUSH PRIVILEGES;

mysql> quit

注:5.7 版本的 Password 字段已经改名为 authentication_string; 所以密码语句需要修改为:

UPDATE user SET authentication_string=PASSWORD('new') where USER='root';

赋权限

ALTER USER 'root'@'localhost' IDENTIFIED BY '45UIkdW230..';

grant all privileges on *.*  to  'root'@'%'  identified by '45UIkdW230..'  with grant option;

 grant all privileges on *.* to 'root'@'%' identified by '45UIkdW230..';

45UIkdW230

修改mysql时间:

rm -rf  /etc/localtime

cp  /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

-select now() 

MySQL 主主同步

机器A

server-id=101

user=mysql

log-bin=mysql-bin

log-slave-updates

slave-skip-errors=all

sync_binlog=1

auto_increment_increment=1

auto_increment_offset=1

binlog-do-db=test1

binlog-do-db=test1

binlog-ignore-db=db1

binlog-ignore-db=db2

机器B

server-id=102

user=mysql

log-bin=mysql-bin

log-slave-updates

slave-skip-errors=all

sync_binlog=1

auto_increment_increment=2

auto_increment_offset=1

binlog-do-db=test1

binlog-do-db=test1

binlog-ignore-db=db1

binlog-ignore-db=db2

在机器A MySQL Client中插入: 

change master to

master_host='机器B的IP',

master_user='数据库用户名',

master_password='数据库密码',

master_log_file='mysql-bin.000001',

master_log_pos=154;

在机器B MySQL Client中插入:

change master to

master_host='机器A的IP',

master_user='数据库用户名',

master_password='数据库密码',

master_log_file='mysql-bin.000001',

master_log_pos=154;

MySQL 主从同步

机器A

server-id=101

user=mysql

log-bin=mysql-bin

机器B

server-id=102

user=mysql

log-bin=mysql-bin

在机器B MySQL Client中插入:

change master to

master_host='机器A的IP',

master_user='数据库用户名',

master_password='数据库密码',

master_log_file='mysql-bin.000001',

master_log_pos=154;

安装Redis

IK290yd7Dx2

vi /etc/redis.conf

# find # requirepass foobared

#replace it with your password

requirepass somePassword

redis 127.0.0.1:6379[1]> config set requirepass my_redis 

OK 

redis 127.0.0.1:6379[1]> config get requirepass 

1) "requirepass" 

2) "my_redis"  

不重启Redis设置密码:

在配置文件中配置requirepass的密码(当redis重启时密码依然有效)。

redis 127.0.0.1:6379> config set requirepass test123

查询密码:

redis 127.0.0.1:6379> config get requirepass

(error) ERR operation not permitted

密码验证:

redis 127.0.0.1:6379> auth test123

OK

HTTPS 设置


在使用git进行代码更新时,出现认证错误,起初认为是账户和密码输入错误,可是经过再三尝试,终于确定是git版本太低问题,因此将git升级到2.x版本。以下是升级步骤。

[root@test ~]# git --version

git version 1.7.1

 1、安装依赖

[root@test ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel

[root@test ~]# yum install -y perl-ExtUtils-MakeMaker package

2、卸载系统原有git

[root@test ~]# rpm -e git

3、下载git源码包

[root@test ~]# wget https://www.kernel.org/pub/software/scm/git/git-2.0.0.tar.gz

4、安装git

[root@test ~]# tar xf git-2.0.0.tar.gz

[root@test tools]# cd git-2.0.0

[root@test git-2.0.0]# ./configure

[root@test git-2.0.0]# make

[root@test git-2.0.0]# make install

[root@test git-2.0.0]# cd

5、验证

[root@test ~]# git --version

git version 2.0.0

项目配置:

etm-m-link-check  8013

etc-m-warn-report 8012

etc-m-com         8010

etc-m-com-warn    8011

安装目录:

查看安装目录 # whereis php

ubuntu 安装软件

apt-cache search 软件名称

vi

gg           : 跳转到文件头

Shift+g   : 跳转到文件末尾

centos 安装扩展

CentOS 7 安装 PHP 7.0以及memcache和redis扩展

安装EPEL

EPEL 是 Extra Packages for Enterprise Linux 的缩写(EPEL),是用于 Fedora-based Red Hat Enterprise Linux (RHEL) 的一个高质量软件源,所以同时也适用于 CentOS 或者 Scientific Linux 等发行版。

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

yum install epel-release

安装PHP 采用webtatic的编译版本

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

yum install php70w php70w-devel php70w-bcmath php70w-fpm php70w-mbstring php70w-pdo php70w-soap php70w-mysql php70w-gd

安装memcached for php7

git clone https://github.com/php-memcached-dev/php-memcached.git

cd php-memcached

git checkout php7

phpize

./configure --disable-memcached-sasl

make && make install

add

extension=memcached.so

to php.ini

安装redis for php7

git clone https://github.com/phpredis/phpredis.git

cd phpredis

git checkout php7

phpize

./configure

make && make install

add

extension=redis.so

to php.ini

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

推荐阅读更多精彩内容