首頁 > 運維 > linux運維 > 主體

LAMP=Linux+Apache+Mysql+Php

巴扎黑
發布: 2017-06-23 14:34:40
原創
2829 人瀏覽過

一、目前網路主流web服務

靜態服務:

1.apache---中小型靜態web服務的主流,web伺服器中的老大哥

2.nginx---大型新型網路靜態web服務主流,web伺服器中的初生牛犢

3 .lighttpd---靜態web服務不溫不火,逐漸被淘汰的意味,社群不活躍,效率很高。

動態服務:

1.IIS(Internet information services)---微軟的##web伺服器(aspaspx

2.tomcat---

中小企業動態web服務主流,網際網路java容器主流(jspdo

3.resin---

大型動態網站web服務主流,網路 java容器主流(jspdo

# 4.php

fcgi---大中小網站,php 程式的解析容器

  a.

配合#apachephp不是守護進程,而是mod_php5.so(module)

  b.

配合nginxlighttpdphp#守護程式模式,FCGI模式。

 

二、apache

的安裝

#1.

首先確定安裝#httpd 服務(yum install httpd -y

#確定:yum install gcc gcc++ zlib zlib-devel -y

2.

安裝apache(位址#上官網路找)

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]

apache優化1.把root@localhost conf]# vi httpd.conf 裡的Index前面加-號或直接刪除

/application/apache/conf/extra

三個重點檔案

四、虛擬主機

1.

虛擬主機:部署多個站點,每個站點希望用不同的網域名稱和站點目錄,或是不同的端口,不同的

IP

的時候需要虛擬主機。

一句話,一個

http

服務要配置多個站點,就需要虛擬機器。

虛擬機器分類:

a.基於網域名稱b.基於連接埠

c.

基於IP

 

2.搭建虛擬機器(網域名稱)

2.搭建虛擬機器(網域名稱)

#              

             

# | www.etiantian.org

        /var/html/www

blog.etiantian.org        /var/html/blog

## 

#建立主頁檔案:

[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

ServerAdmin 928939638@qq .com

DocumentRoot "/var/html/www"

ServerName www.etiantian.org

ServerAlias etiantian.org

#ErrorLog "logs/www -error_log"

CustomLog "logs/www-access_log" common

 

 

 

ServerAdmin 928939638@qq.com

DocumentRoot "/var/html/blog"

ServerName blog.etiantian.org

ErrorLog "logs/blog-error_log "

CustomLog "logs/blog-access_log" common#######
###### ######################### ##ServerAdmin 928939638@qq.com######DocumentRoot "/var/html/bbs"######ServerName bbs.etiantian.org######ErrorLog "logs/bbs-error_log"# #####CustomLog "logs/bbs-access_log" common############ ######vm /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 在最末行加入下面的內容:

Options FollowSymLinks

AllowOverride None

#Order allow,deny

##Allow from all

以上設定是防止403出錯,之後檢查語法是否錯誤(有錯誤檢視

 

修改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

建立mysqluseradd 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

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-passwordsqladmin -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##databases and anonymous user created by default. This is

##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 bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel bzip-m^m openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers(需要安裝的各種函式庫)

 

yum install zlib libxml libjpeg freetype # 

yum install zlib libxml libjpeg 是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# 

 

vim /application/apache# 

 

vim /application/apache# 

 

vim /application/apache# 

 

vim/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+apache成功####### ######vi /var/html/blog/index.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####成功#######

以上是LAMP=Linux+Apache+Mysql+Php的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板