1. 程式人生 > >yum 快速LAMP/LNMP 安裝(centos7+mysql5.7+apache+php5.6 (缺點:好多模組沒有載入)

yum 快速LAMP/LNMP 安裝(centos7+mysql5.7+apache+php5.6 (缺點:好多模組沒有載入)

1.安裝Apache

安裝centos7預設自帶(Apache2.4.6)版本

yum -y install httpd

 

2.開啟apache服務

systemctl start httpd.service

 

3.設定apache服務開機啟動

systemctl enable httpd.service

 

4.開啟防火牆

firewall-cmd --permanent --zone=public --add-service=https

firewall-cmd --reload

firewall-cmd --permanent --zone=public --add-service=http

 

5.開啟80埠

firewall-cmd --zone=public --add-port=80/tcp --permanent

在瀏覽器中輸入你虛擬機器的ip地址,如果看到apache預設的頁面--有Testing 123...字樣,便是成功安裝了apache服務了

 

6.安裝php

a、預設centos7 自帶的是php5.4版本,升級php5.6。不升級只有yum 安裝

b、升級php5.6

yum install epel-release

rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

 

7.安裝PHP5.6.x

yum源配置好了,下一步就安裝PHP5.6

yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof php-gd php-redis

安裝PHP-fpm

yum install --enablerepo=remi --enablerepo=remi-php56 php-fpm

 

8.重啟apache

systemctl restart httpd.service

 

9.測試是否成功

然後,你可以寫一個php檔案在瀏覽器中執行一下了;
eg:
vi /var/www/html/info.php
i
<?php phpinfo(); ?>
Esc
:wq
然後,在自己電腦瀏覽器輸入 虛擬機器ip/info.php執行,會出現php的配置一些資訊安裝成功

-------------------------------------下面安裝nginx-----------------------------------------------------------------------------------

1. 在安裝nginx前,先要安裝依賴包

yum -y install gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl-devel

 

2.下載nginx對應的tar包

wget http://nginx.org/download/nginx-1.13.7.tar.gz

 

3.解壓tar 包

tar zxvf nginx-1.13.7.tar.gz

 

4.建立nginx 目錄

mkdir -p /usr/local/nginx

進入

cd nginx-1.13.7

./configure --prefix=/usr/local/nginx

make && make install

 

5.進入nginx/sbin目錄啟動nginx

cd /use/local/nginx/sbin

啟動nginx

./nginx

 

6.Nginx中其他簡單的操作也類似

cd /use/local/nginx/sbin

重新載入配置

./nginx -s reload

重新啟動Nginx

./nginx -s reopen

停止Nginx

./nginx -s stop

 

7.php-fpm,並設定php-fpm開機自啟

service php-fpm start

chkconfig php-fpm on

 

8.在相應的目錄下找到nginx.conf配置檔案,這裡是在預設目錄下,開啟Nginx支撐PHP的模組


cd /usr/local/nginx/conf 進入Nginx配置目錄

vim nginx.conf 配置nginx.conf檔案

 

修改前

#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;

修改後

location ~ \.php$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

 

首先將註釋,也就是#號去掉,接著將fastcgi_param對應的/scripts$fastcgi_script_name改成$document_root$fastcgi_script_name

儲存完修改後的配置,重啟一下nginx,讓配置生效,我們就可以通過nginx來處理PHP請求了

-----------------------------------------nginx end----------------------------------------------------------------------------

 

-------------------------------------------------安裝mysql----------------------------------------------------------------------------------------

1.安裝mysql5.7

centos7不自帶mysql5.7 rmp 包需自己手動步驟如下

rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

// 或者使用
wget http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
rpm -ivh mysql57-community-release-el7-9.noarch.rpm

 

2.安裝mysql5.6

yum -y install mysql-community-server

 

3.配置mysql

MySQL 安裝完成之後,在 /var/log/mysqld.log 檔案中給 root 生成了一個預設密碼

通過下面的方式找到root 預設密碼,然後登入 MySQL 進行修改:

systemctl start mysqld

grep 'temporary password' /var/log/mysqld.log # 查詢預設密碼

2017-04-10T02:58:16.806931Z 1 [Note] A temporary password is generated for [email protected]: !E+rhl4VGhh(密碼)安裝完成之後,在 /var/log/mysqld.log 

 

4.登入 MySQL:(如果登入不成功提示錯誤請用步驟4)

mysql -uroot -p'!E+rhl4VGhh'

修改root 預設密碼:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyPass1!';
或者:

mysql> set password for 'root'@'localhost'=password('123abc');

注:

MySQL5.7 預設安裝了密碼安全檢查外掛(validate_password),預設密碼檢查策略要求密碼必須包含:大小寫字母、數字和特殊符號,並且長度不能少於8位。否則會提示 ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 錯誤

5.配置mysql

登入資料庫對mysq進行操作

mysql -uroot -p'密碼'

show databases;