php扩展和嵌入--如何在linux下配置LAMP环境
在linux下面,使用源码包编译的方式安装LAMP,可以对内部的编译机制和php的模块加载等方面有更加深入的了解。
所谓LAMP指的是Linux+Apache+Mysql+Php,这些软件安装完毕了之后,就算是成功搭建了进行php开发的环境了。
首先则是要下载源码包:
apache:wget http://apache.dataguru.cn//httpd/httpd-2.4.7.tar.bz2mysql:直接用apt-get安装好了,这个源码新版本的比较难找。php:wget http://cn2.php.net/distributions/php-5.5.7.tar.bz2 下载完了源码包之后,要进行解压缩,基本的解压缩命令如下: http://www.cnblogs.com/eoiioe/archive/2008/09/20/1294681.html针对.tar.bz2就是 tar jxvf 针对.tar.gz 就是tar zxvf
1 安装mysql
首先说安装mysql。因为对于mysql来说,源码包比较难找,其实也没必要通过编译的方式安装。所以最方便的方式就是直接使用apt-get的安装方式。 sudo apt-get install mysql-client sudo apt-get install mysql-server 按照提示操作了之后,就完成了安装的大部分。在提示中要求设定用户名和密码,这个是连接数据库主要所需要的参数。 接下来就用这个命令进行一下检测: mysql -uusername -ppassword 把username和password换成本来设置的值,然后看一下mysql是否安装成功了。 正常情况下mysql应该是被注册为linux的服务了。可以通过如下命令察看一下: chkconfig --list 查看所有已注册的服务。
2 安装apache
安装apache的时候,首先解压缩并且进入源码目录: tar jxvf apache-version.tar.bz2 cd apache-version/
然后对apache进行配置: ./configure –prefix=/usr/local/apache –enable-module=so –enable-module=rewrite –enable-shared=max –htdocsdir=/var/www &&
这里给出的prefix参数代表安装的目录。htdocsdir参数代表apache服务器的localhost文件位置。enable-module参数则启动和so和rewrite两个模块。so是用来提供DSO支持的apache核心模块。rewrite是实现地址重写的模块。像这些模块都是不能动态的加载进去的,以后需要的话还得重新编译源码,所以推荐都加载进去。 enable-shared=max参数是指定把so以外所有的apache标准模块都编译成DSO模块,而不是apache核心内。 然后就开始: make make install
接下来需要把apache设定为linux的服务: 首先复制启动文件到服务目录下: cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
然后打开服务文件: vim /etc/init.d/httpd
在#!/bin/sh 后面加上下面两行: #chkconfig:345 85 15
#description: Start and stops the Apache HTTP Server.
chkconfig:后面定义的使启动服务的运行级别(例子中使2345启动改服务),以及关闭和启动服务的顺序,(上例中关闭服务的顺序使8,启动的顺序使92)
descriptions:对改服务的描述
接下来更改文件的执行权限,并且增加服务: chmod +x /etc/rc.d/init.d/httpd
chkconfig –add httpd
这样对apache的配置就完成了。
注意:在apache配置的时候可能会出现出现缺包的情况,我之前碰到的是zlib,可以通过下载zlib的源码包,并且同样进行配置安装的形式,在配置的时候可以指定安装目录,比如是/usr/local/zlib 那么再次配置apahce的时候就要加上 --with-zlib=/usr/loca/zlib 来把这个依赖添加上。 别的包也是同样的道理。
3 php安装
同样要执行解压缩和进入目录的操作。 接下来是配置的过程: ./configure --prefix=[php安装目录] --with-config-file-path=[php安装目录] --with-apxs2=[apache安装目录]/bin/apxs --with-mysql=[mysql安装目录] --enable-debug --enable-maintainer-zts
如果还想要添加别的库的话,就用--with-库名=[库安装目录] --enable-debug参数会在出错的时候输出很多有用的信息,从而快速定位错误。 而-enable-maintainer-zts则会让PHP思考在多线程环境中的行为,并且可以让你捕获常见的程序错误,这些错误在非线程环境中不会引起问题,但在多线程环境中却使你的扩展变得不可用。 接下来进入 make make install 常见的错误可以看下面这个链接: http://lyp.cn/350_how-to-fix-php-compile-errors
如果没有yum包的话,找到相应的apt-get包也ok的。
接下来在apache中进行配置: vim /usr/local/apache/conf/httpd.conf 然后在AddType中添加: AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps
在DirectoryIndex增加 index.php,以便Apache识别PHP格式的index
DirectoryIndex index.html index.php
重启apache服务使更改生效: sudo /etc/init.d/httpd restart
再之后,要拷贝php的配置文件: cp ../php-5.2.10/php.ini.dist /usr/local/php/lib/php.ini
然后就可以进行验证了,在网络文件夹下建立info.php: 接着打开浏览器,输入localhost/info.php 如果输出正常,那么配置就完成了。

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

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

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











The SNMP extension for PHP is an extension that enables PHP to communicate with network devices through the SNMP protocol. Using this extension, you can easily obtain and modify the configuration information of network devices, such as CPU, memory, network interface and other information of routers, switches, etc. You can also perform control operations such as switching device ports. This article will introduce the basic knowledge of the SNMP protocol, how to install the SNMP extension of PHP, and how to use the SNMP extension in PHP to monitor and control network devices. 1. SN

From start to finish: How to use php extension cURL for HTTP requests Introduction: In web development, it is often necessary to communicate with third-party APIs or other remote servers. Using cURL to make HTTP requests is a common and powerful way. This article will introduce how to use PHP to extend cURL to perform HTTP requests, and provide some practical code examples. 1. Preparation First, make sure that php has the cURL extension installed. You can execute php-m|grepcurl on the command line to check

The combination of PHP and HTML is a common technology in web development. PHP can embed dynamic content in HTML files and implement auxiliary functions, which greatly improves the interactivity and customizability of the website. This article will introduce three techniques for embedding code and provide specific code examples for reference. 1. Use PHP tags to embed code. The most common way is to use PHP tags () to embed PHP code into HTML files to display dynamic content. For example, you can use PHP

To extend PHP function functionality, you can use extensions and third-party modules. Extensions provide additional functions and classes that can be installed and enabled through the pecl package manager. Third-party modules provide specific functionality and can be installed through the Composer package manager. Practical examples include using extensions to parse complex JSON data and using modules to validate data.

1.UncaughtError:Calltoundefinedfunctionmb_strlen(); When the above error occurs, it means that we have not installed the mbstring extension; 2. Enter the PHP installation directory cd/temp001/php-7.1.0/ext/mbstring 3. Start phpize(/usr/local/bin /phpize or /usr/local/php7-abel001/bin/phpize) command to install php extension 4../configure--with-php-config=/usr/local/php7-abel

The POSIX extensions for PHP are a set of functions and constants that allow PHP to interact with POSIX-compliant operating systems. POSIX (PortableOperatingSystemInterface) is a set of operating system interface standards designed to allow software developers to write applications that can run on various UNIX or UNIX-like operating systems. This article will introduce how to use POSIX extensions for PHP, including installation and use. 1. Install the POSIX extension of PHP in

PHP is a popular server-side language that can be used to develop web applications and process files. The ZipArchive extension for PHP is a powerful tool for manipulating zip files in PHP. In this article, we’ll cover how to use PHP’s ZipArchive extension to create, read, and modify zip files. 1. Install the ZipArchive extension. Before using the ZipArchive extension, you need to ensure that the extension has been installed. The installation method is as follows: 1. Install

PHP and WebDriver extensions: How to simulate user clicks and input operations In recent years, with the rapid development of web applications, automated testing has become more and more important. In automated testing, simulating user operations is a key link, which allows us to test and verify our applications more accurately. In PHP development, we usually use SeleniumWebDriver to implement automated testing. SeleniumWebDriver is a powerful tool which can simulate
