php5.6+apache2.4+linux搭建php环境,php5.6apache2.4
php5.6+apache2.4+linux搭建php环境,php5.6apache2.4
前言
最近突然想搭建个人博客,尽管笔者擅长java-web,但综合各种原因,于是选择了大众化的php+mysql搭建个人博客。对于php,只闻其大名,但从未学过,于是,笔者将从php环境搭建开始,到服务器、域名的租赁,php博客模板的选择,一一记录整个过程。计划为学习php用时一个月,租赁服务器和寻找blog模板等相关最终过程耗时一个月。现在就让我们从搭建php环境开始吧。注意,这是在linux服务器上的教程, 已在虚拟机上安装的centos6.4测试成功过,至于windows的,笔者卡在载入模块部分,唉。。。。
搭建php环境主要分为三个步骤,第一步为
安装apache(2.4)服务器:
apache安装之前,需要安装APR、APR-Util和PCRE依赖包,因为apache是依赖于它们的。具体下载地址如下
APR和APR-Util:http://apr.apache.org/download.cgi
PCRE:http://sourceforge.net/projects/pcre/files/pcre
apache的下载地址为:
http://httpd.apache.org/download.cgi
笔者下载的版本具体为,apache(httpd-2.4.10.tar.gz), apr(apr-1.5.1.tar.gz), apr-util(apr-util-1.5.4.tar.gz), pcre(pcre-8.36.tar.gz)。
下载完以后就是安装了(相关目录需要自己建)
1.apr的安装:
解压:在apr文件路径下执行(下载文件已经mv到apr目录下)
tar -zxvf apr-1.5.1.tar.gz,文件就解压到当前路径下了
创建软链接并安装:
(1) ln -s /opt/apr/apr /usr/local/apr
(2) cd apr-1.5.1
(3)./configure --prefix=/usr/local/apr (prefix为设置安装目录,和configure前面有空格,注意下)
(4)make
(5)make install
2.apr-util的安装:
解压:在apr-util文件路径下执行(下载文件已经mv到apr-util目录下)
tar -zxvf apr-util-1.5.4.tar.gz,文件就解压到当前路径下了
创建软链接并安装:
(1) ln -s /opt/apr/apr-util /usr/local/apr-util
(2) cd apr-util-1.5.4
(3)./configure --prefix=/usr/local/apr-util (prefix为设置安装目录)
(4)make
(5)make install
3.pcre的安装:
解压:在pcre文件路径下执行(下载文件已经mv到pcre目录下)
tar -zxvf pcre-8.36.tar.gz,文件就解压到当前路径下了
创建软链接并安装:
(1) ln -s /opt/apr/pcre /usr/local/pcre
(2) cd pcre-8.3.6
(3)./configure --prefix=/usr/local/pcre (prefix为设置安装目录)
(4)make
(5)make install
4.最后一步就是安装apache了:
解压:在apache文件路径下执行(下载文件已经mv到apache目录下)
tar -zxvf httpd-2.4.10.tar.gz,文件就解压到当前路径下了
创建软链接并安装:
(1) ln -s /opt/apr/apache /usr/local/apache
(2) cd httpd-2.4.10
(3)./configure --prefix=/usr/local/apache2.4
--enable-so-rewrite=shared
--with-mpm=prefork
--with-apr=/usr/local/apr (路径为apr的安装路径,下同)
--with-apr-util=/usr/local/apr-util
--with-pcre=/usr/local/pcre
安装参数具体含义请help
(4) make
(5) make install
至此,apache就已经安装完成了,接下来就是启动和测试其是否启动成功了
执行命令:
/usr/local/apache2.4/bin/apachectl start
检查是否有apache进程
ps aux | grep httpd
如下,是笔者执行命令的结果
如果有进程的话,就可以输入http://localhost,笔者的结果为
由于是部署在虚拟机,故用的是虚拟机的ip访问的。
如果你能看到"It works!", it does work!
为了以后方便,可以把它添加到服务中去,将apachectl 拷贝到 /etc/init.d/httpd, 这样执行
service httpd start
就可以直接启动服务了
安装php
安装php前需要有确保已经安装libxml2,下载地址为:
http://download.chinaunix.net/download.php?id=28497&ResourceID=6095
笔者当时也是随便百度的,并不是官方的,如果需要官方的话,请大家自己发挥搜索能力啦
安装其实也是和上面大体相同,就简单罗列命令就是了
(1)tar -zxvf libxml2-2.7.4.tar.gz
(2)cd libxml2-2.7.4
(3)./configure --prefix=/usr/local/libxml2
(4)make
(5)make install
这样就把libxml2安装好了。
接下来就是安装php了
官方下载地址为:
http://php.net/downloads.php
然后是安装了
在把文件拷贝到/opt/php后
解压:
tar -zxvf php-5.6.3.tar.gz
然后:
cd php-5.6.3
执行安装:
./configure
--prefix=/usr/local/php (路径为需要安装php的路径)
--with-mysql=/usr/local/mysql (路径为已经安装好的mysql的安装路径)
--with-apxs2=/usr/local/apache2.4/bin/apxs (在有些教程写的是--with-apxs,这里写的是apxs2,2是版本2以上的就这样设置)
--with-libxml2=/usr/local/libxml2 (就是我们上面安装libxm2的路径)
然后make,make install就可以了
最后就是配置apache让它支持php
修改apache的配置文件httpd.conf
vim /usr/local/apache2.4/conf/httpd.conf
然后在文本最后面添加
LoadModule php5_module modules/libphp5.so (注意,在apache安装目录下,modules下有libphp5.so,这是php安装时添加进去的,如果没有,php,你需要重装下)
AddType application/x-httpd-php .php (.前面有空格)
(注意,如果上面一条没配置好的话会导致,,访问http:localhost/*.php会直接下载,而不是打开)
笔者配置截图
接下来复制php启动文件
cp php-5.6.3/php.ini-development /usr/local/php/lib/php.ini
保存,重新启动
service httpd start
如果没有报错则说明启动成功
测试php是否安装成功
写一个简单的php页面,如下
是不是很简单,然后保存为welcome.php,文件需要放到apache的htdocs目录下
在浏览器中输入http://localhost/welcome.php
如果看到下面的页面,则说明安装成功了
总结:
大家在搭建php环境的时候,多参考几个教程。每个教程的版本等各个因素可能都不一样,所以并不一定适合大家,这也是笔者的经验,参考了很多教程。写这篇教程的原因是发现很多教程并不全面,故希望以笔者的经验,给正在学习php的coder一些帮助。在安装过程中遇到困难的童鞋可以给我留言,我会尽力帮助大家的

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



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

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

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

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,

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

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.

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.
