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、编译

make
Copy after login

6、测试编译

make test
Copy after login

7、安装

make install
Copy after login

8、配置文件

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,里面的内容如下:

<?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账号,并加入组群。

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

Video Face Swap

Video Face Swap

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

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
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)

Hot Topics

Java Tutorial
1665
14
PHP Tutorial
1269
29
C# Tutorial
1249
24
Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

The Continued Use of PHP: Reasons for Its Endurance The Continued Use of PHP: Reasons for Its Endurance Apr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

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.

What happens if session_start() is called multiple times? What happens if session_start() is called multiple times? Apr 25, 2025 am 12:06 AM

Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

Using Laravel: Streamlining Web Development with PHP Using Laravel: Streamlining Web Development with PHP Apr 19, 2025 am 12:18 AM

Laravel optimizes the web development process including: 1. Use the routing system to manage the URL structure; 2. Use the Blade template engine to simplify view development; 3. Handle time-consuming tasks through queues; 4. Use EloquentORM to simplify database operations; 5. Follow best practices to improve code quality and maintainability.

How to understand DMA operations in C? How to understand DMA operations in C? Apr 28, 2025 pm 10:09 PM

DMA in C refers to DirectMemoryAccess, a direct memory access technology, allowing hardware devices to directly transmit data to memory without CPU intervention. 1) DMA operation is highly dependent on hardware devices and drivers, and the implementation method varies from system to system. 2) Direct access to memory may bring security risks, and the correctness and security of the code must be ensured. 3) DMA can improve performance, but improper use may lead to degradation of system performance. Through practice and learning, we can master the skills of using DMA and maximize its effectiveness in scenarios such as high-speed data transmission and real-time signal processing.

Composer: Aiding PHP Development Through AI Composer: Aiding PHP Development Through AI Apr 29, 2025 am 12:27 AM

AI can help optimize the use of Composer. Specific methods include: 1. Dependency management optimization: AI analyzes dependencies, recommends the best version combination, and reduces conflicts. 2. Automated code generation: AI generates composer.json files that conform to best practices. 3. Improve code quality: AI detects potential problems, provides optimization suggestions, and improves code quality. These methods are implemented through machine learning and natural language processing technologies to help developers improve efficiency and code quality.

See all articles