搭建LAMP服務器

LAMP  網站運行平臺 Linux  Apache  MySQL   PHP

網站的網頁文件用PHP語言開發的

網站服務器用apache軟件實現

網站運行過程中產生的數據保存到數據庫裏,數據庫軟件用mysql

Php apache mysql安裝在linux操作系統中。

Php apache mysql開源且跨平臺。

用rpm包搭建lamp環境

Yum –y install  php  mysql-sever  httpd

用源碼包搭建lamp環境。

安裝前的準備工作

1、 配置固定IP地址

2、 安裝開發工具和開發庫軟件包組

3、 準備安裝需要的源碼包

4、 把當前主機上rpm包提供的網站服務mysql數據庫服務停止並設置開機不自啓

安裝apache源碼包。PHP要最後安裝,apache和mysql先安裝。

[root@www LAMP]# tar zxvf httpd-2.2.25.tar.gz -C /usr/src/

[root@www src]# cd /usr/src/httpd-2.2.25/

--prefix  指定安裝目錄

--enable-so  支持動態加載模塊

--enable-rewrite 支持網站地址重寫

-- enalbe-cgi  支持CGI程序腳本

CGI 通用網關接口。可以通過頁面執行操作。

--enable-charset-lite  支持多語言編碼

--enable-ssl  支持ssl加密

--enable-suexec  支持setuid權限封裝

--with-suexec-caller=daemon 指定suEXEC用戶。源碼包安裝apache的進程所有者爲daemon。

[root@www httpd-2.2.25]# grep daemon /etc/passwd

daemon:x:2:2:daemon:/sbin:/sbin/nologin

沒有daemon用戶需手動添加上

--with-suexec-docroot  指定suEXEC目錄

[root@www httpd-2.2.25]# ./configure --prefix=/usr/local/apache --enable-so --enable-rewrite --enable-cgi --enable-charset-lite --enable-ssl

[root@www httpd-2.2.25]# make

[root@www httpd-2.2.25]# make install

[root@www apache]# cd /usr/local/apache/

[root@www apache]# ls

bin    cgi-bin  error   icons    logs  manual

build  conf     htdocs  include  man   modules

conf  配置文件目錄。主配置文件httpd.conf.

logs  日誌文件目錄。

modules 模塊目錄。

bin   可執行腳本目錄。

htdocs  網頁目錄

[root@www apache]# bin/apachectl start

[root@www apache]# netstat -antup | grep :80

tcp        0      0 :::80                       :::*                        LISTEN      24227/httpd         

[root@www apache]# elinks --dump http://localhost

                                   It works!

[root@www apache]# vim  /etc/init.d/myhttpd

[root@www apache]# cp bin/apachectl /etc/init.d/myhttpd

#chkconfig:35 85 15

# description: Apache is a World Wide Web server.

[root@www init.d]# chkconfig --add myhttpd

[root@www init.d]# chkconfig --list myhttpd

[root@www init.d]# service myhttpd stop

[root@www init.d]# elinks --dump http://localhost

ELinks: 拒絕連接

[root@www init.d]# service myhttpd start

[root@www init.d]# elinks --dump http://localhost

                                   It works!

進程名     httpd

監聽端口   80

傳輸協議   tcp

進程所有者 daemon

安裝mysql

[root@www ~]# useradd -M -s /sbin/nologin mysql

[root@www ~]# grep mysql /etc/passwd

mysql:x:501:501::/home/mysql:/sbin/nologin

[root@www mysql-5.1.62]# ./configure --prefix=/usr/local/mysql --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charset=gbk,gb2312

[root@www mysql-5.1.62]# make&&make install

[root@www local]# cd /usr/local/mysql/

[root@www mysql]# ls

bin  docs  include  lib  libexec  mysql-test  share  sql-bench

bin 啓動腳本目錄

創建主配置文件

[root@www support-files]# pwd

/usr/src/mysql-5.1.62/support-files

[root@www support-files]# cp my-medium.cnf /etc/my.cnf

初始化授權庫

[root@www bin]# pwd

/usr/local/mysql/bin

[root@www bin]# ./mysql_install_db --user=mysql

[root@www mysql]# pwd

/usr/local/mysql

[root@www mysql]# ls

bin  docs  include  lib  libexec  mysql-test  share  sql-bench  var

var  數據庫目錄

啓動服務

[root@www bin]# pwd

/usr/local/mysql/bin

[root@www bin]# ./mysqld_safe --user=mysql &

[root@www bin]# jobs

[1]+  Running                 ./mysqld_safe --user=mysql &

[root@www bin]# ./mysql -uroot -p

給源碼的數據庫服務添加啓動腳本。

[root@www support-files]# pwd

/usr/src/mysql-5.1.62/support-files

[root@www support-files]# cp mysql.server /etc/init.d/mysql

[root@www init.d]# pwd

/etc/init.d

[root@www init.d]# chmod +x mysql

[root@www init.d]# chkconfig --add mysql 

[root@www init.d]# chkconfig --list mysql

[root@www bin]# netstat -antup | grep :3306

tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      6688/mysqld         

[root@www bin]# PATH=$PATH:/usr/local/mysql/bin/

[root@www bin]# echo $PATH

/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin:/usr/local/mysql/bin/

[root@www bin]# vim /etc/bashrc

export PATH=$PATH:/usr/local/mysql/bin/

連接數據庫服務器:數據庫管理員從本機登陸沒有密碼

[root@www bin]# mysql -uroot -p

將庫文件和頭文件鏈接到默認的系統目錄下。

把源碼包安裝目錄的庫文件和頭文件鏈接到系統默認的庫文件頭文件存放的目錄。其他程序鏈接mysql服務需要庫文件和頭文件,所以需要做此操作。Apache是根據http協議進行鏈接的所以不需要。

兩種方式均可。

第一種

[root@www bin]# ln -s /usr/local/mysql/lib/mysql/* /usr/lib64/

[root@www bin]# ln -s /usr/local/mysql/include/mysql/* /usr/include/

第二種

[root@www support-files]# vim /etc/ld.so.conf

include ld.so.conf.d/*.conf

/usr/local/mysql/lib/mysql/

/usr/local/mysql/include/mysql/

[root@www support-files]# ldconfig -v

進程名

監聽端口

傳輸協議

進程所有者

數據庫目錄

主配置文件

停止、啓動源碼mysql數據庫服務

連接數據庫服務器

安裝源碼PHP軟件包

--prefix=  指定安裝目錄

--enable-mbstring   支持多字節字符

--with-apxs2     指定httpd的模塊工具位置

--with-mysql   指定mysql 的安裝位置

--enable-sockets  啓用套接字支持

--with-config-file-path  指定配置路徑

[root@www php-5.4.19]# pwd

/usr/src/php-5.4.19

[root@www php-5.4.19]# ./configure --prefix=/usr/local/php --enable-mbstring --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs   --with-mysql=/usr/local/mysql   --with-config-file-path=/usr/local/php/etc

[root@www php-5.4.19]# make&&make install

[root@www modules]# pwd

/usr/local/apache/modules

[root@www modules]# ls

httpd.exp  libphp5.so

[root@www conf]# pwd

/usr/local/apache/conf

[root@www conf]# vim httpd.conf

DirectoryIndex index.php index.html

AddType application/x-httpd-php .php

[root@www conf]# service myhttpd stop

[root@www conf]# service myhttpd start

PHP配置文件。文件名必須爲php.ini

[root@www php-5.4.19]# pwd

/usr/src/php-5.4.19

[root@www php-5.4.19]# cp php.ini-production /usr/local/php/etc/php.ini

[root@www etc]# vim php.ini  給PHP程序員用

; Allow ASP-style <% %> tags.

; http://php.net/asp-tags

asp_tags = on

[root@www htdocs]# vim index.php

<%

        phpinfo();

%>

測試php能否連接mysql數據庫。

[root@www htdocs]# vim linkdb.php

<?php                        

        $linkdb=mysql_connect("192.168.1.1","root","");

        if($linkdb){

                echo "echo ok";

            }

        else{

                echo "echo no";

            }

?>

$linkdb=mysql_connect("192.168.1.1","root","");

$linkdb 定義變量

(mysql服務器IP地址或主機名,連接mysql的用戶名,用戶連接mysql的密碼)

PHP和apache必須裝一臺服務器上。但是也要安裝mysql源碼包。

mysql服務器可以分開。

[root@localhost ~]# yum install -y mysql-server mysql

[root@localhost ~]# /etc/init.d/mysqld restart

初始化 MySQL 數據庫: Installing MySQL system tables...

授權

mysql> grant all on *.* to bbsuser@"192.168.1.1" identified by "123456";

apache服務器

[root@www ~]# /usr/local/mysql/bin/mysql -h192.168.1.30 -ubbsuser -p123456

使用LAMP發佈論壇

[root@www Desktop]# unzip Discuz_X3.0_SC_UTF8.zip

[root@www Desktop]# ls

 readme    upload     utility

[root@www Desktop]# mv upload/ /usr/local/apache/htdocs/bbs

[root@www bbs]# pwd

/usr/local/apache/htdocs/bbs

[root@www bbs]# ls

admin.php    cp.php           home.php    portal.php  uc_client

api          crossdomain.xml  index.php   robots.txt  uc_server

api.php      data             install     search.php  userapp.php

archiver     favicon.ico      member.php  source

config       forum.php        misc.php    static

connect.php  group.php        plugin.php  template

[root@www bbs]# chown -R daemon config/ data/ uc_server/ uc_client/ template/

[root@svr5 bbs]# chown -R daemon  config/  data/  uc_server/

[root@svr5 bbs]# chown -R daemon  template/  uc_client/

安裝Discuz

http://server_ip/bbs

mysql> grant all on bbsdb.* to bbsuser@"%" identified by "123456";


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章