


Install and configure the LAMP platform using yum method under Linux 6
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>
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>
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>
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>
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.
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.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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

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

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

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

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

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 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...

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
