Home > Backend Development > PHP Tutorial > Install and configure the LAMP platform using yum method under Linux 6

Install and configure the LAMP platform using yum method under Linux 6

WBOY
Release: 2016-07-28 08:26:28
Original
999 people have browsed it

LAMP built under Linux is a classic website construction platform for small and medium-sized enterprises that cannot be more classic. Its full name is Linux+Apache+Mysql+PHP. It is often used to build dynamic websites. They are independent programs. However, because they are often used together, they have higher and higher compatibility, and together they form a powerful Web application platform. Therefore, there is also the famous LAMP one-click installation solution on the Internet. But for operation and maintenance personnel, it is necessary to understand the completed installation process. This article mainly describes the use of yum method to quickly build the LAMP platform based on CentOS 6 (Linux installation is ignored).

1. Prepare yum source (163 mirror is used in this article)

<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>
Copy after login

2. Install apache httpd

For details, please refer to: Installing Apache httpd under Linux

<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>
Copy after login

3. Install php

<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>
Copy after login

4. Install mysql

<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>
Copy after login

5. Summary

1. The connection between apache httpd and php is achieved through modularization.
2. For perfork mode, use the libphp5 module, and for worker and event modes, use the libphp5-zts module.
3. For php and mysql, access from php to mysql is achieved by installing the php-mysql package.

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the installation and configuration of the LAMP platform using yum method under Linux 6, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template