Centos6.6用yum快速安裝LA(N)MP

本文主要介紹在CentOS6.6下用yum快速搭建LAMP或LNMP環境
php


基本流程:
html

  1.安裝apche或nginxmysql

  2.安裝mysqllinux

  3.安裝phpnginx

  4.測試環境redis




流程一:安裝apache或nginx
sql


1)關閉SELINUX
apache

修改配置文件,重啓服務後永久生效。vim

sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/configcentos

命令行設置當即生效。

setenforce 0

網易官方源
centos6.x
cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.$(date +%F)
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
yum clean all
yum makecache

更多國內知名yum源可參考:https://blog.51cto.com/13707680/2104644

2)安裝Apache:

yum -y install httpd

yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql

/etc/init.d/httpd start 

netstat -tnlp|grep 80


安裝nginx:

Centos6系統庫中默認是沒有nginx的rpm包的,因此咱們須要先更新下rpm依賴庫

1)使用yum安裝nginx,安裝nginx庫

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

2)使用下面命令安裝nginx

yum -y install nginx

[root@localhost ~]# nginx -v 

nginx version: nginx/1.14.0

3)啓動nginx

/etc/init.d/nginx start 或 service nginx start

4 ) 防火牆容許經過80端口

vim /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT 

/etc/init.d/iptables restart




流程二:安裝mysql


1)安裝Mysql,先更新yum源。yum源下載地址,根據本身須要的版本選擇相應的源

https://dev.mysql.com/downloads/repo/yum/

2)這裏版本是6.x系列的,因此選擇linux 6 下載

wget https://repo.mysql.com//mysql57-community-release-el6-11.noarch.rpm

3)安裝mysql的yum源

rpm -Uvh mysql57-community-release-el6-11.noarch.rpm  或 yum -y localinstall mysql57-community-release-el6-11.noarch.rpm

4)查看mysql源是否成功

[root@localhost yum.repos.d]# ls /etc/yum.repos.d/|grep mysql

mysql57-community-release-el6-11.noarch.rpm

mysql-community.repo

mysql-community-source.repo

5)安裝mysql

yum -y install mysql-community-server

[root@localhost ~]# mysql -V

mysql  Ver 14.14 Distrib 5.7.22, for Linux (x86_64) using  EditLine wrapper

6)開啓mysql,並更改默認密碼

/etc/init.d/mysqld start 

netstat -tnlp |grep 3306

chkconfig mysqld on

[root@localhost yum.repos.d]# grep 'temporary password' /var/log/mysqld.log 

2018-05-10T22:59:11.434638Z 1 [Note] A temporary password is generated for root@localhost: OScMFRu&j75Q

mysql -uroot -p"OScMFRu&j75Q"

ALTER USER 'root'@'localhost' IDENTIFIED BY 'ywxi123';

mysql -uroot -p"ywxi123"

7)防火牆容許經過3306端口

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

service iptables restart




流程三:安裝php


1)更新yum源

rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm

rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

2)安裝PHP

yum -y install --enablerepo=remi --enablerepo=remi-php56 php php-bcmath php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-gd php-xml php-memcache php-redis php-fpm php-mysql php-common php-mssql

3)配置php.ini文件,關閉php信息頭

sed 's#expose_php = On#expose_php = Off#g' /etc/php.ini -i

[root@localhost html]# php -v

PHP 5.6.36 (cli) (built: Apr 25 2018 10:11:47)

4)啓動php,並開機自啓

/etc/init.d/php-fpm start

chkconfig php-fpm on




流程四:環境測試


1)LNMP環境測試準備

編輯/etc/nginx/conf.d/default.conf,在所支持的主頁面格式中添加php格式的主頁,相似以下:

[root@localhost conf.d]# cat default.conf 

server {

    listen       80;

    server_name  localhost;


    #charset koi8-r;

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


    location / {

        root   /usr/share/nginx/html;

        index index.php 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           /usr/share/nginx/html;

        fastcgi_pass   127.0.0.1:9000;

        fastcgi_index  index.php;

        fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html/$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;

    #}

}


[root@localhost html]# cat /usr/share/nginx/html/index.php 

<?php

$conn=mysql_connect('127.0.0.1','root','ywxi123');

if ($conn){

echo "LNMP platform connect to mysql is successful!";

}else{

echo "LNMP platform connect to mysql is failed!";

}

phpinfo();

?>

chown -R nginx.nginx /usr/share/nginx/html/

http://192.168.1.22/index.php 訪問到以下頁面證實LNMP環境搭建成功

image.png





2)LAMP環境測試準備

/etc/init.d/nginx stop

/etc/init.d/httpd start

[root@localhost html]# cat /var/www/html/index.php 

<?php

$conn=mysql_connect('127.0.0.1','root','ywxi123');

if ($conn){

echo "LAMP platform connect to mysql is successful!";

}else{

echo "LAMP platform connect to mysql is failed!";

}

phpinfo();

?>

chown -R apache.apache /var/www/html

http://192.168.1.22/index.php 訪問到以下頁面證實LAMP環境搭建成功

image.png

相關文章
相關標籤/搜索