目前最爲成熟的一種企業網站應用模式,可提供動態Web站點應用及開發環境。php
Linux、Apache、 MySQL、 PHP/Per/Pythonhtml
成本低廉
可定製、易於開發
方便易用、安全和穩定mysql
(1)經過Samba服務,從個人宿主機將整個LAMP部署所需的壓縮包,掛載到「/mnt/」目錄下。c++
smbclient -L //192.168.100.50/ //查看共享的文件 mount.cifs //192.168.100.50/LAMP-C7 /mnt/ //掛載咱們所須要的文件
(2)將安裝Apache須要的用到的壓縮包解壓到「/opt/」目錄下。sql
[root@localhost mnt]# tar zxvf apr-1.6.2.tar.gz -C /opt/ //跨平臺所需組件包 ....... //省略過程 [root@localhost mnt]# tar zxvf apr-util-1.6.0.tar.gz -C /opt/ //跨平臺所需組件包 ....... //省略過程 [root@localhost mnt]# tar jxvf httpd-2.4.29.tar.bz2 -C /opt/ //服務包 ....... //省略過程
(3)將兩個組件包的目錄文件移動到httpd文件目錄下面,並分別重命名爲apr、apr-util數據庫
[root@localhost mnt]# cd ../opt/ [root@localhost opt]# ls apr-1.6.2 apr-util-1.6.0 httpd-2.4.29 rh [root@localhost opt]# mv apr-1.6.2/ httpd-2.4.29/srclib/apr [root@localhost opt]# ls apr-util-1.6.0 httpd-2.4.29 rh [root@localhost opt]# mv apr-util-1.6.0/ httpd-2.4.29/srclib/apr-util [root@localhost opt]# ls httpd-2.4.29 rh [root@localhost opt]#
(4)安裝編譯Apache服務以及服務所需的相關工具。apache
[root@localhost opt]# yum -y install \ > gcc \ > gcc-c++ \ > make \ > pcre-devel \ > expat-devel \ > perl ....... //省略過程
(5)進入到「/opt/httpd-2.4.29/」目錄下,進行對Apache服務器的配置。vim
[root@localhost opt]# ls httpd-2.4.29 rh [root@localhost opt]# cd httpd-2.4.29/ [root@localhost httpd-2.4.29]# ls ABOUT_APACHE BuildBin.dsp emacs-style LAYOUT NOTICE srclib acinclude.m4 buildconf httpd.dep libhttpd.dep NWGNUmakefile support Apache-apr2.dsw CHANGES httpd.dsp libhttpd.dsp os test Apache.dsw CMakeLists.txt httpd.mak libhttpd.mak README VERSIONING apache_probes.d config.layout httpd.spec LICENSE README.cmake ap.d configure include Makefile.in README.platforms build configure.in INSTALL Makefile.win ROADMAP BuildAll.dsp docs InstallBin.dsp modules server [root@localhost httpd-2.4.29]# ./configure \ > --prefix=/usr/local/httpd \ //安裝路徑 > --enable-so \ //啓用動態加載模塊支持 > --enable-rewrite \ //啓用網頁地址重寫功能 > --enable-charset-lite \ //啓用字符集支持 > --enable-cgi //啓用CGI腳本程序支持 ....... //省略過程
(6)編譯安裝Apache服務。api
[root@localhost httpd-2.4.29]# make && make install ....... //省略過程(編譯時間較長耐心等待) #make進行編譯,將源代碼轉換爲可執行程序。make install 進行安裝。
(7)將「/usr/local/httpd/bin/」目錄下的「apachectl」文件移動到「/etc/init.d/」目錄下,並在文件開頭添加chkconfig識別配置,而後將其添加爲標準的Linux系統服務。瀏覽器
[root@localhost httpd-2.4.29]#ls /usr/local/httpd/ bin build cgi-bin conf error htdocs icons include lib logs man manual modules [root@localhost httpd-2.4.29]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd [root@localhost httpd-2.4.29]# ls /etc/init.d/ functions httpd netconsole network README [root@localhost httpd-2.4.29]# #/usr/local/httpd/目錄下的,主要子目錄的用途: #/usr/local/httpd/bin //存放各類執行程序文件 #/usr/local/httpd/conf //存放各類配置文件 #/usr/local/httpd/htdocs //存放網頁文檔 #/usr/local/httpd/logs //存放日誌文件 #/usr/local/httpd/modules //存放各類模塊文件 #/usr/local/httpd/cgi-bin //存放各類CGI程序文件 [root@localhost httpd-2.4.29]# vim /etc/init.d/httpd #!/bin/sh # chkconfig: 35 85 21 //服務識別參數,在級別三、5中啓動:啓動和關閉的順序分別爲8五、21 # description: Apache is a World Wide Web server //服務描述信息 # # Licensed to the Apache Software Foundation (ASF) under one or more .......... //省略部份內容 [root@localhost httpd-2.4.29]# chkconfig --add httpd //將httpd服務添加爲系統服務 [root@localhost httpd-2.4.29]#
(8)編輯httpd服務的主配置文件,配置網站名稱,這裏覺得「www.yun.com:80」爲例。將監聽地址改成網站服務器的IP地址「192.168.52.132:80」,端口爲80,我這裏直接監聽當前主機的IP地址。將監聽ipv6IP地址的命令行註釋掉。
[root@localhost httpd-2.4.29]# vim /usr/local/httpd/conf/httpd.conf ServerName www.yun.com:80 //配置網站名稱 Listen 192.168.52.132:80 //配置IPv4監聽地址 #Listen 80
(9)優化配置文件與執行路徑,在系統默認的配置文件目錄「/etc/下」創建httpd服務配置文件的軟連接,同時在系統識別的環境變量目錄「/usr/local/bin/」下,創建httpd服務執行程序的軟連接。
[root@localhost httpd-2.4.29]# ln -s /usr/local/httpd/conf/httpd.conf /etc/ [root@localhost httpd-2.4.29]# ln -s /usr/local/httpd/bin/* /usr/local/bin/ [root@localhost httpd-2.4.29]#
(10)對服務的命令對配置內容進行語法檢查,用「httpd -t」或「apachectl -t」均可以,「Syntax OK」表示沒有語法錯誤,沒有錯誤咱們直接開啓服務,而後檢查可否監聽TCP的80端口。最後關閉防火牆和加強性安全功能。
[root@localhost httpd-2.4.29]# httpd -t Syntax OK [root@localhost httpd-2.4.29]# apachectl -t Syntax OK [root@localhost httpd-2.4.29]# service httpd start //開啓服務 [root@localhost httpd-2.4.29]# netstat -ntap | grep 80 //檢查可否監聽TCP的80端口 tcp 0 0 192.168.52.132:80 0.0.0.0:* LISTEN 34935/httpd [root@localhost httpd-2.4.29]# systemctl stop firewalld.service //關閉防火牆 [root@localhost httpd-2.4.29]# setenforce 0 //關閉加強性安全功能 [root@localhost httpd-2.4.29]#
(11)用咱們的宿主機去訪問搭建好的http服務。
(1)安裝編譯MySQL服務以及服務所需的相關工具。
[root@localhost httpd-2.4.29]# yum install -y ncurses-devel autoconf cmake ....... //省略過程
(2)將MySQL服務的源碼包解壓到「/opt/」目錄下。
[root@localhost mnt]#cd /mnt/ [root@localhost mnt]# tar zxvf mysql-5.6.26.tar.gz -C /opt/ ....... //省略過程
(3)進入「opt/mysql-5.6.26/」,對服務進行配置。
[root@localhost mnt]# cd /opt/mysql-5.6.26/ [root@localhost mysql-5.6.26]# ls BUILD config.h.cmake extra libmysqld packaging sql-bench unittest BUILD-CMAKE configure.cmake include libservices plugin sql-common VERSION client COPYING INSTALL-SOURCE man README storage vio cmake dbug INSTALL-WIN-SOURCE mysql-test regex strings win CMakeLists.txt Docs libevent mysys scripts support-files zlib cmd-line-utils Doxyfile-perfschema libmysql mysys_ssl sql tests [root@localhost mysql-5.6.26]# cmake \ > -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ //指定安裝路徑 > -DDEFAULT_CHARSET=utf8 \ //指定默認字符集 > -DDEFAULT_COLLATION=utf8_general_ci \ //指定默認字符集的校對規則 > -DEXTRA_CHARSETS=all \ //指定額外支持的其它字符集 > -DSYSCONFIDIR=/etc \ //指定初始化參數文件目錄 > -DMYSQL_DATADIR=/home/mysql/ \ //指定數據文件目錄 > -DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock //指定鏈接數據庫的文件 ....... //省略過程
(4)編譯安裝MySQL。
[root@localhost mysql-5.6.26]# make&&make install ....... //省略過程(編譯時間較長耐心等待) #make進行編譯,將源代碼轉換爲可執行程序。make install 進行安裝。
(5)創建配置文件,用咱們源碼包裏自帶的默認配置文件,去覆蓋系統默認的MySQL服務配置文件。
[root@localhost mysql-5.6.26]# cp support-files/my-default.cnf /etc/my.cnf cp:是否覆蓋"/etc/my.cnf"? yes [root@localhost mysql-5.6.26]#
(6)先將將腳本文件「mysql.server」從「support-files/」目錄下複製到「/etc/init.d/」目錄下,重命名爲「mysqld」,同時給腳本文件添加執行權限。而後將MySQL服務添加爲系統服務,並設置MySQL的環境變量。
[root@localhost mysql-5.6.26]# cp support-files/mysql.server /etc/init.d/mysqld //將腳本文件複製到/etc/init.d/目錄 [root@localhost mysql-5.6.26]# ls -l /etc/init.d/mysqld -rw-r--r--. 1 root root 10870 10月 18 17:28 /etc/init.d/mysqld [root@localhost mysql-5.6.26]# chmod +x /etc/init.d/mysqld //添加執行權限 [root@localhost mysql-5.6.26]# ls -l /etc/init.d/mysqld -rwxr-xr-x. 1 root root 10870 10月 18 17:28 /etc/init.d/mysqld [root@localhost mysql-5.6.26]# chkconfig --add /etc/init.d/mysqld //添加爲系統服務 [root@localhost mysql-5.6.26]# chkconfig mysqld --level 35 on [root@localhost mysql-5.6.26]# echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile //設置環境變量 [root@localhost mysql-5.6.26]# source /etc/profile //從新執行一下,刷新配置 [root@localhost mysql-5.6.26]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin [root@localhost mysql-5.6.26]#
(7)建立一個mysql用戶,設爲禁止登錄。而後將「/usr/local/mysql/」目錄下的全部文件目錄的屬主、屬組改成mysql。
[root@localhost mysql-5.6.26]# useradd -s /sbin/nologin mysql //添加用戶 [root@localhost mysql-5.6.26]# chown -R mysql:mysql /usr/local/mysql/ //更改屬主、屬組,-R表示遞歸 [root@localhost mysql-5.6.26]# ls -l /usr/local/mysql/ 總用量 152 drwxr-xr-x. 2 mysql mysql 4096 10月 18 17:27 bin -rw-r--r--. 1 mysql mysql 17987 7月 15 2015 COPYING drwxr-xr-x. 3 mysql mysql 18 10月 18 17:27 data drwxr-xr-x. 2 mysql mysql 55 10月 18 17:27 docs drwxr-xr-x. 3 mysql mysql 4096 10月 18 17:27 include -rw-r--r--. 1 mysql mysql 104897 7月 15 2015 INSTALL-BINARY drwxr-xr-x. 3 mysql mysql 4096 10月 18 17:27 lib drwxr-xr-x. 4 mysql mysql 30 10月 18 17:27 man drwxr-xr-x. 10 mysql mysql 4096 10月 18 17:27 mysql-test -rw-r--r--. 1 mysql mysql 2496 7月 15 2015 README drwxr-xr-x. 2 mysql mysql 30 10月 18 17:27 scripts drwxr-xr-x. 28 mysql mysql 4096 10月 18 17:27 share drwxr-xr-x. 4 mysql mysql 4096 10月 18 17:27 sql-bench drwxr-xr-x. 2 mysql mysql 136 10月 18 17:27 support-files [root@localhost mysql-5.6.26]#
(8)初始化數據庫。
[root@localhost mysql-5.6.26]# /usr/local/mysql/scripts/mysql_install_db \ > --user=mysql \ //管理用戶 > --ldata=/var/lib/mysql \ //數據目錄 > --basedir=/usr/local/mysql \ //工做目錄 > --datadir=/home/mysql //數據目錄 ....... //省略過程
(9)爲鏈接數據庫的文件「mysql.sock」在目錄「/home/mysql/」下創建一個軟連接,方便使用。
[root@localhost mysql-5.6.26]# ln -s /var/lib/mysql/mysql.sock /home/mysql/mysql.sock [root@localhost mysql-5.6.26]#
(10)對配置文件進行修改,添加咱們的工做目錄與數據存放目錄。
[root@localhost mysql-5.6.26]# vim /etc/init.d/mysqld basedir=/usr/local/mysql datadir=/home/mysql
(11)開啓mysql服務,同時檢查是否監聽到TCP協議端口3306。
[root@localhost mysql-5.6.26]# service mysqld start //啓動服務 Starting MySQL. SUCCESS! [root@localhost mysql-5.6.26]# netstat -anpt | grep 3306 tcp6 0 0 :::3306 :::* LISTEN 53852/mysqld [root@localhost mysql-5.6.26]#
(12)修改mysql數據庫的管理員密碼。
[root@localhost mysql-5.6.26]# mysqladmin -u root -p password "abc123" Enter password: //這裏輸入原始密碼,原始密碼爲空,直接回車便可 Warning: Using a password on the command line interface can be insecure. [root@localhost mysql-5.6.26]#
(13)嘗試進入mysql數據庫,檢查數據庫是否搭建成功。
[root@localhost mysql-5.6.26]# mysql -u root -p //登陸 Enter password: //輸入上一步設置的密碼 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.6.26 Source distribution Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; //查看數據庫 +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec) mysql> quit //退出 Bye [root@localhost mysql-5.6.26]#
(1)安裝編譯PHP服務以及服務所需的相關工具。
[root@localhost mysql-5.6.26]# yum -y install \ > gd \ > libpng \ > libpng-devel \ > pcre \ > pcre-devel \ > libxml2-devel \ > libjpeg-devel ....... //省略過程
(2)將PHP服務的源碼包解壓到「/opt/」目錄下。
[root@localhost mysql-5.6.26]#cd /mnt/ [root@localhost mnt]# ls apr-1.6.2.tar.gz Discuz_X2.5_SC_UTF8.zip LAMP-php5.6.txt php-5.6.11.tar.bz2 apr-util-1.6.0.tar.gz httpd-2.4.29.tar.bz2 mysql-5.6.26.tar.gz [root@localhost mnt]# tar jxvf php-5.6.11.tar.bz2 -C /opt/ ....... //省略過程
(3)進入「/opt/php-5.6.11/」目錄下,對PHP服務進行配置。
[root@localhost mnt]# cd /opt/php-5.6.11/ [root@localhost php-5.6.11]# ./configure \ > --prefix=/usr/local/php5 \ //指定安裝路徑 > --with-gd \ //圖片處理庫 > --with-zlib \ //壓縮函數庫 > --with-apxs2=/usr/local/httpd/bin/apxs \ //設置Apache HTTP Server提供的apxs模塊支持程序的文件位置 > --with-mysql=/usr/local/mysql \ //設置MySQL數據庫服務程序安裝位置 > --with-config-file-path=/usr/local/php5 \ //設置PHP的配置文件php.ini將要存放的位置 > --enable-mbstring //啓用多字節字符串功能 ....... //省略過程
(4)編譯安裝PHP
[root@localhost php-5.6.11]# make&& make install ....... //省略過程(編譯時間較長耐心等待) #make進行編譯,將源代碼轉換爲可執行程序。make install 進行安裝。
(5)將源碼包裏的配置文件複製到「/usr/local/php5/」目錄下,並重命名爲「php.ini」,而後同時在系統識別的環境變量目錄「/usr/local/bin/」下,創建PHP服務執行程序的軟連接。
[root@localhost php-5.6.11]# cp php.ini-development /usr/local/php5/php.ini [root@localhost php-5.6.11]# ln -s /usr/local/php5/bin/* /usr/local/bin/ [root@localhost php-5.6.11]#
(6)對httpd服務的配置文件「httpd.conf」進行修改,使httpd服務器支持PHP頁面解析功能。
[root@localhost php-5.6.11]# vim /etc/httpd.conf <IfModule dir_module> DirectoryIndex index.html index.php //添加默認首頁識別php格式文件類型 </IfModule> AddType application/x-httpd-php .php //添加對「.php」類型網頁文件的支持 AddType application/x-httpd-php-source .phps
(7)從新啓動httpd服務,不建議用「restart」,由於「restart」有些進程不會結束。
[root@localhost php-5.6.11]# service httpd stop [root@localhost php-5.6.11]# service httpd start [root@localhost php-5.6.11]#
(8)修改首頁文件內容,並將首頁文件「index.html」重命名爲「index.php」。
[root@localhost php-5.6.11]# cd /usr/local/httpd/htdocs/ [root@localhost htdocs]# ls index.html [root@localhost htdocs]# vim index.html <?php phpinfo(); ?> [root@localhost htdocs]# mv index.html index.php [root@localhost htdocs]# ls index.php [root@localhost htdocs]#
(9)此時再用咱們的宿主機去訪問http服務,結果以下。
(1)進入MySQL,爲論壇建立一個名爲「bbs」的數據庫,
[root@localhost htdocs]# cd /mnt/ [root@localhost mnt]# ls apr-1.6.2.tar.gz Discuz_X2.5_SC_UTF8.zip LAMP-php5.6.txt php-5.6.11.tar.bz2 apr-util-1.6.0.tar.gz httpd-2.4.29.tar.bz2 mysql-5.6.26.tar.gz [root@localhost mnt]# mysql -u root -p //登陸 Enter password: //輸入密碼 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.6.26 Source distribution Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> create database bbs; //建立數據庫 Query OK, 1 row affected (0.03 sec) mysql> grant all on bbs.* to 'bbsuser'@'%' identified by 'admin123'; //給bbs數據庫中的全部表格提高權限,同時建立管理數據庫的用戶"bbsuser",設置密碼。"%"表示能夠從全部終端訪問 Query OK, 0 rows affected (0.01 sec) mysql> flush privileges; //刷新數據庫 Query OK, 0 rows affected (0.01 sec) mysql> quit //退出 Bye [root@localhost mnt]#
(2)將Discuz壓縮包,解壓到「/opt/」目錄下,命名爲「dis」。
[root@localhost mnt]# ls apr-1.6.2.tar.gz Discuz_X2.5_SC_UTF8.zip LAMP-php5.6.txt php-5.6.11.tar.bz2 apr-util-1.6.0.tar.gz httpd-2.4.29.tar.bz2 mysql-5.6.26.tar.gz [root@localhost mnt]# unzip Discuz_X2.5_SC_UTF8.zip -d /opt/dis
(3)用「cp -r」命令把「upload/」目錄遞歸複製到,httpd服務存放網頁文檔的目錄「/usr/local/httpd/htdocs/」下面,命名爲bbs。
[root@localhost mnt]# cd /opt/ [root@localhost opt]# ls dis httpd-2.4.29 mysql-5.6.26 php-5.6.11 rh [root@localhost opt]# cd dis/ [root@localhost dis]# ls readme upload utility [root@localhost dis]# cp -r upload/ /usr/local/httpd/htdocs/bbs [root@localhost bbs]#
(4)分別將下列文件或目錄的屬主改成「daemon」。
[root@localhost dis]# cd /usr/local/httpd/htdocs/bbs/ [root@localhost bbs]# ls admin.php config data home.php misc.php search.php uc_client api connect.php favicon.ico index.php plugin.php source uc_server api.php cp.php forum.php install portal.php static userapp.php archiver crossdomain.xml group.php member.php robots.txt template [root@localhost bbs]# chown -R daemon ./config //更改屬主 [root@localhost bbs]# chown -R daemon ./data //更改屬主 [root@localhost bbs]# chown -R daemon ./uc_client //更改屬主 [root@localhost bbs]# chown -R daemon ./uc_server/data //更改屬主 [root@localhost bbs]#
(5)在咱們的宿主機瀏覽器輸入http://192.168.52.132/bbs,進入論壇安裝界面點擊我贊成。
(6)點擊下一步。
(7)選擇全新安裝,點擊下一步。
(8)按照下圖輸入數據庫相關信息,而後點擊下一步,安裝數據庫。
安裝完畢以下圖:
(9)從新輸入http://192.168.52.132/bbs,成功進入論壇。