Home Backend Development PHP Tutorial Linux下怎么配置PHP环境?

Linux下怎么配置PHP环境?

Jun 01, 2016 pm 12:35 PM
linux php

Linux下怎么配置PHP环境?

在Linux下搭建PHP环境比Windows下要复杂得多。除了安装Apache,PHP等软件外,还要安装一些相关工具,设置必要参数。而且,如果要使用PHP扩展库,还要进行编译。

安装之前要准备如下安装包:

http-2.2.8.tar.gz。下载地址:http://www.apache.org。

php-5.2.5.tar.gz。下载地址:http://www.php.net/downloads.php。

Mysql-5.0.5la-Linux-i686.tar.gz。下载地址:http://www.Mysql.com。

在Linux下配置php开发环境,需要注意以下几问题。

首先需要打开Linux终端(Linux下几乎所有的软件都需要在终端下安装)。打开RedHat9的“主菜单/系统工具”,在弹出的菜单中选择“终端”命令。

在Linux下配置Apache和php,同样需要配置php.ini和httpd.conf。

Linux下安装Apache

首先到官方网站http://www.apache.org下载Linux的“http2.2.8.tar.gz”压缩包。

在Linux下安装和配置Apache服务器的操作步骤如下:

 ● 进入到Apache安装文件的目录,如/usr/local/work。

 ● 解压安装包,完成后进入到httpd2.2.8目录中, tar xfz httpd2.2.8.tar.gz     cd  httd2.2.8

 ● 建立makefile,将Apache服务器安装到user/local/Apache2下,./configure-prefix=/usr/local/Apache2-enable-module=so

 ● 编译文件。make

 ● 开始安装。 make install

 ● 安装完成后,在终端窗口中键入如下命令启动或重启Apache服务。/usr/local/Apache2/bin/Apachect1 start                     /usr/local/Apache2/bin/Apachect1  restart

 ● 打开Mozilla浏览器,在地址栏中输入“http://localhost/”,看看Apache服务器安装是否成功。

Linux下安装php

1、 下载

    http://www.php.net/downloads.php

2、解压

    tar -zxvf php-5.3.16.tar.gz

3、建立目标文件夹

    mkdir /usr/local/php

    也就是说等下安装的php要安装到这个文件夹里面

4、配置

    回到原来解压后的文件夹

    ./configure --prefix=/usr/local/php  --with-apxs2=/usr/local/apache/bin/apxs

    注意这里有一个-with-apxs2=/usr/local/apache/bin/apxs选项,其中apxs是在安装Apache时产生的,apxs是一个为Apache HTTP服务器编译和安装扩展模块的工具,使之可以用由mod_so提供的LoadModule指令在运行时加载到Apache服务器中。我的理解是通过这个工具把PHP模块动态加载到Apache中

出现错误:configure: error: xml2-config not found. Please check your libxml2 installation.

运行yum install libxml2,然后再运行yum install libxml2-devel安装完毕后,重新运行上面的./configure命令。

5、编译

1

make

Copy after login

6、测试编译

1

make test

Copy after login

7、安装

1

make install

Copy after login

8、配置文件

1

cp /usr/local/src/php-5.3.16/php.ini-development  /usr/local/php/lib/php.ini

Copy after login

把原来位于源代码里面的php.ini-development拷贝到/usr/local/php/lib/php.ini下,并且重命名为php.ini

9.重启apache

10、测试

在apache的htdocs下建立一个php文件test.php,里面的内容如下:

1

2

3

<?php

    phpinfo();

?>

Copy after login

然后在浏览器里输入http://127.0.0.1/test.php

如果出现php的相关配置,成功,如果什么都没有输入,说明失败,重新以上步骤或者查找原因

如果决定在安装后改变配置选项,只需重复最后的三步configure, make, 以及 make install,然后需要重新启动 Apache 使新模块生效。Apache不需要重新编译。

测试结果如下图:

1.jpg

Linux下安装Mysql

在Linux系统安装Mysql服务器需要到官方网站http://www.Mysql.com下载Linux下Mysql的安装包“mysql-5.0.5la-linux-i686.tar.gz”。

在Linux下安装和配置mysql服务器的操作步骤如下.

 ● 将下载的mysql-5.0.51a-linux-i686.tar.gz文件复制到/usr/local/work目录下,创建mysql账号,并加入组群。

1

2

groupadd  mysql

useradd-g mysql  mysql

Copy after login

 ● 进入到Mysql的安装目录,将其解压(例如:目录为/usr/local/mysql)。

 ● 考虑到mysql数据库升级的需要,所以通常以链接的方式建立/usr/local/mysql目录。

 ● 进入到mysql目录,在/usr/local/mysql/data中建立mysql数据库.

 ● 修改文件权限。

 ● 到此Mysql安装成功。

用户可以通过在终端中键入命令启动Mysql服务。/usr/local/mysql/bin/mysqld_safe -user=Mysql& 启动后键入命令,进入Mysql。/user/local/mysql/bin/mysql -uroot

Linux下发布网站

Linux下发布基于PHP的网站,首先需要配置PHP的运行环境,其次需要对网卡参数进行设定。比如:

 ● 假设已经申请到了以下网络参数:ip:192.168.1.*   netmask:255.255.255.*    network:192.168.1.0    broadcast:192.168.1.*     gateway:192.168.1.*    主机名:abc  DNS :168.95.1.*

 ● 将网站的所有文件复制到Apache主目录下。

 ● 设置主机名称。在终端窗口中键入如下命令编辑/etc/sysconfig/network文件:vi/ect/sysconfig/network  将文件中的参数NETQWORKING设置为yes,表示启动网络,将参数HOSTNAME设置abc,表示设置主机名为“abc”。

 ● 设置网卡参数。在终端窗口中键入如下命令编辑文件/ect/sysconfig/network-scripts/ifcfg-eth0:vi  /etc/sysconfig/network-scripts/ifefg-eth0  按如下形式设置该文件的相关参数。DEVICE =eth0:设置网卡名称,要与ifcfg-eth0对应。ONBOOT=yes:指定在开机时启动网卡。BOOTPROTO=static:设定启动时获取IP的方式。  IPADDR=192.168.1.*:设定服务器IP地址。NETMASK=255.255.255.*:设定子网掩码。BROADCAST=192.168.1.*:设定同网段的广播地址。GETWAY=192.168.1.*:设定网卡的网关。

 ● 设置DNS主机的IP。在终端编辑/etc/resolv.conf文件:vi/etc/resoplv.conf   设置参数nameserver的值为168.95.1.*。

 ● 重新启动网络设置。在终端窗口中键入如下命令: /etc/rc.d/inin.d/network  restart   ifdow  eth0   ifup  eth0

 ● 打开浏览器,在地址栏目中键入服务器IP地址或域名,能正常显示网站,说明发布成功。

推荐教程: linux教程

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)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 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)

How to solve the permissions problem encountered when viewing Python version in Linux terminal? How to solve the permissions problem encountered when viewing Python version in Linux terminal? Apr 01, 2025 pm 05:09 PM

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Why does an error occur when installing an extension using PECL in a Docker environment? How to solve it? Why does an error occur when installing an extension using PECL in a Docker environment? How to solve it? Apr 01, 2025 pm 03:06 PM

Causes and solutions for errors when using PECL to install extensions in Docker environment When using Docker environment, we often encounter some headaches...

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

How to efficiently integrate Node.js or Python services under LAMP architecture? How to efficiently integrate Node.js or Python services under LAMP architecture? Apr 01, 2025 pm 02:48 PM

Many website developers face the problem of integrating Node.js or Python services under the LAMP architecture: the existing LAMP (Linux Apache MySQL PHP) architecture website needs...

How to solve permission issues when using python --version command in Linux terminal? How to solve permission issues when using python --version command in Linux terminal? Apr 02, 2025 am 06:36 AM

Using python in Linux terminal...

How to configure apscheduler timing task as a service on macOS? How to configure apscheduler timing task as a service on macOS? Apr 01, 2025 pm 06:09 PM

Configure the apscheduler timing task as a service on macOS platform, if you want to configure the apscheduler timing task as a service, similar to ngin...

See all articles