1. 程式人生 > >linux自學筆記--lamp簡單配置

linux自學筆記--lamp簡單配置

linux

1.httpd配置

(1)基本設置

Listen 80 端口

DocumentRoot /var/www 根目錄

DirectoryIndex index.html 主頁

Alias /icon/ "/download/newicon" 路徑別名

ErrorDocument 404 /missing.html 404文件

ExtendeStatus On 220行左右,狀態頁面,在920左右定義具體

(2)訪問控制

<Directory "/var/www/html">

Options Indexes FollowSymLinks

AllowOverride None

Order allow,deny

Allow from all

</Directory>

Indexes:若頁面無法訪問則提供結構列表,應註釋掉

FollowSymLinks:若在根目錄下的文件,鏈接到非此目錄,默認為 失敗,設置此項可讓鏈接離開目錄限制

AllowOverride:是否允許.htaccess功能覆蓋

Order: allow,deny開放所有,拒絕特定條件。deny,allow拒絕所 有,開放特定條件

Allow|deny from x.x.x.x:允許或拒絕特定網址或網段

(3)持久連接

KeepAlive on|off

KeepAliveTimeout 15默認,不宜太高

MaxKeepAliveRequests 500 默認100,最大超時請求數量

優點:一次連接處理多個請求,無需每個小圖片都建立一次tcp請求

缺點:大並發服務器,後續請求可能無法及時響應

(4)MPM

prefork: 多進程模型

worker: 多進程多線程模型

pstree | grep ‘httpd‘ 能查看到具體區別

配置文件: centos6 /etc/sysconfig/httpd

centos7 /etc/httpd/conf.modules.d/00-mpm.conf

(5)虛擬主機 需要註釋掉DocumentRoot

基於ip或端口區分不同網站

<VirtualHost 192.168.1.10:80>

ServerName www.mage.com

DocumentRoot ‘/www/mage.com/htdocs‘

</VirtualHost>

-------------------------------------------------

基於主機名,需要設置DNS或hosts文件解析

NameVirtualHost 192.168.1.10:80 註意2.4不需要

<VirtualHost 192.168.1.10:80>

ServerName www.mage.com

Document ‘/www/mage.com/htdocs‘

</VirtualHost>

<VirtualHost 192.168.1.10:80>

ServerName www.niaoge.com

Document ‘/www/niaoge.com/htdocs‘

</VirtualHost>


2.mariadb

(1)admin密碼: mysqladmin -uroot password 123

(2)修改admin密碼: mysqladmin -uroot -p123 Password

(3)授權: grant all on dbname.tbname to ‘user‘@‘ipaddr‘ identified by ‘password‘;

使用任意數據:*.*

任意地址:%

(4)修改用戶密碼:

use mysql;

update user set Password=password(‘456‘) where User=‘root‘;

flush privileges;

(5)拒絕反解析 /etc/my.cnf

[mysqld]

skip_name_resolve=ON;

3.編譯安裝lamp

(1)httpd

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

--sysconfdir=/etc/httpd

--with-apr=/usr --with-apr-util=/usr

(2)mariadb

復制support-files下配置文件到/etc/mysql/my.cnf,復制 mysql.server到/etc/init.d/mysqld

chkconfig --add mysqld

初始化數據庫,在/usr/local/mysql下使用scripts /mysql_install_db --user=mysql --datadir=/path

(3)php

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

--with-mysql=/usr/local/mysql

--with-mysqli=/usr/local/mysql/bin/mysql_config

--with-config-file-path=/etc

--with-config-file-scan-dir=/etc/php.d

--with-apxs2=/usr/local/httpd/bin/apxs 將編譯為模塊使用

linux自學筆記--lamp簡單配置