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

Jul 28, 2016 am 08:26 AM
etc httpd mysql php worker

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.

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the &quot;MySQL Native Password&quot; plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

The page is blank after PHP is connected to MySQL. What is the reason for the invalid die() function? The page is blank after PHP is connected to MySQL. What is the reason for the invalid die() function? Apr 01, 2025 pm 03:03 PM

The page is blank after PHP connects to MySQL, and the reason why die() function fails. When learning the connection between PHP and MySQL database, you often encounter some confusing things...

Top 10 PHP CMS Platforms For Developers in 2024 Top 10 PHP CMS Platforms For Developers in 2024 Dec 05, 2024 am 10:29 AM

CMS stands for Content Management System. It is a software application or platform that enables users to create, manage, and modify digital content without requiring advanced technical knowledge. CMS allows users to easily create and organize content

See all articles