Compile and Install LAMP(Linux/Apache/MySQL/PHP) from source on Ubuntu 12.10

This blog will guide you finish the compiling and installing a LAMP Server from source on Ubuntu step by step.

Of course, it will take you a little much time(Thanks for the 15 source packages ) ,so a cup of coffee will be a good choice 🙂

Zeroth. Here follows some source packages, which will be used when we build the LAMP.Some of them are the newest, others not.

1. httpd-2.4.4

2. mysql-5.6.10

3. php.5.3.22

4. libxml2-2.6.30

5. libmcrypt-2.5.8

6. zlib-1.2.7

7. gd-2.0.35

8. autoconf-2.61

9. freetype-2.3.5

10. libpng-1.6.0

11. jpeg-6b

12. apr-1.4.6

13. apr-util-1.4.1

14. pcre-8.32

15. libtool-2.2.6

First. check the basic system info

1. $ uname -a:
Selection_103

2. check whether there is gcc or not
$ gcc -v
Selection_104
Whoops!!!There is not,but never mind ,just install it.
$ sudo apt-get install gcc

Now, we can begin to build all the source packages:)

Second. Compile and install the source packages

2.1 install the newest libxml2 library files
2.1.1 download the libxml2-2.6.30.tar.gz from the link above or the official site, and put it into the directory /usr/local/src/, then extract it to directory  libxml2-2.6.30/ and then get into that derectory. Command lines as follow:
$ cd /usr/local/usr/                                      // enter the directory which the source package lays
$ sudo tar zxvf libxml2-2.6.30.tar.gz         // extract it
$ cd libxml2-2.6.30/                                    // enter the directory

2.1.2 use command “configure” to check and configure the system environment and generate the configured files. Command lines as follow:
$ ./configure –prefix=/usr/local/libxml2
the option –prefix=/usr/local/libxml2 here is to tell the installer to install it to directory /usr/local/libxml2 .When it finished, there will be a tips “Done configuring”, as the pic shows below.
Selection_106

2.1.3 use  command “make” to compile and generate install files
$ sudo make                                                          // compile
Here comes a error:
In function ‘open’,inlined from ‘xmlNanoHTTPSave__internal_alias’ at nanohttp.c:1588:12:

/usr/include/x86_64-linux-gnu/bits/fcntl2.h:51:24: error: call to ‘__open_missing_mode’ declared with attribute error: open with O_CREAT in second argument needs 3 arguments

solution:
open and edit the nanohttp.c which is  on the current directory,see the 1588th line, and modify
fd = open(filename, O_CREAT | O_WRONLY);                   to
fd = open(filename, O_CREAT | O_WRONLY,0777);
as the pic shows below.
Selection_108

2.14 use command”make install” to install the software.Command lines as follow:
$ sudo make install                                               // install
if installed success, there will be 5 subdirectories bin, include ,lib, man and share under /usr/local/libxml2/, as the pic shows below.
Selection_109
*when we install php5 later, we’ll add “–with-libxml-dir=/usr/local/libxml2” to the configure options to  specify the location of  libxml2 library files.

2.2 install the newest libmcrypt library files
2.2.1 download the libmcrypt-2.5.8.tar.gz from the link above or the official site, and put it into the directory /usr/local/src/, then extract it to directory libxml2-2.6.30/ and then get into that derectory. Command lines as follow:
$ cd /usr/local/usr/                                      // enter the directory which the source package lays
$ sudo tar libmcrypt-2.5.8.tar.gz                // extract it
$ cd libxml2-2.6.30/                                    // enter the directory

2.2.2 use command “configure” to check and configure the system environment and generate the configured files. Command lines as follow:
$ ./configure –prefix=/usr/local/libmcrypt
the option –prefix=/usr/local/libmcrypt here is to tell the installer to install it to directory /usr/local/libmcrypt.
Here will use the g++ complier, and if there is not a g++, you should first do the sudo apt-get install g++ first.

2.2.3 use  command “make” to compile and generate install files
$ sudo make                                                          // compile

2.2.4 use command”make install” to install the software.Command lines as follow:
$ sudo make install                                              // install
if installed success, there will be 5 subdirectories bin, include ,lib, man and share under /usr/local/libmcrypt/, as the pic shows below.
Selection_110
*when we install php5 later, we’ll add “–with-mcrypt-dir=/usr/local/libmcrypt” to the configure options to  specify the location of  libmcrypt library files.

2.2.5 install the libltdl library files
when finished installing the libmcrypt, enter into the directory /usr/local/src/libmcrypt-2.5.8, and then enter the subdirectory libltdl. Follow the command lines below to finish the configure, compile and install:
$ cd /usr/local/src/libmcrypt-2.5.8/libltdl    // enter the directory which the source package lays
$ ./configure  –enable-ltdl-install                  // configure it
$ make                                                             // compile
$ make install                                                  // install
if installed success, there will be a header file ltdl.h under the directory /usr/local/include,as the pic show below.
Selection_112

2.3 install the newest zlib library files
2.3.1 download the zlib-1.2.7.tar.gz from the link above or the official site, and put it into the directory /usr/local/src/, then extract it to directory zlib-1.2.7/ and then get into that derectory. Command lines as follow:
$ cd /usr/local/usr/                                      // enter the directory which the source package lays
$ sudo tar zxvf zlib-1.2.7.tar.gz                  // extract it
$ cd zlib-1.2.7/                                             // enter the directory

2.3.2 use command “configure” to check and configure the system environment and generate the configured files. Command lines as follow:
$ ./configure
you’d better not use the option –prefix=/usr/local/zlib here, because it will lead to failing  to locate the zlib library when install libpng.

2.3.3 use  command “make” to compile and generate install files
$ sudo make                                                          // compile

2.3.4 use command”make install” to install the software.Command lines as follow:
$ sudo make install                                              // install
if installed success, there will be 3 subdirectories include ,lib and share under /usr/local/zlib/, as the pic shows below.
Selection_113*when we install php5 later, we’ll add “–with-zlib-dir=/usr/local/zlib” to the configure options to  specify the location of  zlib library files.

2.4 install the newest libpng library files

2.4.1 Download the file: libpng-1.6.0.tar.gz from the above link or the official site , put it under /usr/local/src/, and extract it to libpng-1.6.0/, then enter the directory using following command:

$ cd /usr/local/usr/                                      // enter the directory where the source code is
$ sudo tar zxvf libpng-1.6.0.tar.gz             // extract the file
$ cd libpng-1.6.0/                                        // enter the current directory

2.4.2 Check and configure the installation environment with “configure” command, which will generate installation configuration file.  The command line as follows:

$ ./configure –prefix=/usr/local/libpng

“–prefix=/usr/local/libpng” means that the installing software will be installed under /usr/local/libpng.

ERROR: configure: error: zlib not installed

Solution at this blog: http://keping.me/2013-3-12-2/ (see the English version… I don’t like this solution but it’s the only effective one I have ever found. 🙁 )

2.4.3 use the make command to compile the source file and generate the installation file:

$ make                                                          // compile

2.4.4 use command make install to install:

$ make install                                              // install

If the installation succeeded, there would be four directories(bin/, include/, lib/, share/)generated under /usr/local/libpng, as following picture:

* When installing the GD2 lib, it should add the option –with-png-dir=/usr/local/libpng behind configure command to locate the position of libpng file.

2.5 install the newest jpeg6 library files

2.5.1 Download the jpegsrc.v6b.tar.gz file from above link or the official site,  put it under /usr/local/src/, and extract it into  directory jpeg-6b/  and then enter the current directory jpeg-6b/. Commands as follows:

$ cd /usr/local/usr/                                      // enter the directory where the source file is
$ sudo tar zxvf jpegsrc.v6b.tar.gz              // extract the file
$ cd jpeg-6b/                                                // enter the current directory

2.5.2 We need to create the installation directory manually when installing the jpeg6 lib files before installing the GD2. The installation directory will not be created automatically. The command as follows:

$ sudo mkdir /usr/local/jpeg6                          // create a installation directory
$ sudo mkdir /usr/local/jpeg6/bin                   // create a directory saving commands
$ sudo mkdir /usr/local/jpeg6/lib                     // create a jpeg6 directory
$ sudo mkdir /usr/local/jpeg6/include              // create a directory saving header files
$ sudo mkdir -p /usr/local/jpeg6/man/man1   // create a directory saving manual

2.5.3 Check and configure the installation environment with “configure” command, which will generate installation configuration file.  The command line as follows: ( for displaying explicitly, use “\” to split the command for several lines):

$ sudo ./configure \
> –prefix=/usr/local/jpeg6/ \                // install the software into /usr/local/jpeg6
> –enable-shared \                                 // GUN’s libtool will be used when creating shared lib
> –enable-static                                       // GUN’s libtool will be used when creating static  lib

2.5.4 use the make command to compile the source file and generate the installation file:

$ make                                                          // compile

ERROR:

./libtool –mode=compile gcc -O2 -I. -c ./jcapimin.c
make: ./libtool: Command not found
make: *** [jcapimin.lo] Error 127

Solution:  http://keping.me/2013-4-12/ ( see the English version…:) )

2.5.5 use command make install to install:

$ make install                                              // install

* When installing the GD2 lib, it should add the option –with-jpeg-dir=/usr/local/jpeg6 behind configure command to locate the position of jpeg lib file.

So far, we have installed so many packages as following picture~~~Have a rest, please~~

2.6 install the newest freetype library files

2.6.1 Download the file freetype-2.3.5.tar.gz on the above link or the official site, put it under /usr/local/src/, and extract it into freetype-2.3.5/ and then enter the current directory. The commands as follows:

$ cd /usr/local/usr/                                      //  enter the directory where the source code is
$ sudo tar zxvf freetype-2.3.5.tar.gz          // extract the file
$ cd freetype-2.3.5/                                     // enter the current directory

2.6.2 Check and configure the installation environment with “configure” command, which will generate installation configuration file.  The command line as follows:

$ ./configure –prefix=/usr/local/freetype

“–prefix=/usr/local/freetype” means that the installing software will be installed under /usr/local/freetype.

2.6.3 use the make command to compile the source file and generate the installation file:
$make                                                      // compile

2.6.4 use command make install to install:
$ make install                                              // install

If the installation succeeded, there would be four directories(bin/, include/, lib/, share/)generated under /usr/local/freetype, as following picture:

* When installing the freetype lib, it should add the option –with-jpeg-dir=/usr/local/freetype behind configure command to locate the position of freetype lib file.

2.7 install the newest autoconf library files

2.7.1 Download the file autoconf-2.61.tar.gz on the above link or the official site, put it under /usr/local/src/, and extract it into autoconf-2.61/ and then enter the current directory. The commands as follows:

$ cd /usr/local/usr/            // enter the directory where the source code is
$ sudo tar zxvf autoconf-2.61.tar.gz          // extract the file
$ cd autoconf-2.61/                              // enter the current directory

2.7.2 Check and configure the installation environment with “configure” command, which will generate installation configuration file.  The command line as follows:
$ ./configure

ERROR: configure: error: GNU M4 1.4 is required

Solution: $ sudo apt-get install m4

2.7.3 use the make command to compile the source file and generate the installation file:
$make                                                      // compile

2.7.4 use command make install to install:
$ make install                                              // install

2.8 install the newest GD library files

2.8.1 Download the file gd-2.0.35.tar.gz on the above link or the official site, put it under /usr/local/src/, and extract it into gd-2.0.35/ and then enter the current directory. The commands as follows:

$ cd /usr/local/usr/            // enter the directory where the source code is
$ sudo tar zxvf gd-2.0.35.tar.gz          // extract the file
$ cd gd-2.0.35/                              // enter the current directory

2.8.2 Check and configure the installation environment with “configure” command, which will generate installation configuration file.  The command line as follows:

$ sudo ./configure \
> –prefix=/usr/local/gd2/ \                             // install the software into /usr/local/gd2
> –with-zlib=/usr/local/zlib/ \                         // locate zlib
> –with-jpeg=/usr/local/jpeg6/ \                    // locate jpeg6
> –with-png=/usr/local/libpng/ \                    // locate libpng
> –with-freetype=/usr/local/freetype/           // locate freetype 2.x font lib

2.8.3 use the make command to compile the source file and generate the installation file:
$make                                                      // compile

ERROR: gd_png.c:16:53: fatal error: png.h: No such file or directory

Solution: http://keping.me/2013-3-13/( see the English version 🙂 )

2.8.4 use command make install to install:
$ make install                                              // install

If the installation succeeded, there would be four directories(bin/, include/, lib/, share/)generated under /usr/local/gd2, as following picture:

* When installing the GD2 lib, it should add the option –with-jpeg-dir=/usr/local/gd2/ behind configure command to locate the position of GD lib file.

2.9 install the newest Apache server

2.9.1 Download the file httpd-2.4.4.tar.gz on the above link or the official site, put it under /usr/local/src/, and extract it into httpd-2.4.4/ and then enter the current directory. The commands as follows:

$ cd /usr/local/usr/            // enter the directory where the source code is
$ sudo tar zxvf  httpd-2.4.4.tar.gz          // extract the file
$ cd httpd-2.4.4/                              // enter the current directory

2.9.2 Check and configure the installation environment with “configure” command, which will generate installation configuration file.  The command line as follows: ( for displaying explicitly, use “\” to split the command for several lines):

$ sudo ./configure \
> –prefix=/usr/local/apache2 \                // specify the installation location of Apache
> –sysconfdir=/etc/httpd  \                             // specify the location saving configuration files of Apache server
> –with-z=/usr/local/zlib/ \                             // specify the location of zlib
> –with-included-apr  \                                    // using the copy of bundled APR / APR-Util
> –disable-userdir \                                          // requests mapped to user-specific directories
> –enable-so \                                                   // compiled as dynamic sharing object(DSO)
> –enable-deflate=shared \                             // reduce the support of transmission encoding
> –enable-expires=shared \                            // support the control of the header files expiration
> –enable-rewrite=shared \                            // url control based on rules
> –enable-static-support                                 // create a support of a statically linked version

ERROR: configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.

Solution: http://keping.me/2013-3-13-2/ (see the English version 🙂 )

2.9.3  use the make command to compile the source file and generate the installation file:
$make                                                      // compile

2.9.4 use command make install to install:
$ make install                                              // install

If the installation succeeded, there would be twelve directories(bin/, build/, cgi-bin/, error/, htdocs/, icons/, include/, lib/, logs/, man/, manual/, modules/)generated under /usr/local/apache2, as following picture:

2.9.5 Start Apache server using following command:

$ sudo /usr/local/apache2/bin/apachectl start

ERROR: AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1. Set the ‘ServerName’ directive globally to suppress this message

Solution: modify the file httpd.conf under the directory /etc/httpd( the location specified when installing Apache server), as following picture:

and use following command to modify the file:

$ sudo vim /etc/httpd/httpd.conf

find the location of ServerName, as following picture:

add a line “ServerName localhost” under the ServerName, as following picture:

Restart Apache server with following command:

sudo /usr/local/apache2/bin/apachectl restart

To check whether it started successfully, use the grep command:

$ ps -ef | grep httpd

If there are 4/5 lines output, it started successfully, as following picture:

Also, we can check it by entering “localhost” in the your browser. If succeeded, the following content will occur:

2.9.6 Run on startup

Each server software need to be configured to run on startup. About Apache, we just need to add the start command line of Apache server in the file “/etc/rc.local”. Command as follows:

$ sudo vim /etc/rc.local

2.10 install the Mysql

2.10.1 Download the file mysql-5.6.10.tar.gz on the above link or the official site, put it under /usr/local/src/, and extract it to mysql-5.6.10/, and enter the current directory. The commands as follows:
$ cd /usr/local/usr/            // enter the directory where the source code is
$ sudo tar zxvf  mysql-5.6.10.tar.gz         // extract the file
$ cd mysql-5.6.10/                              // enter the current directory

2.10.2 Install cmake. The mysql 5.5 doesn’t use “./configure” command to configure and change to cmake, so we should install cmake. Check if there is cmake in your system with command as follows:

$ cmake -version

If there is no output as the following picture

you should install it by yourself:

$ sudo apt-get install cmake

2.10.3 Add new user group:

$ sudo groupadd mysql

2.10.4 Add new user:

$ sudo useradd mysql -g mysql

2.10.5 Create a new directory of database execution file :

$ sudo mkdir -p /usr/local/mysql

2.10.6 Create a new directory of new data file

$ sudo mkdir -p /db/mysql/data

2.10.8 Modify the directory owners:

$ sudo chown -R mysql:mysql /usr/local/mysql
$ sudo chown -R mysql:mysql /db/mysql/data
$ sudo chown -R mysql:mysql /usr/local/mysql/.
$ sudo chown -R mysql:mysql /db/mysql/data/.

2.10.8 Configure with cmake:

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/db/mysql/data \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306

ERROR:CMake Error at cmake/readline.cmake:83 (MESSAGE):
Curses library not found. Please install appropriate package,

remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:126 (FIND_CURSES)
cmake/readline.cmake:193 (MYSQL_USE_BUNDLED_LIBEDIT)
CMakeLists.txt:325 (MYSQL_CHECK_READLINE)

Solution: according the prompt, install the missing package ncurses:

$ sudo apt-get install libncurses5-dev

adn then delete the cache files under current diretory:

$ sudo rm CMakeCache.txt

then reconfigure using cmake. Just copy commands above.

2.10.9 use the make command to compile the source file and generate the installation file:
$sudo make                                                      // compile

It shall take a long time to compile:

2.10.10 use command make install to install:
$ sudi make install                                              // install

2.10.11 copy the configuration file

$ sudo cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

2.10.12 enter the installation path:

$ cd /usr/local/mysql

2.10.13 run the configuration script;

$ sudo ./scripts/mysql_install_db –user=mysql –datadir=/db/mysql/data

2.10.14 copy the service start script:

$ sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

2.10.15 start MySQL:

$ sudo service mysql start

2.10.16 set  password for root:

$ sudo /usr/local/mysql/bin/mysqladmin -u root password 123456

2.10.17 run on startup:

$ sudo update-rc.d mysql defaults

2.10.18 set mysql as system command:

$ sudo ln -s /usr/local/mysql/bin/* /bin/

after that, just execute the following command:

$ mysql -u root -p

you can login to mysql

2.10.19 set access permission

During installing MySQL, the application mysql_install_db installed the MySQL database authorization table. This table defines the initial accounts and authorizations of MySQL, and all accounts have no passwords. These accounts are super user accounts, they can perform any operations. Root account’s initial has no password, so anyone an use the root account without password to connect to MySQL server and get all permissions, which means MySQL installation is unprotected. If you want to prevent client form connecting without password, you should specify a password for anonymous account or delete anonymous account and set a password for MySQL users. Start MySQL client  console with “mysql –u root” to connect to MySQL server, command as follows:

$ mysql -u root -p

use the password set above (123456) to login, and perform:

mysql> DELETE FROM mysql.user WHERE Host=’localhost’ AND User=”;
Query OK, 1 rows affected (0.08 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 1 rows affected (0.01 sec)

This means MySQL installed succeessfully~~

2.11 install the PHP

2.11.1 Download the file php-5.3.22.tar.gz on the above link or the official site, put it under /usr/local/src/, and extract it to php-5.3.22/, and enter the current directory. The commands as follows:
$ cd /usr/local/usr/            // enter the directory where the source code is
$ sudo tar zxvf  pcphp-5.3.22.tar.gz          // extract the file
$ cd php-5.3.22/                              // enter the current directory

2.11.2 Check and configure the installation environment with “configure” command, which will generate installation configuration file.  The command line as follows: ( for displaying explicitly, use “\” to split the command for several lines):

$ sudo ./configure \
> –prefix=/usr/local/php \                                                     // set the installation path for PHP5
> –with-config-file-path=/usr/local/php/etc \                     // specify the path saving PHP5 configuration files
> –with-apxs2=/usr/local/apache2/bin/apxs \                   // locate Apache2
> –with-mysql=/usr/local/mysql/ \                                      // specify the installation directory of PHP5
> –with-libxml-dir=/usr/local/libxml2/ \                             // locate libxml2
> –with-png-dir=/usr/local/libpng/ \                                   // locate libpng
> –with-jpeg-dir=/usr/local/jpeg6/ \                                    // locate jpeg
> –with-freetype-dir=/usr/local/freetype/ \                        // locate freetype
> –with-gd=/usr/local/gd2/ \                                                // locate gd
> –with-zlib-dir=/usr/local/zlib/ \                                         // locate zlib
> –with-mcrypt=/usr/local/libmcrypt/ \                              // locate libmcrypt
> –with-mysqli=/usr/local/mysql/bin/mysql_config \       // locate  MySQLi
> –enable-soap \                                                                    // enable SOAP
> –enable-mbstring=all \                                                       // enable multiple string
> –enable-sockets                                                                   // enable socket

2.11.3 use the make command to compile the source file and generate the installation file:
$make                                                      // compile
2.11.4 use command make install to install:
$ make install                                              // install
2.11.5 Create configuration file. Specify the location of configuration file by adding the option “–with-config-file-path=/usr/local/php/etc/” when using “configure” command to install the configuration. Copy the “php.ini- dist” file from the source directory to specified
directory “/usr/local/php/etc/” and change its name to “php.int”:

$ sudo cp php.ini-dist /usr/local/php/etc/php.ini      // create the configuration

2.11.6 Integrate Apache and PHP. Before compiling PHP, we add the option “–with-apxs2=/usr/local/apache2/bin/apxs” behind the configure command to make PHP as the Apache function. But we still need to modify Apache configuration file by adding PHP support to tell Apache certain extensions as PHP parse. For example, let Apache parse files with extensions like .php and .phtml to PHP. Open Apache configuration file /etc/httpd/httpd.conf, find the line “AddType application/x-gzip .gz .tgz” and under it add a command line “Addtype application/x-httpd- php .php .phtml”. Files with any extension can be parsed to PHP, as long as we add the type to the added command and separated with backspace, as following picture:

We add a line “AddType application/x-httpd-php-source .phps” in the end to take the file with .phps extensions as PHP source file for syntax highlighting.

2.11.7 Restart Apache server, for only after the restart changes of configuration file would take effect:

$ sudo /usr/local/apache2/bin/apachectl stop           // stop Apache service
$ sudo /usr/local/apache2/bin/apachectl start           // start Apache service

2.11.8 Test the PHP environment. Create a directory named phpinfo/ under /usr/local/apache2/htdocs and create a file named index.php. Add following lines to the file:

<?php
phpinfo();
?>

Open your browser enter the URL”http://localhost/phpinfo/index.php”, if the following picture occurs, it means your LAMP is successfully installed.

The function phpinfo() is to output most information about the PHP current status. It includes the information of compilation and extension, the PHP version, server information and environment, PHP environment, system information, path, local configuration value , HTTP header information and PHP License. Due to the different of each system’s installation, the  function phpinfo() can be used to check the configuration of a particular system and available predefined variable. It’s also a valuable debug tool, because it includes all EGPCS data(Environment,GET,POST,Cookie,Server).

large

ahaaaaaaaaaaaaaa~

Finally, we finished it

Sophia 译

Ubuntu搭建LAMP环境(jpeg-6b 安装错误 ,找不到libtool命令)

继续安装php开发环境,

jpeg-6b make的时候错误:

./libtool –mode=compile gcc -O2 -I. -c ./jcapimin.c
make: ./libtool: Command not found
make: *** [jcapimin.lo] Error 127

看提示应该是没有安装libtool,由于才拿到手里的服务器,什么都没装,出现这个错误也正常。

解决办法:安装libtool

1 在上面的链接或者网上下载 libtool-2.2.6a.tar.gz,放到/usr/local/src/目录下,解压软件包到当前目录libtool-2.2.6下,并进入libtool-2.2.6目录,命令如下:
$ cd /usr/local/usr/                                      // 进入源码包所在目录
$ sudo tar zxvf libtool-2.2.6a.tar.gz           // 解压缩
$ cd libtool-2.2.6                                         // 进入目录

2 使用“configure”命令检查并配置安装需要的系统环境,并生成安装配置文件,命令行如下:
$ ./configure
安装到默认路径就可以。

3 使用make命令编译源码文件并生成安装文件,命令如下:
$ sudo make                                                    // 编译

4 使用make install命令进行安装,命令如下:
$ sudo make install                                         // 安装

5 复制libtool中的config.sub和config.guess文件至jpeg-6b根目录,命令如下:
$ cd /usr/local/src/jpeg-6b/
$ sudo cp /usr/local/share/libtool/config/config.sub .
$ sudo cp /usr/local/share/libtool/config/config.guess .

6 重新配置并编译、安装jpeg-6b,命令如下:
$ sudo ./configure \
> –prefix=/usr/local/jpeg6/ \                             // 安装时将软件安装到/usr/local/jpeg6目录下
> –enable-shared \                                              // 建立共享库使用的GNU的libtool
> –enable-static                                                   // 建立静态库使用的GNU的libtool
$ sudo make                                                        // 编译
$ sudo make install                                             // 安装

7 Done.
————————————-华丽丽的分割线,下面是英语版———————–

English Version:

Continue to install the PHP environment.
An error occured when make jpeg-6b:

./libtool –mode=compile gcc -O2 -I. -c ./jcapimin.c
make: ./libtool: Command not found
make: *** [jcapimin.lo] Error 127

According the prompt, the libtool isn’t installed. It’s normal to have this error on a bare machine.

Solution: install libtool, of course!

1. Download the file libtool-2.2.6a.tar.gz on the above link or the official site, put it under /usr/local/src/, and extract it into libtool-2.2.6/ and then enter the current directory. The commands as follows:

$ cd /usr/local/usr/            // enter the directory where the source code is
$ sudo tar zxvf libtool-2.2.6a.tar.gz           // extract the file
$ cd libtool-2.2.6                              // enter the current directory

2. Check and configure the installation environment with “configure” command, which will generate installation configuration file.  The command line as follows:
$ ./configure
we can just install it in the default path.

3. use the make command to compile the source file and generate the installation file:
$make                                                      // compile

4. use command make install to install:
$ make install                                              // install

5. copy the config.sub and config.guess of libtool to jpeg-6b/, command as follows:
$ cd /usr/local/src/jpeg-6b/
$ sudo cp /usr/local/share/libtool/config/config.sub
$ sudo cp /usr/local/share/libtool/config/config.guess

6. reconfigure, compile and install jpeg-6b, commands as follows:
$ sudo ./configure \
> –prefix=/usr/local/jpeg6/ \                                   //install the software into /usr/local/jpeg6
> –enable-shared \                                       // GUN’s libtool will be used when creating shared lib
> –enable-static                                           // GUN’s libtool will be used when creating static  lib
$ sudo make                                                        // compile
$ sudo make install                                             // install

7. Done

Linux(Ubuntu12.10)搭建PHP开发环境(源码包方式)

哇哈哈哈哈,今天拿到了全新刀片服务器的权限!就在这机器上来配置吧!!!

这将是一篇很长很长的文章。需要安装的包实在太多了。

我将一点一点的写,尽量细化到每一步。所以完成这篇博客需要的时间可能会比较长。

But, just rock it!

OK.开题了。众所周知,在Linux下安装PHP有几种方法,但是最好的还是自己下载所有的源码包,然后编译一个适合自己的环境(当然,也就可以用最新的东西,只要不版本冲突)。LAMP组合中每个成员都是开源的软件,都可以从各自的官方网站上免费下载安装程序的源代码文件,并在自己的系统上编译,编译之前会检查系统的环境,并可以针对目标系统的环境进行优化,所以和自己系统的兼容性是最好的,不仅如此,允许你根据自己的需求进行定制安装。

这是LAMP环境最理想的搭建方法,也是最复杂的安装方式。所以要搭建一个最完美的LAMP工作环境,多花费一些时间和精力在源代码包的安装上,还是值得的。

零. 好了,现在列一下所需要的包,是我搭配环境的时候用到的。有些是最新的,有些不是。

(下载地址下次补齐,今天准备回去了。)

1. httpd-2.4.4

官网:http://httpd.apache.org/download.cgi#apache24

2. mysql-5.6.10

官网:http://downloads.mysql.com/archives.php?p=mysql-5.6&v=5.6.11

3. php.5.3.22

官网:http://www.php.net/downloads.php

4. libxml2-2.6.30

官网:ftp://xmlsoft.org/libxml2/

5. libmcrypt-2.5.8

官网:http://mcrypt.hellug.gr/lib/

6. zlib-1.2.7

官网:http://www.zlib.net/

7. gd-2.0.35

官网:https://bitbucket.org/libgd/gd-libgd/downloads

8. autoconf-2.61

官网:http://ftp.gnu.org/gnu/autoconf/

9. freetype-2.3.5

官网:http://sourceforge.net/projects/freetype/files/

10. libpng-1.6.0

官网:http://www.libpng.org/pub/png/libpng.html

11. jpeg-6b

官网:http://www.ijg.org/

12. apr-1.4.6

官网:http://apr.apache.org/download.cgi

13. apr-util-1.4.1

官网(同上,是一个地址):http://apr.apache.org/download.cgi

14. pcre-8.32

官网:http://www.pcre.org/

15. libtool-2.2.6

官网:http://ftp.gnu.org/gnu/libtool/libtool-2.4.2.tar.gz

一. 先检测一下基本的系统环境信息

1.$ uname -a
Selection_103

2. 看一下gcc装了没有
$ gcc -v
Selection_104

果然没有(当然没有啦!!新机器!!哇卡卡卡卡卡卡卡!!),
$ sudo apt-get install gcc

下面开始正式编译源码包并安装。

二. 编译各个源码包并安装

2.1 安装libxml2最新库文件
2.1.1 在上面的链接或者网上下载 libxml2-2.6.30.tar.gz,放到/usr/local/src/目录下,解压软件包到当前目录libxml2-2.6.30下,并进入libxml2-2.6.30目录,命令如下:
$ cd /usr/local/usr/                                      // 进入源码包所在目录
$ sudo tar zxvf libxml2-2.6.30.tar.gz         // 解压缩
$ cd libxml2-2.6.30/                                    // 进入目录

2.1.2 使用“configure”命令检查并配置安装需要的系统环境,并生成安装配置文件,命令行如下:
$ ./configure –prefix=/usr/local/libxml2
选项–prefix=/usr/local/libxml2作用,是在安装时将软件安装到/usr/local/libxml2目录下
执行成功后,会看见Done configuring的提示,如下图所示。
Selection_106

2.1.3 使用make命令编译源码文件并生成安装文件,命令如下:
$ make                                                          // 编译
出现错误:In function ‘open’,inlined from ‘xmlNanoHTTPSave__internal_alias’ at nanohttp.c:1588:12:
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:51:24: error: call to ‘__open_missing_mode’ declared with attribute error: open with O_CREAT in second argument needs 3 arguments
解决方法:http://keping.me/2013-3-12/

2.1.4 使用make install命令进行安装,命令如下:
$ make install                                              // 安装
如果安装成功以后,在/usr/local/libxml2/目录下将生成bin、include、lib、man和share五个目录。
Selection_109
*在后面安装PHP5源代码包的配置时,会通过在configure命令的选项中加上
“–with-libxml-dir=/usr/ local/libxml2“选项,用于指定安装libxml2库文件的位置

2.2 安装libmcrypt最新库文件
2.2.1 在上面的链接或者网上下载 libmcrypt-2.5.8.tar.gz,放到/usr/local/src/目录下,解压软件包到当前目录libxml2-2.6.30下,并进入libxml2-2.6.30目录,命令如下:
$ cd /usr/local/usr/                                      // 进入源码包所在目录
$ sudo tar zxvf libmcrypt-2.5.8.tar.gz        // 解压缩
$ cd libmcrypt-2.5.8                                     // 进入目录

2.2.2 使用“configure”命令检查并配置安装需要的系统环境,并生成安装配置文件,命令行如下:
$ ./configure –prefix=/usr/local/libmcrypt
选项–prefix=/usr/local/libmcrypt作用,是在安装时将软件安装到/usr/local/libmcrypt目录下
这里需要系统安装了g++,如果没有提前安装g++,那就先sudo apt-get install g++吧,我这新服务器就没有装。

2.2.3 使用make命令编译源码文件并生成安装文件,命令如下:
$ make                                                          // 编译

2.2.4 使用make install命令进行安装,命令如下:
$ make install                                              // 安装
如果安装成功就会在/usr/local/libmcrypt/目录下生成bin、include、lib、man和share五个目录。
Selection_110
*在后面安装PHP5源代码包的配置时,会通过在configure命令的选项中加上
“–with-mcrypt-dir=/usr/local/libmcrypt”选项,指定这个libmcrypt库文件的位置。

2.2.5 安装libltdl库。
安装完成libmcrypt库以后,进入到解压缩的目录/usr/local/src/ libmcrypt-2.5.8下,找到libltdl库源代码文件所在的目录libltdl,进入这个目录,按照下面几个命令配置、编译、安装就可以了。命令如下:
$ cd /usr/local/src/libmcrypt-2.5.8/libltdl         // 进入软件源代码目录
$ ./configure  –enable-ltdl-install                       // 配置ltdl库的安装
$ make                                                                  // 编译
$ make install                                                       // 安装
安装完成后,会在/usr/local/include/目录下发现 ltdl.h头文件,如下图所示。
Selection_112

2.3 安装zlib最新库文件
2.3.1 在上面的链接或者网上下载 zlib-1.2.7.tar.gz,放到/usr/local/src/目录下,解压软件包到当前目录zlib-1.2.7/下,并进入zlib-1.2.7目录,命令如下:
$ cd /usr/local/usr/                                      // 进入源码包所在目录
$ sudo tar zxvf zlib-1.2.7.tar.gz                  // 解压缩
$ cd zlib-1.2.7/                                             // 进入目录

2.3.2 使用“configure”命令检查并配置安装需要的系统环境,并生成安装配置文件,命令行如下:
$ ./configure –prefix=/usr/local/zlib
选项–prefix=/usr/local/zlib作用,是在安装时将软件安装到/usr/local/zlib目录下

2.3.3 使用make命令编译源码文件并生成安装文件,命令如下:
$ make                                                          // 编译

2.3.4 使用make install命令进行安装,命令如下:
$ make install                                              // 安装
如果安装成功就会在/usr/local/zlib/目录下生成include、lib和share三个目录。如下图
Selection_113
*在后面安装PHP5源代码包的配置时,会通过在configure命令的选项中加上
“–with-zlib-dir=/usr/local/zlib”选项,指定这个zlib库文件的位置。

2.4 安装libpng最新库文件
2.4.1 在上面的链接或者网上下载 libpng-1.6.0.tar.gz,放到/usr/local/src/目录下,解压软件包到当前目录libpng-1.6.0下,并进入libpng-1.6.0目录,命令如下:
$ cd /usr/local/usr/                                      // 进入源码包所在目录
$ sudo tar zxvf libpng-1.6.0.tar.gz             // 解压缩
$ cd libpng-1.6.0/                                        // 进入目录

2.4.2 使用“configure”命令检查并配置安装需要的系统环境,并生成安装配置文件,命令行如下:
$ ./configure –prefix=/usr/local/libpng
选项–prefix=/usr/local/libpng作用,是在安装时将软件安装到/usr/local/libpng目录下
出现错误:configure: error: zlib not installed
解决方法(我很讨厌这个方法其实,但研究几天未果):http://keping.me/2013-3-12-2/

2.4.3 使用make命令编译源码文件并生成安装文件,命令如下:
$ make                                                          // 编译

2.4.4 使用make install命令进行安装,命令如下:
$ make install                                              // 安装
如果安装成功就会在/usr/local/libpng目录下生成bin、include、lib和share四个目录。如下图
Selection_116
*在后面安装GD2库配置时,会通过在configure命令的选项中加上
“–with-png-dir=/usr/local/libpng”选项,指定这个libpng库文件的位置。

2.5 安装jpeg6最新库文件
2.5.1 在上面的链接或者网上下载 jpegsrc.v6b.tar.gz,放到/usr/local/src/目录下,解压软件包到当前目录jpeg-6b下,并进入jpeg-6b目录,命令如下:
$ cd /usr/local/usr/                                      // 进入源码包所在目录
$ sudo tar zxvf jpegsrc.v6b.tar.gz              // 解压缩
$ cd jpeg-6b/                                                // 进入目录

2.5.2 安装GD2库前所需的jpeg6库文件,需要自己手动地创建安装需要的目录,它们在安装时不能自动创建。命令行如下:
$ sudo mkdir /usr/local/jpeg6                                                           // 建立jpeg6软件安装目录
$ sudo mkdir /usr/local/jpeg6/bin                                                    // 建立存放命令的目录
$ sudo mkdir /usr/local/jpeg6/lib                                                     // 创建jpeg6库文件所在目录
$ sudo mkdir /usr/local/jpeg6/include                                             // 建立存放头文件目录
$ sudo mkdir -p /usr/local/jpeg6/man/man1                                  // 建立存放手册的目录

2.5.3 使用“configure”命令检查并配置安装需要的系统环境,并生成安装配置文件,命令行如下(为了直观,使用“\”将一个命令换成多行):
$ sudo ./configure \
> –prefix=/usr/local/jpeg6/ \                             // 安装时将软件安装到/usr/local/jpeg6目录下
> –enable-shared \                                              // 建立共享库使用的GNU的libtool
> –enable-static                                                   // 建立静态库使用的GNU的libtool

2.5.4 使用make命令编译源码文件并生成安装文件,命令如下:
$ make                                                          // 编译
出现错误:
./libtool –mode=compile gcc -O2 -I. -c ./jcapimin.c
make: ./libtool: Command not found
make: *** [jcapimin.lo] Error 127
解决方法:http://keping.me/2013-4-12/

2.5.5 使用make install命令进行安装,命令如下:
$ make install                                              // 安装
*在后面安装GD2库配置时,会通过在configure命令的选项中加上
“–with-jpeg-dir=/usr/local/jpeg6”选项,指定这个jpeg库文件的位置。
至此,我们已经使用了如下图所示的这么多的安装包~~休息一下先。
Selection_117

2.6 安装freetype最新库文件
2.6.1 在上面的链接或者网上下载 freetype-2.3.5.tar.gz,放到/usr/local/src/目录下,解压软件包到当前目录freetype-2.3.5下,并进入freetype-2.3.5目录,命令如下:
$ cd /usr/local/usr/                                      // 进入源码包所在目录
$ sudo tar zxvf freetype-2.3.5.tar.gz          // 解压缩
$ cd freetype-2.3.5/                                     // 进入目录

2.6.2 使用“configure”命令检查并配置安装需要的系统环境,并生成安装配置文件,命令行如下:
$ ./configure –prefix=/usr/local/freetype
选项–prefix=/usr/local/freetype作用,是在安装时将软件安装到/usr/local/freetype目录下

2.6.3 使用make命令编译源码文件并生成安装文件,命令如下:
$ make                                                          // 编译

2.6.4 使用make install命令进行安装,命令如下:
$ make install                                              // 安装
如果安装成功就会在/usr/local/freetype目录下生成bin、include、lib和share四个目录。如下图
Selection_118
*在后面安装GD2库配置时,会通过在configure命令的选项中加上
“–with-freetype-dir=/usr/local/freetype”选项,指定这个freetype库文件的位置。

2.7 安装autoconf最新库文件
2.7.1 在上面的链接或者网上下载 autoconf-2.61.tar.gz,放到/usr/local/src/目录下,解压软件包到当前目录autoconf-2.61下,并进入autoconf-2.61目录,命令如下:
$ cd /usr/local/usr/                                      // 进入源码包所在目录
$ sudo tar zxvf autoconf-2.61.tar.gz          // 解压缩
$ cd autoconf-2.61/                                     // 进入目录

2.7.2 使用“configure”命令检查并配置安装需要的系统环境,并生成安装配置文件,命令行如下:
$ ./configure
出现错误:configure: error: GNU M4 1.4 is required
解决方法:$ sudo apt-get install m4

2.7.3 使用make命令编译源码文件并生成安装文件,命令如下:
$ make                                                          // 编译

2.7.4 使用make install命令进行安装,命令如下:
$ make install                                              // 安装

2.8 安装GD最新库文件
2.8.1 在上面的链接或者网上下载 gd-2.0.35.tar.gz,放到/usr/local/src/目录下,解压软件包到当前目录gd-2.0.35下,并进入gd-2.0.35目录,命令如下:
$ cd /usr/local/usr/                                      // 进入源码包所在目录
$ sudo tar zxvf gd-2.0.35.tar.gz                 // 解压缩
$ cd gd-2.0.35/                                            // 进入目录

2.8.2 使用“configure”命令检查并配置安装需要的系统环境,并生成安装配置文件,命令行如下(为了直观,使用“\”将一个命令换成多行):
$ sudo ./configure \
> –prefix=/usr/local/gd2/ \                             // 安装时将软件安装到/usr/local/gd2目录下
> –with-zlib=/usr/local/zlib/ \                         // 指定到哪去找zlib库文件的位置
> –with-jpeg=/usr/local/jpeg6/ \                    // 指定到哪去找jpeg6库文件的位置
> –with-png=/usr/local/libpng/ \                    // 指定到哪去找libpng库文件的位置
> –with-freetype=/usr/local/freetype/           // 指定到哪去找freetype 2.x字体库的位置

2.8.3 使用make命令编译源码文件并生成安装文件,命令如下:
$ make                                                          // 编译
出现错误:gd_png.c:16:53: fatal error: png.h: No such file or directory
解决方法:http://keping.me/2013-3-13/

2.8.4 使用make install命令进行安装,命令如下:
$ make install                                              // 安装
如果安装成功就会在/usr/local/gd2目录下生成bin、include和lib三个目录。如下图
Selection_119
*在后面安装PHP5源代码包的配置时,会通过在configure命令的选项中加上
“–with-gd=/usr/ local/gd2/“选项,用于指定安装GD库文件的位置

2.9 安装新版本的Apache服务器
2.9.1 在上面的链接或者网上下载 httpd-2.4.4.tar.gz,放到/usr/local/src/目录下,解压软件包到当前目录 httpd-2.4.4下,并进入 httpd-2.4.4目录,命令如下:
$ cd /usr/local/usr/                                      // 进入源码包所在目录
$ sudo tar zxvf httpd-2.4.4.tar.gz               // 解压缩
$ cd  httpd-2.4.4/                                         // 进入目录

2.9.2 使用“configure”命令检查并配置安装需要的系统环境,并生成安装配置文件,命令行如下(为了直观,使用“\”将一个命令换成多行):
$ sudo ./configure \
> –prefix=/usr/local/apache2 \                       // 指定Apache软件安装的位置
> –sysconfdir=/etc/httpd  \                             // 指定Apache服务器的配置文件存放位置
> –with-z=/usr/local/zlib/ \                             // 指定zlib库文件的位置
> –with-included-apr  \                                    // 使用捆绑APR/APR-Util的副本
> –disable-userdir \                                          // 请求的映象到用户特定目录
> –enable-so \                                                   // 以动态共享对象(DSO)编译
> –enable-deflate=shared \                             // 缩小传输编码的支持
> –enable-expires=shared \                            // 支持头文件过期控制
> –enable-rewrite=shared \                            // 基于规则的URL操控
> –enable-static-support                                 // 建立一个静态链接版本的支持
出现错误:configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.
解决方法:http://keping.me/2013-3-13-2/

2.9.3 使用make命令编译源码文件并生成安装文件,命令如下:
$ make                                                          // 编译

2.9.4 使用make install命令进行安装,命令如下:
$ make install                                              // 安装
如果安装成功就会在/usr/local/apache2目录下生成bin、build、cgi-bin、error、htdocs、icons、include、lib、logs、man、manual和modules十二个目录,如下图。
Selection_121

2.9.5 启动Apache服务器,命令如下:
$ sudo /usr/local/apache2/bin/apachectl start
出现错误:AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1. Set the ‘ServerName’ directive globally to suppress this message
解决方法:修改httpd.conf配置文件,由于我们配置安装Apache服务器的时候,指定的配置文件放在了/etc/httpd目录下,如下图
Selection_122
我们需要去修改这个文件,命令如下:
$ sudo vim /etc/httpd/httpd.conf
找到ServerName所在的地方,如下图所示
Selection_123
在这下面添加一行ServerName localhost,如下图所示
Selection_124
重新启动Apache服务器即可,命令如下:
sudo /usr/local/apache2/bin/apachectl restart
通过查看进程的方式,查看是否启动成功,命令如下:
$ ps -ef | grep httpd
如果看到许多(一般是4到5个)输出就说明对了,如下图:
Selection_125
也可以通过在浏览器输入localhost,查看是否启动成功,如果成功,会有下图效果:
Selection_126

2.9.6 添加开机自启动
每种服务器软件都有必要制作成开机时自启动,Apache服务器开机自启动,只要在“/etc/rc.local”文件中,加上Apache服务器的启动命令即可,命令如下:
$ sudo vim /etc/rc.local
加上启动命令,如下图所示。
Selection_128

2.10 安装Mysql
2.10.1 在上面的链接或者网上下载 mysql-5.6.10.tar.gz,放到/usr/local/src/目录下,解压软件包到当前目录 mysql-5.6.10下,并进入 mysql-5.6.10目录,命令如下:
$ cd /usr/local/usr/                                         // 进入源码包所在目录
$ sudo tar zxvf mysql-5.6.10.tar.gz              // 解压缩
$ cd  mysql-5.6.10/                                        // 进入目录

2.10.2 安装cmake。由于mysql貌似从5.5已经不用./configure来配置了,换成了cmake,所以需要安装cmake,检测系统中是否有cmake,命令如下:
$ cmake -version
如果没看到类似下图的输出
Selection_129
则需要自己先安装一下,命令如下:
$ sudo apt-get install cmake

2.10.3 新增用户组,命令如下:
$ sudo groupadd mysql

2.10.4 新增用户,命令如下:
$ sudo useradd mysql -g mysql

2.10.5 新建数据库执行文件目录,命令如下:
$ sudo mkdir -p /usr/local/mysql

2.10.6 新建数据库数据文件目录,命令如下:
$ sudo mkdir -p /db/mysql/data

2.10.7 修改目录拥有者,命令如下:
$ sudo chown -R mysql:mysql /usr/local/mysql
$ sudo chown -R mysql:mysql /db/mysql/data
$ sudo chown -R mysql:mysql /usr/local/mysql/.
$ sudo chown -R mysql:mysql /db/mysql/data/.

2.10.8 使用cmake进行配置,命令如下:
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/db/mysql/data \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306

出现错误:CMake Error at cmake/readline.cmake:83 (MESSAGE):
Curses library not found. Please install appropriate package,

remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:126 (FIND_CURSES)
cmake/readline.cmake:193 (MYSQL_USE_BUNDLED_LIBEDIT)
CMakeLists.txt:325 (MYSQL_CHECK_READLINE)

解决办法:按照提示,既然少ncurses包,那就安装一下,命令如下:
$ sudo apt-get install libncurses5-dev
然后把当前目录下这个缓存文件删除,命令如下:
$ sudo rm CMakeCache.txt
然后,重新用cmake进行配置,复制上面的命令即可。

2.10.9 使用make命令编译源码文件并生成安装文件,命令如下:
$ make                                                          // 编译
可能会花比较长的时间编译
Selection_130

2.10.10 使用make install命令进行安装,命令如下:
$ make install                                              // 安装

2.10.11 复制配置文件,命令如下:
$ sudo cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

2.10.12 进入安装路径,命令如下:
$ cd /usr/local/mysql

2.10.13 执行配置脚本,命令如下:
$ sudo ./scripts/mysql_install_db –user=mysql –datadir=/db/mysql/data

2.10.14 复制服务启动脚本,命令如下:
$ sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

2.10.15 启动MySQL服务,命令如下:
$ sudo service mysql start

2.10.16 设置root密码,命令如下:
$ sudo /usr/local/mysql/bin/mysqladmin -u root password 123456
即新密码设置为来123456

2.10.17 设置开机自启动,命令如下:
$ sudo update-rc.d mysql defaults

2.10.18 设置mysql为系统命令,命令如下:
$ sudo ln -s /usr/local/mysql/bin/* /bin/
以后你在系统下直接执行:
$ mysql -u root -p
就可以登录了。

2.10.19 设置访问权限。
在MySQL安装过程中,使用mysql_install_db程序安装了MySQL数据库授权表,表定义了初始MySQL用户账户和访问权限,所有初始账户均没有密码。这些账户为超用户账户,可以执行任何操作。初始root账户的密码为空,因此任何人可以用root账户不用任何密码来连接MySQL服务器,并具有所有权限,这意味着MySQL安装未受保护。如果你想要防止客户端不使用密码用匿名用户来连接,你应当为匿名账户指定密码或删掉匿名账户,应当为MySQL root账户指定密码。使用“mysql –u root”启动MySQL客户端控制台,连接MySQL服务器。命令行如下:
$ mysql -u root -p
Selection_131

然后用刚才的密码123456登录,接着执行:
mysql> DELETE FROM mysql.user WHERE Host=’localhost’ AND User=”;
Query OK, 1 rows affected (0.08 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 1 rows affected (0.01 sec)

mysql的安装配置到此结束,,,,,,,,,,呼~~~~~~~~~~~

2.11 安装最新版本的PHP
2.11.1 在上面的链接或者网上下载php-5.3.22.tar.gz,放到/usr/local/src/目录下,解压软件包到当前目录php-5.3.22下,并进入php-5.3.22目录,命令如下:
$ cd /usr/local/usr/                                         // 进入源码包所在目录
$ sudo tar zxvf php-5.3.22.tar.gz                  // 解压缩
$ cd php-5.3.22/                                             // 进入目录

2.11.2 使用“configure”命令检查并配置安装需要的系统环境,并生成安装配置文件,命令行如下(为了直观,使用“\”将一个命令换成多行):
$ sudo ./configure \
> –prefix=/usr/local/php \                                                    // 设置PHP5 的安装路径
> –with-config-file-path=/usr/local/php/etc \                     // 指定PHP5配置文件存入的路径
> –with-apxs2=/usr/local/apache2/bin/apxs \                   // 告诉PHP查找Apache 2的地方
> –with-mysql=/usr/local/mysql/ \                                      // 指定MySQL的安装目录
> –with-libxml-dir=/usr/local/libxml2/ \                             // 告诉PHP放置libxml2库的地方
> –with-png-dir=/usr/local/libpng/ \                                   // 告诉PHP放置libpng库的地方
> –with-jpeg-dir=/usr/local/jpeg6/ \                                    // 告诉PHP放置jpeg库的地方
> –with-freetype-dir=/usr/local/freetype/ \                        // 告诉PHP放置freetype库的地方
> –with-gd=/usr/local/gd2/ \                                                // 告诉PHP放置gd库的地方
> –with-zlib-dir=/usr/local/zlib/ \                                         // 告诉PHP放置zlib库的地方
> –with-mcrypt=/usr/local/libmcrypt/ \                              // 告诉PHP放置libmcrypt库的地方
> –with-mysqli=/usr/local/mysql/bin/mysql_config \       // 变量激活新增加的MySQLi功能
> –enable-soap \                                                                    // 变量激活SOAP和Web services支持
> –enable-mbstring=all \                                                       // 使多字节字符串支持
> –enable-sockets                                                                   // 变量激活socket通信特性

(如果下载的是php5.5.4 ,可能会出现错误:/php-5.5.1/ext/gd/gd.c:1330: undefined reference to `XpmLibraryVersion’
只需要加上–with-xpm-dir=/usr/lib/x86_64-linux-gnu/ 即可。)

2.11.3 使用make命令编译源码文件并生成安装文件,命令如下:
$ make                                                          // 编译

2.11.4 使用make install命令进行安装,命令如下:
$ make install                                              // 安装

2.11.5 建立配置文件,在使用configure命令安装配置时使用了“–with-config-file-path=/usr/local/php/etc/”选项,指定了配置文件的位置。将源码包目录下的“php.ini- dist”文件复制到指定的目录“/usr/local/php/etc/”中,并改名为“php.int”即可。命令如下:
$ sudo cp php.ini-dist /usr/local/php/etc/php.ini      // 创建配置文件

2.11.6 整合Apache与PHP。上面PHP编译之前,我们使用configure命令安装配置时,使用了“–with-apxs2=/usr/local/apache2/bin/apxs”选项以使Apache 2将PHP作为功能模块使用。但我们还需要修改Apache配置文件,添加PHP的支持,告诉Apache将哪些后缀作为PHP解析。例如,让Apache把.php或.phtml后缀的文件解析为PHP。使用vim打开Apache的配置文件/etc/httpd/httpd.conf,找到“AddType application/x-gzip .gz .tgz”指令项,并在其下方添加一条指令“Addtype application/x-httpd- php .php .phtml”。也可以将任何后缀的文件解析为PHP,只要在添加的语句中加入并用空格分开,这里以多添加一个.phtml来示例。如下所示。
Selection_132
添加最后一条“AddType application/x-httpd-php-source .phps”是为了将 .phps 作为 PHP 的源文件进行语法高亮显示

2.11.7 重启Apache服务器,重启以后才能重新加载配置文件使修改生效。命令如下:
$ sudo /usr/local/apache2/bin/apachectl stop           // 停止Apache服务
$ sudo /usr/local/apache2/bin/apachectl start           // 开启Apache服务

2.11.8 测试PHP环境是否可以正常运行,在/usr/local/apache2/htdocs目录下建一个phpinfo目录,在phpinfo目录下新建一个index.php的文件,在该php文件中添加如下代码:
<?php
phpinfo();
?>
打开浏览器,在地址栏中输入URL为http://localhost/phpinfo/index.php来运行该文件,如果出现如下图所示的内容表示LAMP环境安装成功。
Selection_133
上例中使用了phpinfo()函数,作用是输出有关PHP当前状态的大部分信息内容,这包括关于PHP的编译和扩展信息、PHP版本、服务器信息和环境、PHP的环境、操作系统信息、路径、主要的和本地配置选项的值、HTTP头信息和PHP的许可等。因为每个系统的安装不同,phpinfo()函数可以用于检查某一特定系统配置设置和可用的预定义变量等。它也是一个宝贵的调试工具,因为它包含了所有EGPCS(Environment,GET,POST,Cookie,Server)数据。

三. I’M FUCKING DONE IT!!!!!!!!!!

angry-desk-flip-l (2)

Ubuntu安装mysql5.6.10

Ubuntu下继续安装PHP开发环境,到了安装mysql这一步,由于下的是mysql的最新版本mysql-5.6.10,而mysql貌似从5.5已经不用./configure来配置了,换成了cmake。

于是只能google。最后结合几篇文章与mysql官网的配置介绍Source-Configuration Options,搞定了这个配置。

Selection_019

文本如下:

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
> -DWITH_MYISAM_STORAGE_ENGINE=1 \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
> -DWITH_MEMORY_STORAGE_ENGINE=1 \
> -DWITH_READLINE=1 \
> -DENABLED_LOCAL_INFILE=1 \
> -DMYSQL_DATADIR=/db/mysql/data \
> -DMYSQL_USER=mysql \
> -DMYSQL_TCP_PORT=3306

哦对了,有可能会要sudo。

然后出现了一个问题。

Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:83 (MESSAGE):
Curses library not found. Please install appropriate package,

remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:126 (FIND_CURSES)
cmake/readline.cmake:193 (MYSQL_USE_BUNDLED_LIBEDIT)
CMakeLists.txt:325 (MYSQL_CHECK_READLINE)
— Configuring incomplete, errors occurred!

既然少ncurses包,那就安装一下。

sudo apt-get install libncurses5-dev

然后把当前目录下这个缓存文件删除

sudo rm CMakeCache.txt

终于配置通过。

然后编译源码,需要等待一段时间。

sudo make

Selection_020

然后安装

sudo make install

这个就比较快了。两下搞定。

接下来就是配置了。配置了几个小时,,具体我忘了。好复杂啊~真回忆不起来具体有哪些步骤了,反正是一直网上边搜边做。sigh~

 

 

Ubuntu搭建LAMP环境(安装新版本的Apache服务器)出现问题,执行配置安装httpd时出错

继续在ubuntu下配置PHP开发环境,做到安装Apache服务器了,执行configure的时候,报错,具体如下

configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.

google以后,发现这是需要下载apr和apr-utils 并解压到./srclib/, 再进行编译。

解决办法:

1.1 在上面的链接或者网上下载 apr-1.4.6.tar.gz和apr-util-1.4.1.tar.gz,放到/usr/local/src/目录下,解压软件包到当前目录的apr-1.4.6/和apr-util-1.4.1/下,命令如下:
$ cd /usr/local/usr/                                      // 进入源码包所在目录
$ sudo tar zxvf apr-1.4.6.tar.gz                  // 解压缩
$ sudo tar zxvf apr-util-1.4.1.tar.gz           // 解压缩

1.2 (现在我们依然在/usr/local/src/目录下)拷贝解压缩后的目录到httpd-2.4.4/srclib/apr和httpd-2.4.4/srclib/apr-util中,命令如下:
$ sudo cp -rf apr-1.4.6 httpd-2.4.4/srclib/apr
$ sudo cp -rf apr-util-1.4.1 httpd-2.4.4/srclib/apr-util

然后重新进入httpd目录,进行配置。

结果出现新的问题,如下:
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

又是一个依赖关系,,,,晕死算了。没办法,继续下吧。去http://pcre.org/下载

2.1 在上面的链接或者网上下载 pcre-8.32.tar.gz,放到/usr/local/src/目录下,解压软件包到当前目录的pcre-8.32下,并进入pcre-8.32目录,命令如下:
$ cd /usr/local/usr/                                      // 进入源码包所在目录
$ sudo tar zxvf pcre-8.32.tar.gz                  // 解压缩
$ cd pcre-8.32                                               // 进入目录

2.2 使用“configure”命令检查并配置安装需要的系统环境,并生成安装配置文件,命令行如下:
$ ./configure –prefix=/usr/local/pcre
选项–prefix=/usr/local/pcre作用,是在安装时将软件安装到/usr/local/pcre目录下

2.3 使用make命令编译源码文件并生成安装文件,命令如下:
$ sudo make                                                    // 编译

2.4 使用make install命令进行安装,命令如下:
$ sudo make install                                         // 安装
如果安装成功就会在/usr/local/pcre目录下生成bin、include、lib和share四个目录。如下图
Selection_120

安装完pcre以后,回到httpd目录下,

在./configure的时候加上–with-pcre=/usr/local/pcre即可。

这次终于成功configure了,然后make && make install。

大功告成!

————————————-华丽丽的分割线,下面是英语版——————————————–

English Version:

Continue to install the PHP environment.
An error occured when performing configure command during installing Apache server:

configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.

Google it, I found that we need to download the apr and apr-utils , extract them to ./srclib/ and then compile.

Solution:

1.1 Download the file apr-1.4.6.tar.gz and apr-util-1.4.1.tar.gz on the above link or the official site, put them under /usr/local/src/, and extract them separately to apr-1.4.6/ and apr-util-1.4.1/. The commands as follows:

$ cd /usr/local/usr/            // enter the directory where the source code is
$ sudo tar zxvf apr-1.4.6.tar.gz           // extract the file
$ sudo tar zxvf apr-util-1.4.1.tar.gz      // extract the file

1.2 (remain under the /usr/local/src/)copy the extracted files above separately to directory httpd-2.4.4/srclib/apr/ and httpd-2.4.4/srclib/apr-util/, commands as follows:
$ sudo cp -rf apr-1.4.6 httpd-2.4.4/srclib/apr
$ sudo cp -rf apr-util-1.4.1 httpd-2.4.4/srclib/apr-util

enter the httpd directory to configure.

Another new problem arised:
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

Another dependency?? oops… continue to download~~ go to the website http://pcre.org/.

2.1 Download the file pcre-8.32.tar.gz on the above link or the official site, put it under /usr/local/src/, and extract it to pcre-8.32/, and enter the current directory. The commands as follows:
$ cd /usr/local/usr/            // enter the directory where the source code is
$ sudo tar zxvf  pcre-8.32.tar.gz          // extract the file
$ cd pcre-8.32/                              // enter the current directory

2.2 Check and configure the installation environment with “configure” command, which will generate installation configuration file.  The command line as follows:
$ ./configure –prefix=/usr/local/pcre
“–prefix=/usr/local/pcre” means that the installing software will be installed under /usr/local/pcre.

2.3 use the make command to compile the source file and generate the installation file:
$sudo make                                                      // compile

2.4 use command make install to install:
$ sudi make install                                              // install
If the installation succeeded, there would be four directories(bin/, include/, lib/, share/)generated under /usr/local/pcre, as following picture:

Selection_120

after installing the pcre, return to the httpd directory, and add the option –with-pcre=/usr/local/pcre behind ./configure.

It succeeded~~, and then perform make and make install.
Done!

Ubuntu搭建LAMP环境(安装最新的GD库文件)出现问题,没有头文件

继续安装php开发环境,当安装最新的GD库文件,执行make命令的时候,出现了没有头文件的问题。错误代码如下:

error: png.h: No such file or directory

其实就是头文件的路径不对。

解决办法:

vim gd_png.c

#include “png.h”             
替换成:
#include “/usr/local/libpng/include/png.h”  
           
然后再make就可以了

注:include“”双引号里包含的是libpng安装的路径里的include文件夹

Ubuntu搭建LAMP环境(安装libpng)出现问题,没有makefile文件

继续安装php开发环境,当安装到libpng的时候,输入make命令,确发现提示错误,没有找到makefile。

我还纳闷儿了,明明有makefile.am 和 makefile.in啊,configure以后不就生成makefile了嘛,于是又执行了一遍configure,结果在最后一行发现错误,如下。

configure: error: zlib not installed

google以后,发现大家都是用的这个方法解决:

1.进入zlib的源文件目录,执行命令 make clean,清除zlib;
2.重新配置 ./configure,后面不要接–prefix参数;
3.编辑 make && make install 安装;
4.进入libpng目录,执行命令 ./configure –prefix=/usr/local/libpng;
5.编译 make && make install 安装;

————————————-华丽丽的分割线,下面是英语版———————–

English Version:

Continue to install the PHP environment.
When install the libpng package after entering the make command, the error “cannot find the makefile” might occur.
I’m so confused~~,  the makefile.am and makefile.in obviously exsit in the directory. The makefile should be generated after configuring.
So I perform the configure command again, and then find this error:

configure: error: zlib not installed

Google it, find following solution that many people are using:
1. Enter the directory where the zlib source file is, and perform the make clean command to clean up zlib.
2. Reconfigure using  ./configure without  –prefix parameter.
3. Perform make and make isntall
4. Enter the libpng directory, execute the command ./configure –prefix=/usr/local/libpng.
5. Perform command make and make install.