Linux下安裝nginx+php+mysql+redis

常用命令

查看系統(tǒng)版本:

head -n 1 /etc/issue

lsb_release?-a? ? (centos 7 )

查看系統(tǒng)位數(shù)

getconf LONG_BIT

lsof -i 8080 ?查看8080端口的訪問詳情

內(nèi)核升級(jí)

[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? ##此步會(huì)有點(diǎn)慢

[root@localhost ~]# vim /etc/grub.conf default=1 改為 default=0? ##設(shè)置默認(rèn)以3.10核心啟動(dòng)址否,默認(rèn)是按照舊的核心啟動(dòng)

[root@localhost ~]# reboot

[root@localhost ~]# uname -a? ##升級(jí)后的版本

CentOS 6.x 安裝 php7.0

一:檢查當(dāng)前是否有安裝php

rpm -qa|grep php

如果有安裝PHP酱畅,那么請(qǐng)先刪除這些安裝包:

?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擴(kuò)展源:

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

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

3.現(xiàn)在開始安裝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

安裝源庫(kù)

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

安裝完成后的默認(rèn)配置文件路徑

默認(rèn)nginx配置文件: /etc/nginx/nginx.conf 【nginx主要的配置文件】

默認(rèn)nginx的ssl配置文件: /etc/nginx/conf.d/ssl.conf 【配置SSL證書的,也可以并入到nginx.conf文件里】

默認(rèn)nginx的虛擬主機(jī)配置文件: /etc/nginx/conf.d/virtual.conf 【如同Apache的虛擬主機(jī)配置,也可以并入到nginx.conf文件里】

默認(rèn)的web_root文件夾路徑: /usr/share/nginx/html 【web目錄夾,放置Magento主程序】

配置iptables

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

(這個(gè)步驟,我之前機(jī)器上已經(jīng)裝過apache所以就忽略了)

安裝后的目錄:


配置目錄:

/etc/nginx/

項(xiàng)目目錄:

/usr/share/nginx/html/

安裝Composer

CentOS下Composer的安裝和使用

1. 下載composer.phar

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

2.把composer.phar移動(dòng)到環(huán)境下讓其變成可執(zhí)行

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

3.測(cè)試

composer -V

中國(guó)全量鏡像

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

安裝 php擴(kuò)展

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 ?

安裝源庫(kù)

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/

項(xiàng)目目錄:

/usr/share/nginx/html/

安裝 php擴(kuò)展

apt-get install php70w-mbstring

apt-get install php70w-dom

nginx 設(shè)置

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;

? ? #}

}

部署負(fù)載

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;

}

~

負(fù)載的 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;

? ? #}

}

上傳項(xiàng)目賦予項(xiàng)目運(yùn)行權(quán)限

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

部署告警

啟動(dòng)命令

nohup php artisan redis:subscribe &

安裝MySQL

Step1: 檢測(cè)系統(tǒng)是否自帶安裝mysql

# yum list installed | grep mysql

Step2: 刪除系統(tǒng)自帶的mysql及其依賴命令:

要?jiǎng)h除干凈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 服務(wù)器命令:

# yum install mysql-community-server

Step5: 啟動(dòng)mysql命令:

# service mysqld start

Step6: 查看mysql是否自啟動(dòng),并且設(shè)置開啟自啟動(dòng)命令:

# chkconfig --list | grep mysqld

# chkconfig mysqld on

Step7: mysql安全設(shè)置命令:

# 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 字段已經(jīng)改名為?authentication_string; 所以密碼語(yǔ)句需要修改為:

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

賦權(quán)限

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時(shí)間:

rm -rf??/etc/localtime

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

-select now()?

MySQL 主主同步

機(jī)器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

機(jī)器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

在機(jī)器A MySQL Client中插入:?

change master to

master_host='機(jī)器B的IP',

master_user='數(shù)據(jù)庫(kù)用戶名',

master_password='數(shù)據(jù)庫(kù)密碼',

master_log_file='mysql-bin.000001',

master_log_pos=154;

在機(jī)器B MySQL Client中插入:

change master to

master_host='機(jī)器A的IP',

master_user='數(shù)據(jù)庫(kù)用戶名',

master_password='數(shù)據(jù)庫(kù)密碼',

master_log_file='mysql-bin.000001',

master_log_pos=154;

MySQL 主從同步

機(jī)器A

server-id=101

user=mysql

log-bin=mysql-bin

機(jī)器B

server-id=102

user=mysql

log-bin=mysql-bin

在機(jī)器B MySQL Client中插入:

change master to

master_host='機(jī)器A的IP',

master_user='數(shù)據(jù)庫(kù)用戶名',

master_password='數(shù)據(jù)庫(kù)密碼',

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設(shè)置密碼:

在配置文件中配置requirepass的密碼(當(dāng)redis重啟時(shí)密碼依然有效)音榜。

redis 127.0.0.1:6379> config set requirepass test123

查詢密碼:

redis 127.0.0.1:6379> config get requirepass

(error) ERR operation not permitted

密碼驗(yàn)證:

redis 127.0.0.1:6379> auth test123

OK

HTTPS 設(shè)置


在使用git進(jìn)行代碼更新時(shí),出現(xiàn)認(rèn)證錯(cuò)誤捧弃,起初認(rèn)為是賬戶和密碼輸入錯(cuò)誤赠叼,可是經(jīng)過再三嘗試,終于確定是git版本太低問題违霞,因此將git升級(jí)到2.x版本嘴办。以下是升級(jí)步驟。

[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户辞、卸載系統(tǒng)原有g(shù)it

[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底燎、驗(yàn)證

[root@test ~]# git --version

git version 2.0.0

項(xiàng)目配置:

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 ? ? ? ? ? : 跳轉(zhuǎn)到文件頭

Shift+g ? : 跳轉(zhuǎn)到文件末尾

centos 安裝擴(kuò)展

CentOS 7 安裝 PHP 7.0以及memcache和redis擴(kuò)展

安裝EPEL

EPEL 是 Extra Packages for Enterprise Linux 的縮寫(EPEL),是用于 Fedora-based Red Hat Enterprise Linux (RHEL) 的一個(gè)高質(zhì)量軟件源弹砚,所以同時(shí)也適用于 CentOS 或者 Scientific Linux 等發(fā)行版双仍。

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

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市桌吃,隨后出現(xiàn)的幾起案子朱沃,更是在濱河造成了極大的恐慌,老刑警劉巖茅诱,帶你破解...
    沈念sama閱讀 218,682評(píng)論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件逗物,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡瑟俭,警方通過查閱死者的電腦和手機(jī)翎卓,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,277評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)摆寄,“玉大人失暴,你說我怎么就攤上這事坯门。” “怎么了逗扒?”我有些...
    開封第一講書人閱讀 165,083評(píng)論 0 355
  • 文/不壞的土叔 我叫張陵古戴,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我矩肩,道長(zhǎng)现恼,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,763評(píng)論 1 295
  • 正文 為了忘掉前任蛮拔,我火速辦了婚禮述暂,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘建炫。我一直安慰自己,他們只是感情好疼蛾,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,785評(píng)論 6 392
  • 文/花漫 我一把揭開白布肛跌。 她就那樣靜靜地躺著,像睡著了一般察郁。 火紅的嫁衣襯著肌膚如雪衍慎。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,624評(píng)論 1 305
  • 那天皮钠,我揣著相機(jī)與錄音稳捆,去河邊找鬼。 笑死麦轰,一個(gè)胖子當(dāng)著我的面吹牛乔夯,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播款侵,決...
    沈念sama閱讀 40,358評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼末荐,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了新锈?” 一聲冷哼從身側(cè)響起甲脏,我...
    開封第一講書人閱讀 39,261評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎妹笆,沒想到半個(gè)月后块请,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,722評(píng)論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡拳缠,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,900評(píng)論 3 336
  • 正文 我和宋清朗相戀三年墩新,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片脊凰。...
    茶點(diǎn)故事閱讀 40,030評(píng)論 1 350
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡抖棘,死狀恐怖茂腥,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情切省,我是刑警寧澤最岗,帶...
    沈念sama閱讀 35,737評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站朝捆,受9級(jí)特大地震影響般渡,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜芙盘,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,360評(píng)論 3 330
  • 文/蒙蒙 一驯用、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧儒老,春花似錦蝴乔、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,941評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至囚衔,卻和暖如春挖腰,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背练湿。 一陣腳步聲響...
    開封第一講書人閱讀 33,057評(píng)論 1 270
  • 我被黑心中介騙來(lái)泰國(guó)打工猴仑, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人肥哎。 一個(gè)月前我還...
    沈念sama閱讀 48,237評(píng)論 3 371
  • 正文 我出身青樓辽俗,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親贤姆。 傳聞我的和親對(duì)象是個(gè)殘疾皇子榆苞,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,976評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容