一、當前互聯網主流web服務 靜態服務: 1.apache 中小型靜態web服務的主流,web伺服器中的老大哥 2.nginx 大型新型網路靜態web服務主流,web伺服器中的初生牛犢 3.lighttpd 靜態web服務不溫不火,逐漸被淘汰的意味,社區不活躍,效率很高。 動態服務: 1.IIS(I ...
一、當前互聯網主流web服務
靜態服務:
1.apache---中小型靜態web服務的主流,web伺服器中的老大哥
2.nginx---大型新型網路靜態web服務主流,web伺服器中的初生牛犢
3.lighttpd---靜態web服務不溫不火,逐漸被淘汰的意味,社區不活躍,效率很高。
動態服務:
1.IIS(Internet information services)---微軟的web伺服器(asp、aspx)
2.tomcat---中小企業動態web服務主流,互聯網java容器主流(jsp,do)
3.resin---大型動態網站web服務主流,互聯網java容器主流(jsp,do)
4.php(fcgi)---大中小網站,php程式的解析容器
a.配合apache,php不是守護進程,而是mod_php5.so(module)
b.配合nginx,lighttpd,php守護進程模式,FCGI模式。
二、apache的安裝
1.首先確定安裝httpd服務(yum install httpd -y)
確定:yum install gcc gcc++ zlib zlib-devel -y
2.安裝apache(地址http://apache.fayea.com/httpd/上官網上找)
apache源碼編譯:
./configure --prefix=/application/apache2.2.32 \
--enable-expires \
--enable-headers \
--enable-modules=most \
--enable-so \
--with-mpm=worker \
--enable-deflate \
--enable-rewrite
make &&make install
3.啟動apache服務:
1)查看apache語法是否可行:[root@localhost local]# /application/apache/bin/apachectl -t
2)啟動apache服務:[root@localhost local]# /application/apache/bin/apachectl start
3)查看是否啟動apache服務:lsof -i:80或者ps -ef|grep apache
it works 表示成功
如果不ok檢查埠,防火牆,selinux,進程
strace追蹤進程的命令
修改編譯內容在/application/apache/htdocs/下 有index.html
三、/application/apache目錄結構
apache優化1.把root@localhost conf]# vi httpd.conf 里的Index前面加-號或者直接刪除
/application/apache/conf/extra 三個重點文件
四、虛擬主機
1.虛擬主機:部署多個站點,每個站點希望用不同的功能變數名稱和站點目錄,或者是不同的埠,不同的IP的時候需要虛擬主機。
一句話,一個http服務要配置多個站點,就需要虛擬機。
虛擬機分類:
a.基於功能變數名稱
b.基於埠
c.基於IP
2.搭建虛擬機(基於功能變數名稱)
功能變數名稱 站點目錄
www.etiantian.org /var/html/www
blog.etiantian.org /var/html/blog
bbs.etiantian.org /var/html/bbs
創建主頁文件:
[root@localhost apache]# mkdir /var/html/{www,blog,bbs} -p
[root@localhost apache]# touch /var/html/{www,blog,bbs}/index.html
[root@localhost apache]# for name in www blog bbs;do echo "http://$name.etiantian.org" >/var/html/$name/index.html;done
[root@localhost apache]# for name in www blog bbs;do cat /var/html/$name/index.html;done
vim /application/apache/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/var/html/www"
ServerName www.etiantian.org
ServerAlias etiantian.org
ErrorLog "logs/www-error_log"
CustomLog "logs/www-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/var/html/blog"
ServerName blog.etiantian.org
ErrorLog "logs/blog-error_log"
CustomLog "logs/blog-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/var/html/bbs"
ServerName bbs.etiantian.org
ErrorLog "logs/bbs-error_log"
CustomLog "logs/bbs-access_log" common
</VirtualHost>
vim /application/apache/conf/httpd.conf(去點下兩行註釋)
[root@localhost extra]# /application/apache/bin/apachectl -t
Syntax OK
檢查語法
[root@localhost extra]# /application/apache/bin/apachectl graceful 重啟apache
vim /application/apache/conf/httpd.conf 在最末行加入下麵的內容:
<Directory "/application/apache2.2.32/htdocs">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
以上配置是防止403出錯,之後檢查語法是否錯誤http://blog.csdn.net/u011130583/article/details/42363831(有錯誤查看
修改windows本地system32 drives hosts (192.168.76.128 www.etiantian.org blog.etiantian.org bbs.etiantian.org
)
[root@localhost extra]# grep "^Include" /application/apache/conf/httpd.conf
Include conf/extra/httpd-mpm.conf
Include conf/extra/httpd-vhosts.conf
一.mysql
創建mysql:useradd mysql -g mysql -M -s /sbin/nologin
mysql的編譯:
./configure --prefix=/application/mysql5.1.72 \
--with-unix-socket-path=/application/mysql5.1.72/tmp/mysql.sock \
--localstatedir=/application/mysql5.1.72/data \
--enable-assembler \
--enable-thread-safe-client \
--with-mysqld-user=mysql \
--with-big-tables \
--without-debug \
--with-pthread \
--enable-assembler \
--with-extra-charsets=complex \
--with-readline \
--with-ssl \
--with-embedded-server \
--enable-local-infile \
--with-plugins=partition,innobase \
--with-mysqld-ldflags=-all-static \
--with-client-ldflags=-all-static
yum -y install ncurses-devel(出錯解決方案)
root@localhost application]# cd /home/cai/tools/
[root@localhost tools]# cd mysql-5.1.72/support-files/
[root@localhost support-files]# cp my-small.cnf /etc/my.cnf
cp:是否覆蓋"/etc/my.cnf"? y
[root@localhost support-files]# cd /etc/
[root@localhost etc]# less my.cnf
[root@localhost etc]# mkdir /application/mysql/date -p
[root@localhost etc]# chown -R mysql.mysql /application/mysql
[root@localhost etc]#/application/mysql/bin/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data/ --user=mysql
Installing MySQL system tables...
170314 20:15:22 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
OK
Filling help tables...
170314 20:15:22 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/application/mysql/bin/mysqladmin -u root password 'new-password'
/application/mysql/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
Alternatively you can run:
/application/mysql/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /application/mysql ; /application/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /application/mysql/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /application/mysql/scripts/mysqlbug script!
啟動mysql :/application/mysql/bin/mysqld_safe &(啟動服務註意添加到開機自啟動)
[root@localhost support-files]# netstat -lntup|grep mysql (確認是否啟動了該服務)
vi /etc/profile在最後添加用戶一行
關閉:
mysqladmin shutdown
/application/mysql/bin/mysqladmin -u root -h localhost.localdomain password 'new-password' 設置密碼
mysql -uroot -p(設置過密碼後登錄mysql的方法)
二、php
LAMP下的php
apache==》libphp5.so
nginx php==》fcgi php-
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers(需要安裝的各種庫)
yum install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel -y(oldboy里的)
libiconv庫需要(編譯安裝)
php編譯:
./configure \
--prefix=/application/php5.3.27 \
--with-apxs2=/application/apache/bin/apxs \
--with-mysql=/application/mysql \
--with-xmlrpc \
--with-openssl \
--with-zlib \
--with-freetype-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-iconv=/usr/local/libiconv \
--enable-short-tags \
--enable-sockets \
--enable-zend-multibyte \
--enable-soap \
--enable-mbstring \
--enable-static \
--enable-gd-native-ttf \
--with-curl \
--with-xsl \
--enable-ftp \
--with-libxml-dir
[root@localhost php]# ll /application/apache/modules/
總用量 23908
-rw-r--r-- 1 root root 9262 4月 15 09:27 httpd.exp
-rwxr-xr-x 1 root root 24465701 4月 15 10:15 libphp5.so
[root@localhost php]# grep libphp5 /application/apache/conf/httpd.conf
LoadModule php5_module modules/libphp5.so
配置php文件:
有兩個,一個是生產環境 一個是開發環境(測試環境)
[root@localhost php-5.3.27]# diff php.ini-development php.ini-production
[root@localhost php-5.3.27]# cp php.ini-production /application/php/lib/php.ini
小結:正式配置文件一般關閉顯示LOG,不輸出LOG
配置apache支持php
vim /application/apache/conf/httpd.conf 修改98行 ServerName 192.168.76.128:80
vim /application/apache/conf/httpd.conf 在311行下添加兩行
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
user daemon 修改為其他的 底下的也該(預設的大家都知道必須修改)
166行 修改為
[root@localhost conf]# diff httpd.conf httpd.conf.ori
67,68c67,68
< User www
< Group www
---
> User daemon
> Group daemon
168c168
< DirectoryIndex index.php index.html
---
> DirectoryIndex index.html
320,321d319
< AddType application/x-httpd-php .php .phtml
< AddType application/x-httpd-php-source .phps
添加www用戶:useradd www -s /sbin/nologin -M
[root@localhost conf]# /application/apache/bin/apachectl graceful 重啟apache服務
測試php 在以建的虛擬機中 /var/html/blog vi index.php
[root@localhost blog]# cat index.php
<?php
phpinfo();
?>
出現這個界面表示php+apache成功
vi /var/html/blog/index.php
<?php
//$link_id=mysql_connect('主機名','用戶','密碼');
$link_id=mysql_connect('localhost','root','oldboy123') or mysql_error();
if($link_id){
echo "mysql successful by oldboy !";
}else{
echo mysql_error();
}
?>
上界面表示mysql成功