首頁 > 後端開發 > php教程 > Linux 6 下yum方式安裝設定LAMP平台

Linux 6 下yum方式安裝設定LAMP平台

WBOY
發布: 2016-07-28 08:26:28
原創
994 人瀏覽過

Linux下搭建LAMP是經典的不能再經典的中小企業站點建構平台。它的全名是Linux+Apache+Mysql+PHP,常用來搭建動態網站,本身都是各自獨立的程序,但是因為常被放在一起使用,擁有了越來越高的兼容度,共同組成了一個強大的Web應用程式平台。因此在網路上也有比叫有名的LAMP一鍵安裝解決方案。但是對於維運人員來講,有必要了解其完成的安裝過程。本文主要描述基於CentOS 6 下使用yum方式來快速建構LAMP平台(Linux安裝忽略)。

一、準備yum源(本文使用了163鏡像)

<code><span># mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup</span><span># wget http://mirrors.163.com/.help/CentOS6-Base-163.repo -P /etc/yum.repos.d/</span><span># yum clean all</span><span># yum makecache</span></code>
登入後複製

二、安裝apache httpd

詳細可以參考:Linux下安裝Apache httpd

<code><span>###检查是否已安装httpd</span><span># rpm -qa|grep httpd</span><span>        httpd-tools-2.2.15-45.el6.centos.x86_64</span><span>        httpd-2.2.15-45.el6.centos.x86_64</span><span># yum -y install httpd   ###此时我们看到httpd的小版本从45变成了53</span><span># rpm -qa|grep httpd</span><span>        httpd-tools-2.2.15-53.el6.centos.x86_64</span><span>        httpd-2.2.15-53.el6.centos.x86_64</span><span>###查询生成的相关配置文件</span><span># rpm -qc httpd|grep conf</span><span>        /etc/httpd/conf.d/welcome.conf</span><span>        /etc/httpd/conf/httpd.conf</span><span>        /etc/httpd/conf/magic</span><span>        /etc/sysconfig/htcacheclean</span><span>        /etc/sysconfig/httpd</span><span>###启动httpd</span><span># /etc/init.d/httpd start</span><span>        Starting httpd:                                            [  OK  ]</span><span># netstat -nltp|grep 80</span><span>        tcp        0      0 :::80          :::*      LISTEN      7621/httpd</span><span>###验证web服务</span><span># curl -I http://localhost</span><span>        HTTP/1.1 403 Forbidden</span><span>        Date: Tue, 12 Jul 2016 09:25:15 GMT</span><span>        Server: Apache/2.2.15 (CentOS)</span><span>        Accept-Ranges: bytes</span><span>        Content-Length: 4961</span><span>        Connection: close</span><span>        Content-Type: text/html; charset=UTF-8</span><span>###编写一个php页面测试</span><span># echo "</span><span>> <html></span><span>> <h1>This is a php test page.</h1></span><span>> <?php</span><span>> phpinfo();</span><span>> ?></span><span>> </html>">>/var/www/html/index.php  </span><span>###测试结果为phpinfo函数没有被解释</span><span># curl http://localhost/index.php</span><span>        <html></span><span>        <h1>This is a php test page.</h1></span><span>        <?php</span><span>        phpinfo();</span><span>        ?></span><span>        </html></span></code>
登入後複製
詳細可以參考:Linux下安裝Apache httpd

<code><span>###安装php,同时会安装依赖包</span><span># yum install php</span>
        Installing:
         php                      x86_64     <span>5.3</span><span>.3</span>-<span>47.</span>el6      base     <span>1.1</span> M
        Installing <span>for</span> dependencies:
         php-cli                  x86_64     <span>5.3</span><span>.3</span>-<span>47.</span>el6      base     <span>2.2</span> M
         php-common               x86_64     <span>5.3</span><span>.3</span>-<span>47.</span>el6      base     <span>530</span> k

<span>###查看php安装清单 </span><span># rpm -ql php</span>
        /etc/httpd/conf.d/php.conf
        /usr/lib64/httpd/modules/libphp5.so
        /<span>var</span>/lib/php/session
        /<span>var</span>/www/icons/php.gif 

<span>###查看php的配置文件 </span><span># grep -vE "^#|^$" /etc/httpd/conf.d/php.conf </span>
        <IfModule prefork.c>
          LoadModule php5_module modules/libphp5.so
        </IfModule>
        <IfModule worker.c>
          LoadModule php5_module modules/libphp5-zts.so
        </IfModule>
        AddHandler php5-script .php
        AddType text/html .php
        DirectoryIndex index.php

<span>###在上面的配置文件中,由于php以模块化方式与httpd结合工作,根据httpd的mpm模式不同,</span><span>###其所需要的php模块格式有所不同;    prefork模式使用libphp5模块    worker和event模式则使用libphp5-zts模块</span><span>###重启httpd已使得php模块生效</span><span># /etc/init.d/httpd configtest</span>
        Syntax OK

<span># /etc/init.d/httpd restart</span>
        Stopping httpd:                 [ <span> OK </span> ]
        Starting httpd:                 [ <span> OK </span> ]

<span>###验证php模块已经被加载</span><span># httpd -M |grep php</span>
        php5_module (shared)

<span>###验证php页面 </span><span># curl http://localhost/index.php|more</span>
        <html>
        <h1>This is a php test page.</h1>
        <!DOCTYPE html<span> PUBLIC </span><span>"-//W3C//DTD XHTML 1.0 Transitional//EN"</span><span>"DTD/xhtml1-transitional.dtd"</span>>
        <html><head>
        <style type=<span>"text/css"</span>>
        body {background-color: #ffffff; color: #<span>000000</span>;}
              ...........

<span>###切换为使用worker工作模式</span><span># cp /etc/sysconfig/httpd /etc/sysconfig/httpd.bk</span><span># sed -i "s@#HTTPD=/usr/sbin/httpd.worker@HTTPD=/usr/sbin/httpd.worker@g" /etc/sysconfig/httpd</span><span># grep -vE "^#|^$" /etc/sysconfig/httpd</span>
        HTTPD=/usr/sbin/httpd.worker

<span>###从下面的提示中,我们需要使用php5zts模块</span><span># /etc/init.d/httpd restart</span>
        Stopping httpd:                                            [ <span> OK </span> ]
        Starting httpd: httpd.worker: Syntax error on line <span>221</span> of /etc/httpd/conf/httpd.conf: 
        Syntax error on line <span>9</span> of /etc/httpd/conf.d/php.conf: Cannot load /etc/httpd/modules/libphp5-zts.so 
        into server: /etc/httpd/modules/libphp5-zts.so: cannot open shared object file: No such file or directory
                                                                   [FAILED]
<span>###安装php-zts模块</span><span># yum -y install php-zts</span><span># rpm -ql php-zts</span>
        /usr/lib64/httpd/modules/libphp5-zts.so

<span># ps -ef|grep http   ###查看httpd,已经切换为使用worker模式</span>
        root      <span>10339</span><span>1</span><span>0</span><span>04</span>:<span>35</span> ?        <span>00</span>:<span>00</span>:<span>00</span> /usr/sbin/httpd.worker
        apache    <span>10341</span><span>10339</span><span>0</span><span>04</span>:<span>35</span> ?        <span>00</span>:<span>00</span>:<span>00</span> /usr/sbin/httpd.worker
        apache    <span>10342</span><span>10339</span><span>0</span><span>04</span>:<span>35</span> ?        <span>00</span>:<span>00</span>:<span>00</span> /usr/sbin/httpd.worker
        apache    <span>10343</span><span>10339</span><span>0</span><span>04</span>:<span>35</span> ?        <span>00</span>:<span>00</span>:<span>00</span> /usr/sbin/httpd.worker
        apache    <span>10344</span><span>10339</span><span>0</span><span>04</span>:<span>35</span> ?        <span>00</span>:<span>00</span>:<span>00</span> /usr/sbin/httpd.worker</code>
登入後複製
三、安裝php

<code><span># rpm -qa|grep mysql</span>
        mysql-libs-<span>5.1</span><span>.73</span>-<span>5.</span>el6_6.x86_64

<span># yum install mysql-server  </span><span># rpm -qa|grep mysql      </span>
        mysql-<span>5.1</span><span>.73</span>-<span>7.</span>el6.x86_64
        mysql-libs-<span>5.1</span><span>.73</span>-<span>7.</span>el6.x86_64
        mysql-server-<span>5.1</span><span>.73</span>-<span>7.</span>el6.x86_64

<span>###查看mysql安装产生的文件</span><span># rpm -ql mysql-server</span><span># rpm -ql mysql</span><span># more /etc/my.cnf</span>
        [mysqld]
        datadir=/<span>var</span>/lib/mysql
        socket=/<span>var</span>/lib/mysql/mysql.sock
        user=mysql
        # Disabling symbolic-links is recommended to prevent assorted security risks
        symbolic-links=<span>0</span>        [mysqld_safe]
        log-error=/<span>var</span>/log/mysqld.log
        pid-file=/<span>var</span>/run/mysqld/mysqld.pid

<span># /etc/init.d/mysqld start</span><span># /usr/bin/mysqladmin -u root password '***'</span><span># mysql -uroot -p</span>
mysql> show variables like <span>'port'</span>;
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | <span>3306</span>  |
+---------------+-------+

<span>###安装php连接mysql驱动</span><span>#   yum install php-mysql</span><span>###查看安装完毕后生产的文件</span><span># rpm -ql php-mysql</span>
        /etc/php.d/mysql.ini      ### Author : Leshami
        /etc/php.d/mysqli.ini     ### Blog   : http:<span>//blog.csdn.net/leshami</span>
        /etc/php.d/pdo_mysql.ini
        /usr/lib64/php/modules/mysql.so
        /usr/lib64/php/modules/mysqli.so
        /usr/lib64/php/modules/pdo_mysql.so

<span>###测试到mysql的连接</span><span>#vim  /var/www/html/connmysql.php</span>
<?php
    $conn = mysql_connect(<span>'127.0.0.1'</span>,<span>'root'</span>,<span>'***'</span>);
    if ($conn)
        echo <span>"succ"</span>;
    <span>else</span>
        echo <span>"failure"</span>;
    mysql_close();
?>

<span># curl http://localhost/connmysql.php</span>
        succ</code>
登入後複製
四、安裝mysql

五、小結

1、apache httpd與php之間的銜接是透過模組化的方式來實現。

2.對於perfork模式使用libphp5模組,worker和event模式則使用libphp5-zts模組。 3.php與mysql則透過安裝php-mysql套件來實現php到mysql的存取。 ').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i

').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介紹了 Linux 6 下yum方式安裝配置LAMP平台,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。

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