1.什麼是LNMP架構php
2.LNMP架構是如何工做的css
location / {
index index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
}
location ~ \.(jpg|png|gif)$ {
root /code/images;
}
3.nginx與php,mysql之間是如何工做的。mysql
4.如何安裝LNMP架構nginx
安裝phpweb
配置擴展源redis
yum localinstall -y http://mirror.webtatic.com/yum/el7/webtatic-release.rpmsql
安裝php7.1mongodb
yum -y install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb數據庫
啓動phpcentos
systemctl start php-fpm
安裝mysql
touch /etc/yum.repos.d/mariadb.repo
而後寫入以下內容
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
安裝
yum install mariadb-server mariadb -y
啓動
systemctl start mariadb
5.nginx與php集成的原理
1.編寫能解析的php的nginx配置文件
[root@web01 conf.d]# cat php.oldxu.com.conf
server {
listen 80;
server_name php.oldxu.com;
root /code;
location / {
index index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
5.2.編寫PHP代碼,測試訪問效果.
[root@web01 conf.d]# cat /code/info.php
<?php
phpinfo();
?>
5.3host劫持
6.php與mysql集成的原理
6.1啓動數據庫
[root@web01 ~]# systemctl start mariadb
6.2.配置鏈接密碼
[root@web01 ~]# mysqladmin password oldxu.com
6.3測試登陸mysql
[root@web01 ~]# mysql -uroot -poldxu.com
MariaDB [(none)]>
6.4編寫php鏈接數據庫的代碼
[root@web01 ~]# /code/mysqli.php <?php $servername = "localhost"; $username = "root"; $password = "oldxu.com"; // 建立鏈接 $conn = mysqli_connect($servername, $username, $password); // 檢測鏈接 if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } echo "php鏈接MySQL數據庫成功"; ?>
6.5測試
(1)[root@web01 ~]# php /code/mysqli.php
(2)也能夠經過瀏覽器的方式去測試
7.經過LNMP架構部署Wordpress、Wecenter、edusoho、phpmyadmin、ecshop、
7.1例
7.1.1.編寫Nginx集成PHP的配置文件 (定義域名以及站點的目錄位置)
[root@web01 conf.d]# cat blog.oldxu.com.conf
server {
listen 80;
server_name blog.oldxu.com;
root /code/wordpress;
location / {
index index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
7.1.2.根據Nginx配置,初始化環境,而後上傳代碼
1.準備站點目錄
[root@web01 conf.d]# mkdir /code
2.下載wordpress代碼
[root@web01 conf.d]# cd /code
[root@web01 code]# tar xf wordpress-5.2.3-zh_CN.tar.gz
3.建立數據庫名
[root@web01 code]# mysql -uroot -poldxu.com
MariaDB [(none)]> create database wordpress;
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| wordpress |
+--------------------+
5 rows in set (0.01 sec)
4.統一Nginx PHP的權限 爲 www
[root@web01 code]# groupadd www -g 666
[root@web01 code]# useradd -u666 -g666 www
[root@web01 code]# sed -i '/^user/c user www;' /etc/nginx/nginx.conf
[root@web01 code]# chown -R www.www /code
[root@web01 code]# systemctl restart nginx
[root@web01 code]# sed -i '/^user/c user = www' /etc/php-fpm.d/www.conf
[root@web01 code]# sed -i '/^group/c group = www' /etc/php-fpm.d/www.conf
[root@web01 code]# systemctl restart php-fpm
7.2wecenter:
1.編寫Nginx的配置文件 虛擬主機
[root@web01 conf.d]# cat zh.oldxu.com.conf
server {
listen 80;
server_name zh.oldxu.com;
root /code/zh;
client_max_body_size 100m;
location / {
index index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
2.上傳代碼,變動代碼的屬主和屬組
[root@web01 conf.d]# cd /code
[root@web01 conf.d]# rz WeCenter_3-3-2.zip
[root@web01 conf.d]# mkdir zh
[root@web01 conf.d]# unzip WeCenter_3-3-2.zip -d /code/zh/
[root@web01 code]# chown -R www.www /code
3.登陸數據庫.建立庫名稱
[root@web01 code]# mysql -uroot -poldxu.com
MariaDB [(none)]> create database zh;
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| wordpress |
| zh |
+--------------------+
6 rows in set (0.00 sec)
3.重啓Nginx服務
[root@web01 code]# systemctl restart nginx
4.配置host劫持
7.3edusoho視頻網站
配置文件
server {
listen 80;
server_name www.xxxx.com;
root /code/edusoho/web;
# 日誌路徑
access_log /var/log/nginx/example.com.access.log;
error_log /var/log/nginx/example.com.error.log;
location / {
index app.php;
try_files $uri @rewriteapp;
}
location @rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}
location ~ ^/udisk {
internal;
root /code/edusoho/app/data/;
}
location ~ ^/(app|app_dev)\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
fastcgi_param HTTP_X-Sendfile-Type X-Accel-Redirect;
fastcgi_param HTTP_X-Accel-Mapping /udisk=/code/edusoho/app/data/udisk;
fastcgi_buffer_size 128k;
fastcgi_buffers 8 128k;
}
# 配置設置圖片格式文件
location ~* \.(jpg|jpeg|gif|png|ico|swf)$ {
# 過時時間爲3年
expires 3y;
# 關閉日誌記錄
access_log off;
# 關閉gzip壓縮,減小CPU消耗,由於圖片的壓縮率不高。
gzip off;
}
# 配置css/js文件
location ~* \.(css|js)$ {
access_log off;
expires 3y;
}
# 禁止用戶上傳目錄下全部.php文件的訪問,提升安全性
location ~ ^/files/.*\.(php|php5)$ {
deny all;
}
# 如下配置容許運行.php的程序,方便於其餘第三方系統的集成。
location ~ \.php$ {
# [改] 請根據實際php-fpm運行的方式修改
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}