Introduction: Here is how to build a lamp environment under CentOS (all using source code compilation installation), for Web server development.
Lamp:linux + Apache + PHP + Mysql.
• System: CentOS 6.5, 32-bit.
CentOS installation
I chose the 32-bit CentOS 6.5 Linux system, the installation process is very simple, no longer too much to describe, just a little bit about my partition situation:
Partition name Size
/boot 200MB
/swap 2GB (not larger than physical partition)
/20GB
/Home remaining space
Apache Compiling the installation
I chose this version of HTTPd 2.2 and can refer to the official documentation.
Installation dependencies:
Install the GCC, g++ compiler that depends on the need:
####### #gcc, g++
sudo yum install gcc
sudo yum install gcc-c++ the following two are Apache optimizer tools:
####### #apr
wget http://labfile.oss.aliyuncs.com/apr-1.5.1.tar.gz
TAR-ZXVF apr-1.5.1.tar.gz
CD APR-1.5.1/
./configure--PREFIX=/OPT/APR
Sudo make && make install
####### #apr-util
CD downloads/
wget http://labfile.oss.aliyuncs.com/apr-util-1.5.4.tar.gz
TAR-ZXVF apr-util-1.5.4.tar.gz
CD apr-util-1.5.4
./configure--prefix=/opt/apr-util--WITH-APR=/OPT/APR
sudo make && make install
Perl libraries, compatible with regular expression libraries:
CD downloads/
wget http://labfile.oss.aliyuncs.com/pcre-8.36.tar.gz
TAR-ZXVF pcre-8.36.tar.gz
CD pcre-8.36
./configure--prefix=/opt/pcre
sudo make && make install
Installing Apache :
CD downloads/
wget http://labfile.oss.aliyuncs.com/httpd-2.2.29.tar.gz
TAR-ZXVF httpd-2.2.29.tar.gz
CD httpd-2.2.29
./configure--prefix=/opt/apache--with-apr=/opt/apr--with-apr-util=/opt/apr-util--with-pcre=/opt/pcre
sudo make && make install
sudo sed-i ' s/^ #ServerName. */servername localhost/'/opt/apache/conf/httpd.conf
Test:
Start:
Sudo/opt/apache/bin/apachectl start Gets the server response (the last step of installing Apache has set the server to localhost):
Curl-i 127.0.0.1 If the installation is successful, the following:
Shut down:
Sudo/opt/apache/bin/apachectl stop
MySQL Compiling the installation
Installation dependencies:
Note: The version after MySQL5.5 is compiled with CMake.
####### #若先前编译过, you need to delete the CMakeCache.txt file that you just compiled
Rm-f CMakeCache.txt
sudo yum-y install gcc gcc-c++ autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* cmake C Make-gui Libaio-devel Bison-devel Make
Compile the installation (longer):
Cd downloads/
Wget http://labfile.oss.aliyuncs.com/mysql-5.6.24.tar.gz
TAR-ZXVF mysql-5.6.24.tar.gz
CD mysql-5.6.24
Cmake-dcmake_install_prefix=/opt/mysql-dmysql_datadir=/opt/mysql/data-dwith_innobase_storage_engine=1
sudo make
sudo make install
To create a MySQL user:
ID mysql >/dev/null 2>&1 | | sudo useradd-r-s/sbin/nologin-m-d/opt/mysql/data MySQL
Initialize Data directory:
sudo chown-r mysql:mysql/opt/mysql/data
sudo/opt/mysql/scripts/mysql_install_db--basedir=/opt/mysql--datadir=/opt/mysql/data--user=mysql-- Defaults-file=/opt/mysql/support-files/my-default.cnf
To modify a configuration file:
sudo sh-c ' cat >>/opt/mysql/my.cnf <<eof
Basedir =/opt/mysql
DataDir =/opt/mysql/data
Log-error =/opt/mysql/data/error.log
Pid-file =/opt/mysql/data/mysql.pid
Port = 3306
EOF '
Purge Residual files:
sudo sh-c ' for file in/etc/mysql/my.cnf/etc/my.cnf; Do [-f $file] && rm-f $file; Done
Start:
Sudo/opt/mysql/support-files/mysql.server start
The success shows:
Test:
/opt/mysql/bin/mysqladmin Ping
The success shows:
To view the database:
/opt/mysql/bin/mysql-u root-e ' show databases; '
Shut down:
Sudo/opt/mysql/support-files/mysql.server stop
The success shows:
PHP Compiling the installation
Installation dependencies:
CD downloads/
sudo yum install zlib1g-dev libbz2-dev libcurl4-gnutls-dev libjpeg-dev libpng12-dev libfreetype6-dev libmcrypt-dev libx Ml2-dev
sudo yum install bzip2-devel-y
sudo yum-y install Curl-devel
sudo yum install OpenSSL openssl-devel-y
sudo yum install libjpeg libpng freetype libjpeg-devel libpng-devel freetype-devel-y
sudo yum install libjpeg libjpeg-devel libpng libpng-devel
* All above not necessarily installed
####### #安装Libmcrypt
TAR-ZXVF libmcrypt-2.5.8.tar.gz
CD libmcrypt-2.5.8
./configure
sudo make
sudo make install
Description: Libmcript is installed by default on/usr/local
####### #安装mhash
Cd..
TAR-ZXVF mhash-0.9.9.9.tar.gz
CD mhash-0.9.9.9
./configure
sudo make
sudo make install
######## #安装mcrypt
Cd..
TAR-ZXVF mcrypt-2.6.8.tar.gz
CD mcrypt-2.6.8
Ld_library_path=/usr/local/lib./configure
sudo make
sudo make install
Compile and install:
CD downloads/
wget http://labfile.oss.aliyuncs.com/php-5.5.21.tar.gz
TAR-ZXVF php-5.5.21.tar.gz
CD php-5.5.21
./configure--prefix=/opt/php--with-bz2--with-curl--with-jpeg-dir--with-gd--enable-shared--enable-mbstring-- With-mcrypt--with-mysql=/opt/mysql--with-pdo-mysql=/opt/mysql--with-mysqli=/opt/mysql/bin/mysql_config-- ENABLE-FPM--enable-phar--enable-bcmath--with-zlib--enable-zip--enable-ftp--with-gettext--enable-sockets-- With-freetype-dir--with-config-file-path=/opt/php/etc/php.ini--WITH-CONFIG-FILE-SCAN-DIR=/OPT/PHP/ETC/CONF.D-- With-apxs2=/opt/apache/bin/apxs
sudo make
sudo make install
sudo cp Php.ini-production/opt/php/etc/php.ini
* The error contains MySQL, that is because Mysql-devel is not installed. Workaround: Yum Install Mysql-devel
Check if PHP supports MySQL:
/opt/php/bin/php-m | grep MySQL
If support is displayed:
Modify the Apache configuration file to add support configuration for PHP:
sudo sh-c ' cat >>/opt/apache/conf/httpd.conf <<eof
<ifmodule mime_module>
AddType application/x-httpd-php. php
</IfModule>
EOF '
If off, Apache is turned on, otherwise Apache will be restarted:
Sudo/opt/apache/bin/apachectl-k Restart Test:
sudo sh-c ' echo ' <?php echo phpinfo ()?> ">/opt/apache/htdocs/test.php"
In the browser input:
http://localhost/test.php
A successful configuration displays the PHP information:
* Follow the steps above and note that the location of the php.ini file should be/opt/php/etc/php.ini/php.ini. Illinois.
Build lamp Environment under CentOS