Home php教程 php手册 Linux下LAMP(Apache+PHP+MySql)环境配置

Linux下LAMP(Apache+PHP+MySql)环境配置

Jun 14, 2016 am 12:02 AM
apache lamp linux mysql php code Open source Environment configuration programming programming language software development

今天我来介绍一下LinuxLAMPApache+PHP+MySql)的环境配置,我将把Apache+MySql+PHP分别安装在redhat下的opt目录下的httpdmysqlphp目录中,以达到可以通过浏览器访问phpinfo以及phpmyadmin页面的最终目的。

 

名词解释:

LAMPLinux+Apache+MySql+PHP的缩写,它指一组常用来搭建动态网站或者服务器的开源软件:

* Linux,操作系统;
* Apache,网页服务器;
* MySQL,数据库管理系统(或者数据库服务器);
* PHP 和有時 Perl 或 Python,脚本语言。

以下为LAMP的在wikipedia中的解释:http://en.wikipedia.org/wiki/LAMP_%28software_bundle%29

 

环境准备:

*RedHat操作系统(需要安装GCCG++-> rhel-server-5.3-x86_64 

* MySQL源码包 -> mysql-5.1.57.tar.gz

* Apache源码包 -> httpd-2.2.21.tar.gz 

* PHP源码包 -> php-5.2.17.tar.gz

* phpMyAdmin源码包 à phpMyAdmin-3.4.7.1-english.tar.gz

以上为我做实验的环境版本,大家可以根据自己的需要,到官网下载自己所需,不过不同版本可能会遇到不同问题,可能需要大家自己去搜索解决方案。

 

安装:

本次安装使用的都是源码编译安装,首先请将全部源码包复制到/usr/local/src下。安装之前,如果安装过其他版本的LinuxMysqlApachePHP,要先卸载。使用rpm包安装的用删除rpm包语句:[rpm -e 包名],查询包名用语句:[rpm -qa | grep 包名]。有依赖关系的包也要一次删除,这样才能成功的删除这些rpm包。

 

1. 安装及配置MySQL

步骤一:编译安装

#cd /usr/local/src  

#tar -zxvf mysql-5.1.57.tar.gz  

#cd mysql-5.1.57

#groupadd -r mysql //创建mysql用户组  

#useradd -m -r -g mysql -d /var/lib/mysql -s /bin/bash   

>-c "MySQL Server" mysql  //加入用户

#./configure --prefix=/opt/mysql  //指定mysql安装目录  

>--sysconfdir=/etc    //指定mysql配置文件存放目录  

>--localstatedir=/var/lib/mysql //指定mysql数据库存放目录  

>--enable-local-infile   //激活load data local infile语句,使mysql支持使用该语句  //等待,no news is good news

#make   //编译(需较长时间),直到出现Making install in win 

#make install   //安装,直到出现Making install in win

#make clean  

#make distclean 

 

步骤二:初始化数据库

#cd /opt/mysql  

#/bin/mysql_install_db//初始化系统数据库  

#ls /var/lib/mysql //查看存放数据库中的目录内容 

#chown -R mysql:mysql /var/lib/mysql //修改数据库所有者

 

步骤三:复制Linux Mysql配置文件到/etc目录中,并更名为my.cnf

#cp /opt/mysql/share/mysql/my-large.cnf /etc/my.cnf

 

步骤四:复制生成Linux Mysql服务器的自动与停止脚本

#cp /opt/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysql

 

步骤五:将Linux Mysql服务添加到服务器管理中,并设置自启动状态:

#chkconfig --list | grep mysql //查询当前是否有mysql服务  

#chkconfig --add mysql //添加mysql服务到服务器管理中  

#chkconfig --list | grep mysql //查询此时mysql服务器的启动状态  

#chkconfig --level 35 mysql on //设置在35运行级别也自启动 

 

步骤六:启动并测试Linux Mysql服务器

#service mysql start  /etc/rc.d/init.d/mysql start //启动MySQL服务器

#/opt/mysql/bin/mysqladmin version //测试服务器是否已启动

#/opt/mysql/bin/mysqladmin ping

 

步骤七:将mysql加入环境变量

#export PATH=/opt/mysql/bin:$PATH

 

步骤八:修改root密码

#mysqladmin -u root password "aHa"

 

最后,由于在编译PHP源码时,会使用到部分MySQL的库文件和头文件,若服务器还需提供PHP动态网页服务,会导致找不到相应的文件,解决办法是为目录创建一个符号连接,其实现的操作命令如下:
    #ln -s /opt/mysql/lib/mysql /usr/lib/mysql
    #ln -s /opt/mysql/include/mysql /usr/include/mysql

 

至此,MySql安装完毕

 

2. 安装Apache

步骤一:安装

#cd /usr/local/src  

#tar -zxvf httpd-2.2.21.tar.gz  

#cd httpd-2.2.21  

#./configure --prefix=/opt/httpd //指定Apache安装目录

>--enable-so //声明使用动态函数库

>--with-mpm=prefork  

>--enable-modules="setenvif rewrite deflate vhost_alias" 

#make  

#make install  

#/opt/httpd/bin/apachectl start 

 

步骤二:设置apache自启动

#echo "/opt/httpd/bin/apachectl start">> /etc/rc.d/rc.local 

#echo "/ opt/httpd /bin/apachectl start" /opt/httpd /bin/apachectl start 

 

步骤三:确定启动状态

#netstat –utl

tcp 0 0 *http ** LISTEN

如果出现以上信息,则证明启动成功

 

3. 安装并配置PHP

步骤一:安装

#tar -zxvf php-5.2.17.tar.gz  

#cd php-5.2.17  

#./configure --prefix=/opt/php --with-mysql=/opt/mysql \  

>--with-apxs2=/opt/httpd/bin/apxs  //通俗易懂,不解释

#make   

#make install  

#make clean  

#make distclean 

 

步骤二:Apache中加载php模块

#cp php.ini-dist /usr/local/lib/php.ini
#vim httpd.conf

查看是否有下面这句话,没有则添加
LoadModule php5_module modules/libphp5.so

找到“#AddType application/x-gzip .gz .tgz”添加
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps

 

步骤三:建立php测试文件

# vi /opt/httpd/htdocs/test.php

phpinfo();

?>

:wq

 

4. 配置并部署PHPMyAdmin

# tar zxvf phpMyAdmin-3.4.7.1-english.tar.gz

# mv phpMyAdmin-3.4.7.1- english /opt/httpd/htdocs/phpmyadmin

# cd /opt/httpd/htdocs/phpmyadmin

# cp ./libraries/config.default.php ./config.inc.php

#vi config.inc.php

$cfg['PmaAbsoluteUri'] = ‘http://localhost/phpmyadmin';

$cfg['Servers'][$i]['auth_type'] = 'http';

 

测试

重启apache服务器

# /opt/httpd/bin/apachectl restart

浏览器中输入:http://127.0.0.1/test.php,出现如下页面 

 

浏览器中输入:http://127.0.0.1 /phpmyadmin ,出现如下页面

 

OK,大功告成

 

结束语

至此,LAMP的安装及简单配置过程已经介绍完毕,有兴趣的朋友可以深入研究一下LAMP的详细配置过程。当然,由于源码版本及硬件存在差异性,过程中也许会出现各种各样奇怪的问题,大家可以根据系统给出的提示信息去查找解决方案。解决问题的能力以及抗摧残能力是搞Linux的人的必备基本素质。

希望能够多多交流,祝你成功!

PS:如果你觉得用LAMP开发web项目已经过时,你还会有更多的选择,Writing a web application is not just LAMP any more!

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

Docker on Linux: Containerization for Linux Systems Docker on Linux: Containerization for Linux Systems Apr 22, 2025 am 12:03 AM

Docker is important on Linux because Linux is its native platform that provides rich tools and community support. 1. Install Docker: Use sudoapt-getupdate and sudoapt-getinstalldocker-cedocker-ce-clicotainerd.io. 2. Create and manage containers: Use dockerrun commands, such as dockerrun-d--namemynginx-p80:80nginx. 3. Write Dockerfile: Optimize the image size and use multi-stage construction. 4. Optimization and debugging: Use dockerlogs and dockerex

The Compatibility of IIS and PHP: A Deep Dive The Compatibility of IIS and PHP: A Deep Dive Apr 22, 2025 am 12:01 AM

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

C  : Is It Dying or Simply Evolving? C : Is It Dying or Simply Evolving? Apr 24, 2025 am 12:13 AM

C isnotdying;it'sevolving.1)C remainsrelevantduetoitsversatilityandefficiencyinperformance-criticalapplications.2)Thelanguageiscontinuouslyupdated,withC 20introducingfeatureslikemodulesandcoroutinestoimproveusabilityandperformance.3)Despitechallen

Explain the purpose of foreign keys in MySQL. Explain the purpose of foreign keys in MySQL. Apr 25, 2025 am 12:17 AM

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

CentOS: Security, Stability, and Performance CentOS: Security, Stability, and Performance Apr 21, 2025 am 12:11 AM

CentOS is the first choice for server and enterprise environments for its superior security, stability and performance. 1) Security provides forced access control through SELinux to improve system security. 2) Stability is supported by the LTS version for up to 10 years to ensure the stability of the system. 3) Performance significantly improves system response speed and resource utilization by optimizing kernel and system configuration.

How does MySQL differ from Oracle? How does MySQL differ from Oracle? Apr 22, 2025 pm 05:57 PM

MySQL is suitable for rapid development and small and medium-sized applications, while Oracle is suitable for large enterprises and high availability needs. 1) MySQL is open source and easy to use, suitable for web applications and small and medium-sized enterprises. 2) Oracle is powerful and suitable for large enterprises and government agencies. 3) MySQL supports a variety of storage engines, and Oracle provides rich enterprise-level functions.

SQL vs. MySQL: Clarifying the Relationship Between the Two SQL vs. MySQL: Clarifying the Relationship Between the Two Apr 24, 2025 am 12:02 AM

SQL is a standard language for managing relational databases, while MySQL is a database management system that uses SQL. SQL defines ways to interact with a database, including CRUD operations, while MySQL implements the SQL standard and provides additional features such as stored procedures and triggers.

See all articles