Home Backend Development PHP Tutorial How to build a php environment in php5.6+apache2.4+linux

How to build a php environment in php5.6+apache2.4+linux

Aug 08, 2016 am 09:33 AM
apache nbsp php

How to build a php environment with php5.6+apache2.4+linux

Foreword

 Recently, I suddenly wanted to build a personal blog. Although the author is good at java-web, for various reasons, I chose the popular php+mysql to build a personal blog. For PHP, I have only heard of its name, but have never learned it. Therefore, the author will record the entire process one by one, starting from the establishment of PHP environment, to the leasing of servers and domain names, and the selection of PHP blog templates. It is planned to take one month to learn PHP and one month to rent a server and find blog templates and other related final processes. Now let us start by setting up the php environment. Note that this is a tutorial on a Linux server. Centos6.4 installed on a virtual machine has been successfully tested. As for Windows, the author is stuck in the loading module part, alas. . . .

There are three main steps to build a php environment, the first step is

 Install apache (2.4) server:

 Before installing apache, you need to install APR, APR-Util and PCRE dependency packages, because apache depends on them. The specific download address is as follows

 APR and APR-Util: http://apr.apache.org/download.cgi

 PCRE: http://sourceforge.net/projects/pcre/files/pcre

The download address of apache is:

http://httpd.apache.org/download.cgi

 The versions downloaded by the author are specifically, 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).

After downloading, it is installed (the relevant directories need to be created by yourself)

 1.apr installation:

 Decompression: Execute in the apr file path (the downloaded file has been mv to the apr directory)

 tar -zxvf apr-1.5.1.tar.gz, the file will be decompressed to the current path

 Create soft link and install:

 (1) ln -s /opt/apr/apr /usr/local/apr

 (2) cd apr-1.5.1

 (3)./configure --prefix=/usr/local/apr (prefix is ​​to set the installation directory, and there is a space in front of configure, please pay attention)

 (4)make

 (5)make install

2. Installation of apr-util:

 Decompression: Execute in the apr-util file path (the downloaded file has been mv to the apr-util directory)

 tar -zxvf apr-util-1.5.4.tar.gz, the file will be decompressed to the current path

 Create soft link and install:

 (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 is ​​to set the installation directory)

 (4)make

 (5)make install

3.pcre installation:

 Decompression: Execute in the pcre file path (the downloaded file has been mv to the pcre directory)

 tar -zxvf pcre-8.36.tar.gz, the file will be decompressed to the current path

 Create soft link and install:

 (1) ln -s /opt/apr/pcre /usr/local/pcre

  (2) cd pcre-8.3.6

 (3)./configure --prefix=/usr/local/pcre (prefix is ​​to set the installation directory)

 (4)make

 (5)make install

 

 4. The last step is to install apache:

 Decompression: Execute in the apache file path (the downloaded file has been mv to the apache directory)

 tar -zxvf httpd-2.4.10.tar.gz, the file will be decompressed to the current path

 Create soft link and install:

 (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 (the path is the installation path of apr, the same below)

   --with-apr-util=/usr/local/apr-util

   --with-pcre=/usr/local/pcre

 Please help for the specific meaning of the installation parameters

 (4) make

 (5) make install

At this point, apache has been installed. The next step is to start and test whether it started successfully

Execute command:

 /usr/local/apache2.4/bin/apachectl start

 Check if there is an apache process

 ps aux | grep httpd

 The following is the result of the author executing the command

 

If there is a process, you can enter http://localhost. The author’s result is

 

Since it is deployed in a virtual machine, it is accessed using the IP address of the virtual machine.

 If you can see "It works!", it does work!

For future convenience, you can add it to the service, copy apachectl to /etc/init.d/httpd, and execute like this

 service httpd start

You can start the service directly

 Install php

Before installing php, you need to make sure that libxml2 has been installed. The download address is:

 http://download.chinaunix.net/download.php?id=28497&ResourceID=6095

The author just searched Baidu at that time, it was not official. If you need official information, please use your own search capabilities

In fact, the installation is basically the same as above, just simply list the commands

 (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

 This will install libxml2.

The next step is to install php

 The official download address is:

 http://php.net/downloads.php

 Then it’s installed

After copying the file to /opt/php

Decompression:

 tar -zxvf php-5.6.3.tar.gz

 Then:

 cd php-5.6.3

Execute installation:

  ./configure

  --prefix=/usr/local/php (the path is the path where php needs to be installed)

  --with-mysql=/usr/local/mysql (the path is the installation path of mysql that has been installed)

  --with-apxs2=/usr/local/apache2.4/bin/apxs (In some tutorials, --with-apxs is written, here it is apxs2, 2 is set like this for version 2 or above)

  --with-libxml2=/usr/local/libxml2 (this is the path where we installed libxm2 above)

Then just make, make install

 

The last step is to configure apache to support php

Modify the apache configuration file httpd.conf

 vim /usr/local/apache2.4/conf/httpd.conf

  Then add at the end of the text

 LoadModule php5_module modules/libphp5.so (Note that in the apache installation directory, there is libphp5.so under modules. This is added during PHP installation. If not, PHP, you need to reinstall it)

 AddType application/x-httpd-php .php (.There is a space in front of it)

 (Note that if the above item is not configured properly, it will result in that when accessing http:localhost/*.php, it will be downloaded directly instead of opened)

 Screenshots of the author’s configuration

 

Next, copy the php startup file

 cp php-5.6.3/php.ini-development /usr/local/php/lib/php.ini

 Save and restart

 service httpd start

 If no error is reported, it means the startup is successful

 

 Test whether php is installed successfully

Write a simple php page, as follows

 

Isn’t it very simple? Then save it as welcome.php. The file needs to be placed in the htdocs directory of apache

 Enter http://localhost/welcome.php in the browser

 If you see the page below, the installation is successful

 

 

 Summary:

When everyone is setting up a PHP environment, please refer to several more tutorials. Various factors such as the version of each tutorial may be different, so it may not be suitable for everyone. This is also the author's experience and has referred to many tutorials. The reason for writing this tutorial is that many tutorials are not comprehensive, so I hope to use my experience to give some help to coders who are learning PHP. If you encounter difficulties with children's shoes during the installation process, you can leave me a message and I will try my best to help you

 

Copy after login

The above introduces how to build a PHP environment with php5.6+apache2.4+linux, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

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)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
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)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

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

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

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

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles