1. 程式人生 > >YUM倉庫安裝LAMP與LNMP

YUM倉庫安裝LAMP與LNMP

LAMP動態網站部署架構是由一套 Linux+Apache+MySQL+PHP 組成的動態網站系統解決方案.
LNMP動態網站部署架構是由一套 Linux+Nginx+MySQL+PHP 組成的動態網站系統解決方案.
編譯安裝費時費力有時還會出錯誤,下面我們將通過Yum倉庫,快速構建LANMP網站環境.

LAMP

1.配置yum源,安裝依賴


yum install -y wget

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

2.安裝LAMP5環境

yum install -y httpd httpd-devel mariadb mariadb-server mysql-devel php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml

3.安裝LAMP7環境

yum -y install epel-release

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

yum install -y httpd httpd-devel mariadb mariadb-server mysql-devel php70w php70w-intl php70w-mysql php70w-common php70w-gd php70w-mbstring php70w-mcrypt php70w-devel php70w-xml


LNMP

1.配置yum源,安裝依賴

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

yum -y install epel-release
yum install -y pcre pcre-devel zlib zlib-devel openssl openssl-devel libjpeg* libmcrypt libmcrypt-devel

2.安裝Nginx

yum install -y nginx

systemctl start nginx
systemctl enable nginx

3.安裝與配置MySQL

yum install -y mariadb mariadb-server

systemctl start mariadb
systemctl enable mariadb

mysql_secure_installation

4.安裝PHP

yum install -y php php-devel php-fpm \
php-mysql php-common php-gd php-imap \
php-ldap php-odbc php-pear php-xml \
php-xmlrpc php-mbstring php-mcrypt \
php-bcmath php-mhash

systemctl start php-fpm
systemctl enable php-fpm

5.編輯PHP主配置檔案

編輯配置檔案,在PHP檔案末尾追加寫入以下標★語句

vim /etc/php.ini 

★cgi.fix_pathinfo=1                     #將註釋去掉,開啟PHP的pathinfo偽靜態功能
★max_execution_time = 0                 #指令碼執行的最長時間,預設30秒
★max_input_time = 300                   #指令碼可以消耗的時間,預設60秒
★memory_limit = 256M                    #指令碼執行最大消耗的記憶體,根據你的需求更改數值,預設128M
★post_max_size = 100M               #單提交的最大資料,預設100M
★upload_max_filesize = 10M              #上載檔案的最大許可大小,預設2M

6.修改php-fpm的配置

編輯配置檔案,在PHP-fpm檔案中,修改以下標★語句

vim /etc/php-fpm.d/www.conf 

★listen.owner = nobody                  #解除註釋
★listen.group = nobody                  #解除註釋

★user = nginx                       #將apache修改為nginx
★group = nginx                      #將apache修改為nginx

7.修改nginx的主配置

編輯配置檔案,在server語句內,寫入以下標★語句

vim /etc/nginx/nginx.conf

38     server {
39         listen       80 default_server;
40         listen       [::]:80 default_server;
41         server_name  _;
42         root         /usr/share/nginx/html;
43 
44         # Load configuration files for the default server block.
45         include /etc/nginx/default.d/*.conf;
46 
★         location / {
★ 
★         root   /usr/share/nginx/html;
★         index index.php index.html index.htm;
★ 
52         }
53 
★         location ~ \.php$ {
★         root           /usr/share/nginx/html;
★         try_files $uri =404;
★         fastcgi_pass   127.0.0.1:9000;
★         fastcgi_index  index.php;
★         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
★         include        fastcgi_params;
★         }
62 
63         error_page 404 /404.html;
64             location = /40x.html {
65         }

8.設定網頁目錄許可權

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

9.新建index.php測試頁

vim /usr/share/nginx/html/index.php

<?php
    phpinfo();
?>

10.重啟服務,並檢視9000埠是否啟動成功

systemctl restart nginx
systemctl restart php-fpm
systemctl restart mariadb

netstat -npa | grep 9000