linux學習筆記-第十八課-LAMP之環境搭建(一)

來源:互聯網
上載者:User

標籤:linux   mysql      運行環境   

一、LAMP搭建前的準備

    LAMP是四套軟體的縮寫,分別指的是L-Linux,A-Apache,M-Mysql,P-php,利用這四套軟體搭建的web的運行環境。

    搭建前需要需要下載好軟體

    apache http://syslab.comsenz.com/downloads/linux/httpd-2.2.16.tar.gz

    mysql  32位 :http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz

           64位 :http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-x86_64-icc-glibc23.tar.gz

    php    http://cn2.php.net/distributions/php-5.3.28.tar.gz

    軟體鏡像http://mirrors.sohu.com/

    安裝擴充庫地址

    yum install -y epel-release

    安裝庫檔案

    yum -y install ntp make openssl openssl-devel pcre pcre-devel libpng libpng-devel libtiff-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel fontconfig-devel zlib zlib-devel libevent-devel gcc gcc-c++ flex bison bzip2-devel libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel libmcrypt-devel

    關閉selinux

二、Apache 

    1 )編譯

# 解壓軟體包[[email protected] src]# tar -zxvf httpd-2.2.16# 進入軟體目錄[[email protected] src]# cd httpd-2.2.16# 執行編譯參數[[email protected] httpd-2.2.16]# ./configure --prefix=/usr/local/apache2 --enable-so --enable-mods-shared=most# 開始編譯[[email protected] httpd-2.2.16]# make# 安裝軟體[[email protected] httpd-2.2.16]# make install

    2 )修改配置

[[email protected] ~]# vim /usr/local/apache2/conf/httpd.conf..................上面省略.....................# at a local disk.  If you wish to share the same ServerRoot for multiple# httpd daemons, you will need to change at least LockFile and PidFile.#ServerRoot "/usr/local/apache2"       # apache 程式目錄...................中間省略....................##Listen 12.34.56.78:80Listen 80           # 監聽連接埠## Dynamic Shared Object (DSO) Support...................中間省略....................# as error documents.  e.g. [email protected]#ServerAdmin [email protected]           # 管理員郵箱地址...................中間省略....................# If your host doesn‘t have a registered DNS name, enter its IP address here.#ServerName localhost:80         # 預設ServerName www.example.com:80                                # 這裡需要修改,預設是用注釋符“#”注釋掉的#...................中間省略....................# symbolic links and aliases may be used to point to other locations.#DocumentRoot "/usr/local/apache2/htdocs/"        # 網站檔案儲存體的位置,檔案監聽目錄                                ## Each directory to which Apache has access can be configured with respect...................中間省略....................# features.#<Directory />    Options FollowSymLinks    AllowOverride None    Order deny,allow    Allow from all     # 預設為Deny from all,拒絕訪問,修改為Allow from all,允許訪問</Directory>## Note that from this point forward you must specifically allow

     3 )啟動apache

# 修改配置 ,檢測是否OK[[email protected] ~]# /usr/local/apache2/bin/apachectl -tSyntax OK[[email protected] ~]# /usr/local/apache2/bin/apachectl start

     4 )檢測httpd服務是否有啟動,網路連接埠是否開啟,關閉防火牆,或者對80連接埠允許存取,外網就可以訪問了

 # 進程檢測[[email protected] ~]# ps aux|grep httpdroot     25675  0.0  0.2   5280  2148 ?        Ss   12:30   0:00 /usr/local/apache2/bin/httpd -k startdaemon   25676  0.0  0.1   5280  1548 ?        S    12:30   0:00 /usr/local/apache2/bin/httpd -k startdaemon   25677  0.0  0.1   5280  1548 ?        S    12:30   0:00 /usr/local/apache2/bin/httpd -k startdaemon   25678  0.0  0.1   5280  1548 ?        S    12:30   0:00 /usr/local/apache2/bin/httpd -k startdaemon   25679  0.0  0.1   5280  1548 ?        S    12:30   0:00 /usr/local/apache2/bin/httpd -k startdaemon   25680  0.0  0.1   5280  1548 ?        S    12:30   0:00 /usr/local/apache2/bin/httpd -k startroot     25686  0.0  0.0   4356   740 pts/4    S+   12:34   0:00 grep httpd[[email protected] ~]## 連接埠檢測[[email protected] ~]# netstat -nlp |grep httpdtcp        0      0 :::80                       :::*                        LISTEN      25675/httpd       # 網站狀態訪問檢測[[email protected] ~]# curl -I localhostHTTP/1.1 200 OKDate: Tue, 28 Apr 2015 04:45:54 GMTServer: Apache/2.2.16 (Unix) DAV/2Last-Modified: Sat, 20 Nov 2004 20:16:24 GMTETag: "12a8-2c-3e9564c23b600"Accept-Ranges: bytesContent-Length: 44Content-Type: text/html

     在瀏覽器中輸入IP地址,如果顯示

   It works!

     代表成功啟動了!



三、mysql

# 解壓mysql[[email protected] src]# tar -zxvf mysql-5.1.40-linux-i686-icc-glibc23.tar.gz# 檔案程式移動到指定的安裝路徑[[email protected] src]# mv mysql-5.1.40-linux-i686-icc-glibc23 /usr/local/mysql# 建立mysql使用者,shell狀態為/sbin/nologin[[email protected] mysql]# useradd -s /sbin/nologin mysql# 進入/usr/local/mysql,初始化mysql庫,當有2個OK,代表初始化成功# 這裡要注意,需要修改/etc/hosts,將主機名稱字,添加到檔案了[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysqlInstalling MySQL system tables...OKFilling help tables...OK..................下面省略....................# 拷貝啟動指令碼,更改許可權[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld[[email protected] mysql]# chmod 755 /etc/init.d/mysqld# 修改啟動指令碼[[email protected] mysql]# vim /etc/init.d/mysqld........................上面省略...................basedir=        <== mysql程式路徑datadir=        <== mysql資料路徑.........................下面省略...................# 拷貝mysql設定檔,這裡需要注意一下,自己的實體記憶體有多大[[email protected] mysql]# cp support-files/my-my-huge.cnf             my-large.cnf            my-small.cnfmy-innodb-heavy-4G.cnf  my-medium.cnf[[email protected] mysql]# cp support-files/my-large.cnf /etc/my.cnfcp: overwrite `/etc/my.cnf‘? y# 將mysqld加到服務列表裡,並啟動[[email protected] mysql]# chkconfig --add mysqld[[email protected] mysql]# chkconfig mysqld on[[email protected] mysql]# service mysqld startStarting MySQL... SUCCESS!

然後進行進程檢測,連接埠檢測



四、php

# 解包軟體[[email protected] php-5.3.28]# tar -zxvf php-5.3.28.tar.gz# 進入php檔案目錄,編輯參數[[email protected] php-5.3.28]# ./configure --prefix=/usr/local/php > --with-apxs2=/usr/local/apache2/bin/apxs > --with-config-file-path=/usr/local/php/etc > --with-mysql=/usr/local/mysql > --with-libxml-dir > --with-gd > --with-jpeg-dir > --with-png-dir > --with-freetype-dir > --with-iconv-dir > --with-zlib-dir > --with-bz2 > --with-openssl > --with-mcrypt > --enable-soap > --enable-gd-native-ttf > --enable-mbstring > --enable-sockets > --enable-exif > --disable-ipv6# 執行編譯[[email protected] php-5.3.28]# make# 安裝檔案[ro[email protected] php-5.3.28]# make install



五、php與apache的組合

    修改apache的設定檔 

[[email protected] ~]# vim /usr/local/apache2/conf/httpd.conf.........................上面省略...........................# is requested.#<IfModule dir_module>    DirectoryIndex index.html index.htm index.php  <== 預設沒有index.htm和index.php,需要加上</IfModule>## The following lines prevent .htaccess and .htpasswd files from being.........................中間省略..............................    # If the AddEncoding directives above are commented-out, then you    # probably should define those extensions to indicate media types:    #    AddType application/x-compress .Z    AddType application/x-gzip .gz .tgz    AddType application/x-httpd-php .php <== 需要在這裡加上這一行,增加對php的解析    #    # AddHandler allows you to map certain file extensions to "handlers":    # actions unrelated to filetype. These can be either built into the server.........................下面省略................................

     還要檢查是否載入了php模組

     LoadModule php5_module        modules/libphp5.so

     修改完配置需要重啟apache服務(重啟前需要進行檢測)

# 編寫php解析測試檔案[[email protected] ~]# vim /usr/local/apache2/htdocs/test.php<?phpphpinfo();?>[[email protected] ~]# curl -I localhost/test.phpHTTP/1.1 200 OKDate: Tue, 28 Apr 2015 23:03:35 GMTServer: Apache/2.2.16 (Unix) DAV/2 PHP/5.3.28X-Powered-By: PHP/5.3.28Content-Type: text/html

      在瀏覽器裡輸入IP地址,顯示如下介面,代表解析php成功

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/6C/17/wKioL1U_o6TQSPQ2AAOXnETv-XA134.jpg" title="QQ20150428230714.jpg" alt="wKioL1U_o6TQSPQ2AAOXnETv-XA134.jpg" />


        到此,LAMP的環境搭建完畢





本文出自 “MyLinux” 部落格,請務必保留此出處http://mylinuxlife.blog.51cto.com/4706737/1640056

linux學習筆記-第十八課-LAMP之環境搭建(一)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.