English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Detailed Explanation of CentOS5.5 Set up PHP Environment (Best LAMP Environment)

This article details the process of setting up a PHP environment in the Linux system. Since PHP is written in C language, it was initially also run on the Linux system, so Linux is the best environment for PHP.

For the software used in this article, please click this link to download.

CentOS5.5The official website no longer provides this, it is recommended that everyone use centos6Above versions:

centos6.8Download address: https://www.oldtoolbag.com/softs/499124.html

centos7.2Download address: https://www.oldtoolbag.com/softs/499109.html

>>> 【Click to download

The author of this article installed CentOS using a virtual machine (VMware) 5.5 Perform experiments. The following is the installation details

1, Preparation work

1. Please first confirm whether Apache, MySQL, PHP have been installed in the Linux system you installed. If installed, please uninstall first.

Check if installed (take Apache as an example)

[root@gamejzy Linux]# rpm -qa|grep httpd 

Note: rpm -qa is to view all software installed on this machine. grep httpd is to filter out software related to httpd (Apache). Note: grep php is to view PHP; grep mysql is to view MySQL

If there is an empty space after executing the command, it means that the Apache software is not installed on the machine. If there are situations like the following, it means that it has been installed.

If it is as shown in the figure above, then you need to uninstall these three software programs.

The uninstall command is as follows:

[root@gamejzy Linux]# rpm -e httpd-2.2.3-43.el5.centos --nodeps 

Note:--nodeps is to force uninstall

2. Please make sure that gcc and g are installed on your Linux system++ compiler

It is very simple to check whether it is installed, type “gc” or “g+”, press the tab key, see if there are any commands displayed below.

If there is no gcc or g, it's okay, install gcc, g++ The method is very simple

Install gcc:

yum -y install gcc 

Install g++:

yum install gcc-c++ 

3. Copy all software packages (most are tar packages) to /tmp/under lamp and unpack

Unpack tar.gz command (take php software as an example): tar zxvf php-5.2.6.tar.gz 

After executing this command, a php will be created in the current directory-5.2.6 The unpacked files will be placed in the php-5.2.6 folders in the folder

Please unpack all packages in the same way and delete all *.tar.gz files

[root@gamejzy lamp]# rm -rf *.gz 

The above commands delete all .gz files

4. Introduction to compiling and installing software packages

The process of installing each source code package on the Linux system is as follows:
△ Configuration (configure)
△ Compilation (make)
△ Installation (make install)

2Build LAMP environment (install in the order given below)

All software is installed here /usr/Under local
1. Install libxml

Installation order:1Enter the libxml directory;2Configure parameters (including installation path; dependent software; installation features, etc.);3Compile;4Install. Note: The installation of all software packages is similar

[root@gamejzy lamp]# cd libxml2-2.6.30/ 
[root@gamejzy libxml2-2.6.30]# ./configure --prefix=/usr/local/libxml2 

./configure is the command for configuring package parameters,--Prefix indicates the specified installation directory, most directories will be automatically created if they do not exist, and some will need to be created manually

[root@gamejzy libxml2-2.6.30]# make && make install 

The above command executes compiling and installing together, since the software is small, the installation speed is relatively fast, but for larger software, it may take a longer time.

Chapter 2: Install libmcrypt

[root@gamejzy lamp]# cd libmcrypt-2.5.8/ 
[root@gamejzy libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt 
[root@gamejzy libmcrypt-2.5.8]# make && make install 

Chapter 3: Install zlib

[root@gamejzy lamp]# cd zlib-1.2.3/ 
[root@gamejzy zlib-1.2.3]# ./configure 
[root@gamejzy zlib-1.2.3]# make && make install 

./Do not follow configure with --The prefix parameter allows it to be installed in the default directory, because zlib is used when installing libpng.
Chapter 4: Install libpng

[root@gamejzy lamp]# cd libpng-1.2.31/ 
[root@gamejzy libpng-1.2.31]# ./configure --prefix=/usr/local/libpng 
[root@gamejzy libpng-1.2.31]# make && make install 

Chapter 5: Install jpeg6

This software does not automatically create directories during configuration, and we need to create them manually

[root@gamejzy libpng-1.2.31]# mkdir /usr/local/jpeg6 
[root@gamejzy libpng-1.2.31]# mkdir /usr/local/jpeg6/]# 
[root@gamejzy libpng-1.2.31]# mkdir /usr/local/jpeg6/lib 
[root@gamejzy libpng-1.2.31]# mkdir /usr/local/jpeg6/include 
[root@gamejzy libpng-1.2.31]# mkdir -p /usr/local/jpeg6/man/man1 

Directory generation completed!

[root@gamejzy lamp]# cd jpeg-6b/ 
[root@gamejzy jpeg-6b]# ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static 
[root@gamejzy jpeg-6b]# make && make install 

./Parameter description in configure:
--enable-shared - Build shared libraries using GNU's libtool
--enable-static - Build static libraries using GNU's libtool

Chapter 6: Install freetype

[root@gamejzy lamp]# cd freetype-2.3.5/ 
[root@gamejzy freetype-2.3.5]# ./configure --prefix=/usr/local/freetype 
[root@gamejzy freetype-2.3.5]# make && make install 

Chapter 7: Install autoconf

[root@gamejzy lamp]# cd autoconf-2.61/ 
[root@gamejzy autoconf-2.61]# ./configure 
[root@gamejzy autoconf-2.61]# make && make install 

This software is directly installed in the default directory.

Chapter 8: Install GD

[root@gamejzy lamp]# cd gd-2.0.35/ 
[root@gamejzy gd-2.0.35]# ./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg6/ --with-png=/usr/local/libpng/ --with-freetype=/usr/local/freetype/ 
[root@gamejzy gd-2.0.35]# make && make install 

./Parameter description in configure:
--with-jpeg=/usr/local/jpeg6/ Specify the location to find the jpeg library file
--with-png=/usr/local/libpng/ Specify the location to find the png library file
--with-freetype=/usr/local/freetype/ Specify where to find freetype 2Location of the .x font library

Note that installing this package may cause the following errors, as shown in the figure below:

If such an error occurs, the solution is:

[root@gamejzy gd-2.0.35]# vi gd_png.c 

Find the keyword "png.h" command:/png.h Enter

Replace with:/usr/local/libpng/include/png.h

The effect is as shown in the figure below:

Save and exit, continue to execute "make && make install" to install successfully.

Chapter 9: Install Apache (Key)

[root@gamejzy lamp]# cd httpd-2.2.9/ 
[root@gamejzy httpd-2.2.9]# ./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/x --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support 
[root@gamejzy httpd-2.2.9]# make && make install 

./Parameter description in configure:
--sysconfdir=/etc/httpd Specify the storage location of the Apache server's configuration file (httpd.conf and other files)
--with-included-apr Use bundled APR/APR-Util copy
--enable-so Compile as a dynamic shared object (DSO)
--enable-deflate=shared Support for compression transfer encoding
--enable-expires=shared Expiration header control
--enable-rewrite=shared Rule-based URL control
--enable-static-support to establish a static link version of the support

Test Apache Server

1Check /usr/local/ Whether apache appears below2 directory

2Check /etc/ Whether the httpd directory appears under the directory, that is, whether there are httpd.conf files, extra directories, and other content inside

3Start the Apache server

[root@gamejzy httpd]# /usr/local/apache2/]#/bin 

stop (close), restart (restart)

4View whether the Apache server is started, that is, check 80 Port whether started

[root@gamejzy httpd]# netstat -tnl|grep 80 

After executing the command, the following is displayed, indicating that it has started
tcp   0  0 :::80                  :::*                        LISTEN

5Access in the browser
If it is on the local machine, please enter in the browser address bar:http://localhost or http://127.0.0.1

If it is a remote connection, such as: SSH connection, then please enter the Linux IP address in the browser address bar. For example:http://192.168.1.233

If there is a large word "
It works!
"It means that Apache has been installed successfully.
Test completed!

Add Apache to automatically start at each boot

[root@gamejzy /]# echo "/usr/local/apache2/]#/apachectl start" >> /etc/rc.d/rc.local 

Ten, install MySQL (important)

Before installing MySQL, first create a special group and username for managing MySQL

Create a group named 'mysql'

[root@gamejzy /]# groupadd mysql 

Create a user named 'mysql' and make it belong to the 'mysql' group

[root@gamejzy /]# useradd -g mysql mysql 
[root@gamejzy lamp]# cd mysql-5.0.41/ 
[root@gamejzy mysql-5.0.41]# ./configure --prefix=/usr/local/mysql --with-extra-charsets=all 
[root@gamejzy mysql-5.0.41]# make && make install 

./configure parameter description:
--with-extra-charsets=all Install all character sets of MySQL
Note in ./If the following error occurs when configure is executed

Reason: Missing ncurses installation package.

Solution: Download and install the corresponding software package

yum list|grep ncurses 
yum -y install ncurses-devel 

After the ncurses installation is complete, then do ./configure configuration!

After the MySQL installation is complete, set some content, which is very繁琐, but also very critical, everyone is expected to learn patiently.

1Set the configuration file my.cnf, placed in /etc/ directory

[root@gamejzy mysql-5.0.41]# cp support-files/my-medium.cnf /etc/my.cnf 

2Initialize the database files, after installing MySQL, the data files and storage location of MySQL will not appear

First switch to the MySQL installation directory

[root@gamejzy mysql-5.0.41]# cd /usr/local/mysql/ 

Use mysql_install_db under the bin directory to initialize the database files and use the mysql user created above

[root@gamejzy mysql]# bin/mysql_install_db --user=mysql 

After running, you will find that a var directory will appear in the MySQL installation directory, which contains the database files, including the databases we have built, will be placed in this directory.

3Set the permissions of the MySQL installation directory

Change the owner of all files and directories under the directory to root

[root@gamejzy mysql]# chown -R root . 

Change the owner of the var directory to the mysql user

[root@gamejzy mysql]# chown -R mysql ./var/ 

Change the user group of all directories and files to the mysql group

[root@gamejzy mysql]# chgrp -R mysql . 

4Start MySQL

[root@gamejzy mysql]# /usr/local/mysql/]#/mysqld_safe --user=mysql & 

& means to start in the background
At this time, use netstat -tnl, if you see 3306 Port, then it means the startup was successful
tcp                  0                  0 0.0.0.0:3306                0.0.0.0:*                   LISTEN

5Set permissions, if we use the mysql command under the bin directory directly now, we can log in

[root@gamejzy mysql]# bin/mysql 

This is too dangerous! Therefore, it is necessary to set permissions.

First log in to MySQL, use the SQL command to delete the username whose host is not 'localhost' (all users in MySQL are in the user table of the mysql database), and only leave the account that allows local login.

mysql> delete from mysql.user where Host != 'localhost'; 

Refresh the authorization table

mysql> flush privileges; 

Set the password for the root user of MySQL on this machine

mysql> set password for 'root'@'localhost'=password('123456'); 

Note: The password set must be remembered, otherwise you cannot enter the MySQL database.

At this step, our root user has already set the password (the password is "123456We can test it by typing 'exit' to exit MySQL

At this point, the command to log in to the MySQL database cannot be bin/MySQL is so simple, it should be as follows:

[root@gamejzy mysql]# bin/mysql -h 127.0.0.1 -u root -p123456 

-h Specify hostname
-u Username
-p Password

6Close MySQL database server

[root@gamejzy mysql]# bin/mysqladmin -u root -p shutdown 

Here the root user is the MySQL user, after execution it will prompt you to enter a password, Enter password:

Enter the password and press Enter to close the database.

For the startup command, please see this section4

7Add to boot default start

[root@gamejzy mysql]# echo "/usr/local/mysql/]#/mysqld_safe --user=mysql &" /etc/rc.d/rc.local 

Chapter 11: Install PHP (Important)

Here we install the high version of PHP php-5.3.19There are many installation parameters, please pay attention.

[root@gamejzy lamp]# cd php-5.3.19/ 
apachectl stop-5.3.19]# ./configure \
 
> --prefix=/usr/local/php \
 
> --with-config-file-path=/usr/local/php/etc \
 
> --with-apxs2=/usr/local/apache2/]#/apxs \
 
> --with-mysql=/usr/local/mysql/ \
 
> --with-libxml-dir=/usr/local/libxml2/ \
 
> --with-png-dir=/usr/local/libpng/ \
 
> --with-jpeg-dir=/usr/local/jpeg6/ \
 
> --with-freetype-dir=/usr/local/freetype/ \
 
> --with-gd=/usr/local/gd2/ \
 
> --with-mcrypt=/usr/local/libmcrypt/ \
 
> --with-mysqli=/usr/local/mysql/]#/mysql_config \
 
> --enable-soap \
 
> --enable-mbstring=all \
 
> --enable-sockets 

./configure parameter description:
--with-config-file-path=/usr/local/php/etc specifies PHP5the path where the configuration file is stored
--with-apxs2=/usr/local/apache2/]#/apxs tells PHP to look for Apache 2location
--with-mysql=/usr/local/mysql/ specifies the installation directory of MySQL
--with-libxml-dir=/usr/local/libxml2/ tells PHP where to place libxml2library location
--with-png-dir=/usr/local/libpng/ tells PHP where to place the libpng library
--with-jpeg-dir=/usr/local/jpeg6/ tells PHP where to place the jpeg library
--with-freetype-dir=/usr/local/freetype/ tells PHP where to place the freetype library
--with-gd=/usr/local/gd2/ tells PHP where to place the gd library
--with-mcrypt=/usr/local/libmcrypt/ tells PHP where to place the libmcrypt library
--with-mysqli=/usr/local/mysql/]#/mysql_config activates the newly added MySQLi feature
--enable-soap activates SOAP and Web services support
--enable-mbstring=all enables multi-byte string support
--enable-The sockets variable activates the socket communication feature

Possible problems during compilation:

The following error may occur:

Solution:

cd /usr/local/mysql/lib/mysql/ 
ln -s libmysqlclient.so.15.0.0 libmysqlclient_r.so 

After compilation, if you see 'Thank you for using PHP.', it means the configuration is successful.

apachectl stop-5.3.19]# make && make install 

Compilation and installation may take a long time, please be patient!

After compilation, the following configuration is required

1and set the php.ini configuration file

apachectl stop-5.3.19]# cp php.ini-development /usr/local/php/etc/php.ini 

Note:/usr/local/php/etc is the specified location when configuring
2and integrate with Apache

First, open the Apache configuration file httpd.conf

apachectl stop-5.3.19]# vi /etc/x/httpd.conf 

You will find the following content in the file

LoadModule php5_module modules/libphp5libphp 

.so

This means that PHP has been loaded into the Apache server, what we need to do is to tell the Apache server which file extensions should be parsed using PHP/Add a line: AddType application-In the vi editor, search for 'AddType application

compress .Z/Add a line: AddType application-x-httpd
php .php

The modified effect is shown in the figure below

apachectl stop-5.3.19[root@gamejzy php /usr/local/apache2/]#/Save and exit, restart Apache 
apachectl stop-5.3.19[root@gamejzy php /usr/local/apache2/]#/bin 

3apachectl start

To test whether the Apache server can parse PHP /usr/local/apache2/Add a phpinfo.php file under the htdocs directory and enter the following code:

<?php 
header("Content-Type:text/html;Charset=utf-8"); 
phpinfo(); 
?> 

Open the browser, visit the file, and see the figure as shown below, indicating that PHP is installed successfully and integrated with the Apache server successfully.

With this, the LAMP environment under CentOS is set up, although the steps are cumbersome, but 'a good craftsman must have a sharp tool', spending some time to build a perfect environment is worthwhile.

Statement: The content of this article is from the network, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, does not undergo human editing, and does not bear relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#w3Please send an email to codebox.com (replace # with @ when sending emails) to report violations, and provide relevant evidence. Once verified, this site will immediately delete the infringing content.

You May Also Like