(1) Install yum1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16[root@delphi ~\]# cd /etc/yum.repos.d/
[root@delphi yum.repos.d\]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
[root@delphi yum.repos.d\]# vi CentOS-Media.repo
# CentOS-Media.repo
#
# This repo can be used with mounted DVD media, verify the mount point for
# CentOS-6. You can use this repo and yum to install items directly off the
# DVD ISO that we release.
#
# To use this repo, put in your DVD and use it with the other repos too:
# yum --enablerepo=c6-media \[command\]
#
# or for ONLY the media repo, do this:
#
# yum --disablerepo=\\* --enablerepo=c6-media \[command\]
[c6-media]
name=CentOS-$releasever - Media
baseurl=file:///mnt/cdrom/ #specifies the three paths where the disc may possibly be mounted.
file:///media/cdrom/
file:///media/cdrecorder/
gpgcheck=1
enabled=1 #enabled=0 here 0 means the default source does not exist, 1 means enabled.
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
# wq to save and quit.
If your linux can get on the Internet, then back up this Base configuration file.
[root@delphi yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak
(2) Make sure gcc gcc-c++ make are installed on your machine; if not, install them first
[root@delphi ~]# yum install gcc -y
[root@delphi ~]# yum install gcc-c++ -y
(3) Uninstall the apache php mysql rpm packages. My system didn't have them installed. There are many ways to do it; I won't list them all. Check whether the services are running:
[root@delphi ~]# service httpd status
httpd: unrecognized service
[root@delphi ~]# service mysqld status
mysqld: unrecognized service
[root@delphi ~]# rpm -qa httpd
[root@delphi ~]# rpm -qa mysql
[root@delphi ~]# rpm -qa mysqld
[root@delphi ~]# rpm -qa | grep php
If your system has these packages, then rpm -e packagename or yum remove packagename (which resolves the dependency on removal). (4) Turn off SElinux and allow the relevant iptables ports 1. Two ways to turn off selinux. —Permanent shutdown. (requires a system reboot)
[root@delphi ~]# vi /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled # change SELINUX=enforcing to SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
- Temporary shutdown (no system reboot needed)
[root@delphi ~]# setenforce 0
(5) Prepare all the source code packages that need to be installed for the source deployment
download with linux commands
wget https://sourceforge.net/projects/erik1314/files/lanmp/autoconf-2.69.tar.gz
wget https://sourceforge.net/projects/erik1314/files/lanmp/freetype-2.4.10.tar.gz
wget https://sourceforge.net/projects/erik1314/files/lanmp/gd-2.0.35.tar.gz
wget https://sourceforge.net/projects/erik1314/files/lanmp/httpd-2.2.27.tar.gz
wget https://sourceforge.net/projects/erik1314/files/lanmp/jpegsrc.v8b.tar.gz
wget https://sourceforge.net/projects/erik1314/files/lanmp/libmcrypt-2.5.8.tar.gz
wget https://sourceforge.net/projects/erik1314/files/lanmp/libpng-1.5.14.tar.gz
wget https://sourceforge.net/projects/erik1314/files/lanmp/libxml2-2.9.0.tar.gz
wget https://sourceforge.net/projects/erik1314/files/lanmp/mysql-5.1.42.tar.gz
wget https://sourceforge.net/projects/erik1314/files/lanmp/ncurses-5.6.tar.gz
wget hhttps://sourceforge.net/projects/erik1314/files/lanmp/phpMyAdmin-3.5.6-all-languages.tar.gz
wget https://sourceforge.net/projects/erik1314/files/lanmp/zlib-1.2.7.tar.gz
wget https://sourceforge.net/projects/erik1314/files/lanmp/php-5.2.17.tar.gz (choose the version according to your website’s situation)
wget https://sourceforge.net/projects/erik1314/files/lanmp/php-5.3.29.tar.gz
wget https://sourceforge.net/projects/erik1314/files/lanmp/php-5.4.11.tar.gz
wget https://sourceforge.net/projects/erik1314/files/lanmp/php-5.4.33.tar.gz
wget https://sourceforge.net/projects/erik1314/files/lanmp/php-5.5.17.tar.gz
wget https://sourceforge.net/projects/erik1314/files/lanmp/php-5.6.1.tar.gz
php 5.3 and above does not support zendoptimizer; use ZendGuard instead
wget https://sourceforge.net/projects/erik1314/files/lanmp/ZendGuard-5\_5\_0.tar.gz
On Windows, download them directly and then upload them to the server with ftp autoconf-2.69.tar.gz freetype-2.4.10.tar.gz gd-2.0.35.tar.gz httpd-2.2.27.tar.gz jpegsrc.v8b.tar.gz libmcrypt-2.5.8.tar.gz libpng-1.5.14.tar.gz libxml2-2.9.0.tar.gz mysql-5.1.42.tar.gz ncurses-5.6.tar.gz phpMyAdmin-3.5.6-all-languages.tar.gz zlib-1.2.7.tar.gz php-5.2.17.tar.gz php-5.3.29.tar.gz php-5.4.11.tar.gz php-5.4.33.tar.gz php-5.5.17.tar.gz php-5.6.1.tar.gz ZendOptimizer-3.3.3-linux-glibc23-x86_64.tar.gz ZendGuard-5_5_0.tar.gz Then extract the files one by one
(6) Start building the lamp environment. Installation is three steps: configure —- make —- make install. configure checks the system configuration and checks the software needed to install the software. make compiles the binary files into executable files. make install installs the software. 1. Compile and install xml2
[root@delphi lamp]#cd libxml2-2.6.30
[root@delphi libxml2-2.6.30]# ./configure —prefix=/usr/local/libxml2/
[root@delphi libxml2-2.6.30]# make && make install
- Install libmcrpyt the same way
[root@delphi lamp]# cd libmcrypt-2.5.8
[root@delphi libmcrypt-2.5.8]# ./configure —prefix=/usr/local/libmcrypt/
[root@delphi libmcrypt-2.5.8]# make && make install
- Compile and install zlib (zlib is a library file; to prevent errors later on, no path is specified here. If you are on a 64-bit system, please install it as described in the libpng troubleshooting section.)
[root@delphi lamp]# cd zlib-1.2.3
[root@delphi zlib-1.2.3]# ./configure
[root@delphi zlib-1.2.3]# make && make install
Compile and install libpng: if the following error appears, it is because your environment is a 64-bit system and cannot match the zlib library. /usr/local/lib/libz.a: could not read symbols: Bad value collect2: ld returned 1 exit status make[1]: [libpng12.la] Error 1 make[1]: Leaving directory `/root/packget/libpng-1.2.31’ make: [all] Error 2 Solution: reinstall zlib tar -zxvf zlib-1.2.3.tar.gz cd zlib-1.2.3 ./configure vi Makefile find CFLAGS=-O3 -DUSE_MMAP and add -fPIC after it, so it becomes CFLAGS=-O3 -DUSE_MMAP -fPIC then follow the steps below make make install 4. Compile and install libpng
[root@delphi lamp]# cd libpng-1.2.31
[root@delphi libpng-1.2.31]# ./configure -prefix=/usr/local/libpng/
[root@delphi libpng-1.2.31]# make && make install
- Install jpeg6. Installing this source package is a bit more complicated, because it does not automatically create the corresponding directories, so first we create the directories by hand /usr/local/jpeg6/ #create the install directory /usr/local/jpeg6/bin/ #create the executable directory /usr/local/jpeg6/lib/ #create the directory for storing library files /usr/local/jpeg6/include #create the header file storage directory /usr/local/jpeg6/man/man1 #create command help in the man manual; man1 means command help and man5 means help for configuration files.
[root@delphi lamp]# cd jpeg-6b/
[root@delphi jpeg-6b]# mkdir /usr/local/jpeg6/ && mkdir /usr/local/jpeg6/bin/ && mkdir /usr/local/jpeg6/lib/ && mkdir /usr/local/jpeg6/include
[root@delphi jpeg-6b]# mkdir -p /usr/local/jpeg6/man/man1
[root@delphi jpeg-6b]# ./configure —prefix=/usr/local/jpeg6/ —enable-shared —enable-static
[root@delphi jpeg-6b]# make && make install
************************************************************************* ./libtool —mode=compile gcc -O2 -I. -c ./jcapimin.c make: ./libtool: command not found make: [jcapimin.lo] Error 127 Solution for the error above: [root@delphi jpeg-6b]# cp /usr/share/libtool/config/config.sub /root/packget/jpeg-6b/ [root@delphi jpeg-6b]# cp /usr/share/libtool/config/config.guess /root/packget/jpeg-6b/ Then: [root@delphi jpeg-6b]# make clean Then run: [root@delphi jpeg-6b]# make [root@delphi jpeg-6b]# make install * 6. Compile and install freetype
[root@delphi lamp]# cd freetype-2.3.5
[root@delphi freetype-2.3.5]# ./configure —prefix=/usr/local/freetype/
[root@delphi freetype-2.3.5]# make && make install
- Compile and install autoconf
[root@delphi lamp]# cd autoconf-2.61
[root@delphi autoconf-2.61]# ./configure
[root@delphi autoconf-2.61]# make && make install
- Compile and install the gd library:
[root@delphi lamp]# cd gd-2.0.35
[root@delphi gd-2.0.35]# ./configure —prefix=/usr/local/gd2/ —with-jpeg=/usr/local/jpeg6/ —with-freetype=/usr/local/freetype/
note: if your zlib library uses a specified path, then you can use —with-zlib=/$PATH
[root@delphi gd-2.0.35]# make && make install
- Compile and install apache:
[root@delphi lamp]# cd httpd-2.2.9
[root@delphi httpd-2.2.9]# ./configure —prefix=/usr/local/apache2/ —sysconfdir=/etc/httpd/ —with-included-apr —disable-userdir —enable-so —enable-deflate=shared —enable-expires=shared —enable-rewrite=shared —enable-static-support
[root@delphi httpd-2.2.9]# make && make install
[root@delphi httpd-2.2.9]# /usr/local/apache2/bin/apachectl start
[root@delphi httpd-2.2.9]# pgrep httpd
27652
27653
27654
27655
27656
27657
If you have not disabled selinux, then use the following command to grant permission to the module: [root@delphi ~]# chcon -t texrel_shlib_t modulename Access the server through a browser; if it returns It‘s works ! that means the installation succeeded. 10. Before compiling and installing mysql you need to compile and install nourses:
[root@delphi lamp]# cd ncurses-5.6
[root@delphi ncurses-5.6]# ./configure —with-shared —without-debug —without-ada —enable-overwrite
[root@delphi ncurses-5.6]# make && make install
- Compile and install mysql: First create the mysql user and user group:
[root@delphi lamp]# cd mysql-5.0.41
[root@delphi mysql-5.0.41]# groupadd mysql
[root@delphi mysql-5.0.41]# grep mysql /etc/group
mysql:x:501:
[root@delphi mysql-5.0.41]# useradd -g mysql mysql
[root@delphi mysql-5.0.41]# ./configure —prefix=/usr/local/mysql —with-extra-charsets=all
[root@delphi mysql-5.0.41]# make && make instal
If make reports an error, use
make ZEND_EXTRA_LIBS=’-liconv’ && make install
Configure mysql: copy my-medium.cnf from the source package into /etc/ and name it my.cnf
[root@delphi mysql-5.0.41]# cp support-files/my-medium.cnf /etc/my.cnf
Initialize the user grant tables:
[root@delphi mysql-5.0.41]# /usr/local/mysql/bin/mysql_install_db —user=mysql
Change the directory permissions:
[root@delphi mysql-5.0.41]# chown -R root /usr/local/mysql #change the user that owns mysql
[root@delphi mysql-5.0.41]# chown -R mysql /usr/local/mysql/var #change the user that owns the var directory under mysql
[root@delphi mysql-5.0.41]# chgrp -R mysql /usr/local/mysql #change the group that owns mysql; the -R here means the permission is inherited by subdirectories
Start: mysql
[root@delphi mysql-5.0.41]# /usr/local/mysql/bin/mysqld_safe —user=mysql &
[1] 25856
[root@delphi mysql-5.0.41]# nohup: ignoring input and redirecting stderr to stdout
Starting mysqld daemon with databases from /usr/local/mysql/var #indicates the data storage path. Just press enter.
Check whether mysql has started:
[root@delphi mysql-5.0.41]# pgrep mysql
Check the mysql version:
[root@delphi mysql-5.0.41]# /usr/local/mysql/bin/mysqladmin version
Check mysql configuration parameters:
[root@delphi mysql-5.0.41]# /usr/local/mysql/bin/mysqladmin variables
Set the mysql user password:
[root@delphi mysql-5.0.41]# /usr/local/mysql/bin/mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.0.41-log Source distribution
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql> set password for ‘root’@’localhost’=PASSWORD(‘123456’);
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
Add apache and mysql to the startup items
[root@delphi mysql-5.0.41]# echo “/usr/local/apache2/bin/apachectl start” >>/etc/rc.d/rc.local
[root@delphi mysql-5.0.41]# echo “/usr/local/mysql/bin/mysqld_safe —user=mysql &” >> /etc/rc.d/rc.local
Or:
[root@delphi ~]# cd lamp/mysql-5.0.41
[root@delphi mysql-5.0.41]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@delphi mysql-5.0.41]# chown root.root /etc/rc.d/init.d/mysqld
[root@delphi mysql-5.0.41]# chmod 755 /etc/rc.d/init.d/mysqld
[root@delphi mysql-5.0.41]# chkconfig —add mysqld
[root@delphi mysql-5.0.41]# chkconfig —list mysqld
mysqld 0:off1:off2:on3:on4:on5:on6:off
[root@delphi mysql-5.0.41]# chkconfig —levels 245 mysqld off #the way to set the startup item for a run level.
[root@delphi mysql-5.0.41]# chkconfig —list mysqld
mysqld 0:off1:off2:off3:on4:off5:off6:off
[root@delphi mysql-5.0.41]# chkconfig —levels 245 mysqld on #change back to the original run level
- Install php:
[root@delphi lamp]# cd php-5.2.6
[root@delphi php-5.2.6]# ./configure —prefix=/usr/local/php/ —with-config-file-path=/usr/local/php/etc —with-apxs2=/usr/local/apache/bin/apxs —with-mysql=/usr/local/mysql/ —with-libxml-dir=/usr/local/libxml2/ —with-jpeg-dir=/usr/local/jpeg8/ —with-freetype-dir=/usr/local/freetype/ —with-gd —with-mcrypt=/usr/local/libmcrypt/ —with-mysqli=/usr/local/mysql/bin/mysql_config –with-curl=/usr/local/curl
—with-zlib-dir=/usr/local/zlib/ —with-png-dir=/usr/local/libpng/ —with-mysql —enable-soap —enable-mbstring=all—enable-sockets
Or
generate curl directly so you don’t have to recompile it later
./configure —prefix=/usr/local/php/ —with-apxs2=/usr/local/apache/bin/apxs —with-curl=/usr/local/curl/bin —with-libxml-dir=/usr/local/libxml2/ —with-jpeg-dir=/usr/local/jpeg/ —with-freetype-dir=/usr/local/freetype/—with-gd-dir=/usr/local/gd/—with-zlib-dir=/usr/local/zlib/—with-mcrypt=/usr/local/libmcrypt/—with-mysqli=/usr/local/mysql/bin/mysql_config —enable-soap —enable-mbstring=all —enable-sockets
[root@delphi php-5.2.6]# make && make install
make install throws an error here; the original author didn’t give me an answer
An error like the following
/opt/php-5.2.17/ext/dom/node.c -o ext/dom/node.lo
/opt/php-5.2.17/ext/dom/node.c: In function â€کdom_canonicalization’:
/opt/php-5.2.17/ext/dom/node.c:1953: error: dereferencing pointer to incomplete type
/opt/php-5.2.17/ext/dom/node.c:1955: error: dereferencing pointer to incomplete type
make: * [ext/dom/node.lo] Error 1
You can use
# curl -o php-5.2.17.patch https://mail.gnome.org/archives/xml/2012-August/txtbgxGXAvz4N.txt
cd php-5.2.17
# patch -p0 -b < ./php-5.2.17.patch
patching file ext/dom/node.c
patching file
ext/dom/documenttype.c
patching file ext/simplexml/simplexml.c
Then recompile and install; remember to run make clean first
If you get
make: * [sapi/cli/php] Error 1
When running make, change it to make ZEND_EXTRA_LIBS=’-liconv’ && make install
[root@delphi php-5.2.6]# cp php.ini-dist /usr/local/php/etc/php.ini[root@delphi php-5.2.6]# echo “Addtype application/x-httpd-php .php .phtml” >> /etc/httpd/httpd.conf[root@delphi php-5.2.6]# /usr/local/apache2/bin/apachectl restart
cp php.ini-dist /usr/local/php/etc/php.ini
vi /usr/local/apache/conf/httpd.conf
After AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
add Addtype application/x-httpd-php .php .phtml
Addtype application/x-httpd-php-source .phps
- Install the Zend accelerator
[root@delphi lamp]# cd ZendOptimizer-3.2.6-linux-glibc21-i386
[root@delphi ZendOptimizer-3.2.6-linux-glibc21-i386]# ./install.sh
During installation, select the correct directory where the php.ini file lives and the directory where the apache control command lives 14. Install phpmyadmin to make managing the mysql database easier
[root@delphi lamp]# mv phpMyAdmin-3.0.0-rc1-all-languages /usr/local/apache2/htdocs/phpmyadmin
I ran into a great many problems when compiling php, and found the answers step by step by searching on Baidu; a freshly configured centos is not complete.

