Compile and install LAMP in Ubuntu

Server environment

1
2
$ cat /etc/issue
Ubuntu 14.04.5 LTS

Some errors encountered during the installation at the bottom of this page

Using root account

1
$ sudo -s

1
2
$ mkdir -p /download
$ cd /download

Install dependence package

1
2
3
4
$ sudo apt-get install -y make gcc automake bison cmake libtool wget gcc unzip \
openssl libssl-dev libxml2 curl build-essential ruby zlib1g zlib1g.dev libncurses5-dev \
libxml2-dev libcurl4-gnutls-dev libjpeg-dev libpng-dev libxpm-dev \
libfreetype6-dev libt1-dev libmcrypt-dev libmysql++-dev libxslt1-dev

Install Apr

1
2
3
4
5
6
7
8
$ cd /download
$ wget http://mirror.bit.edu.cn/apache/apr/apr-1.6.3.tar.gz
$ tar zxvf apr-1.6.3.tar.gz
$ cd apr-1.6.3
$ autoreconf --force --install
$ libtoolize --automake --force
$ ./configure -with-apr=/usr/local/apr
$ make && make install

Install Pcre

1
2
3
4
5
6
$ cd /download
$ wget http://ftp.exim.llorien.org/pcre/pcre-8.36.tar.gz
$ tar zxvf pcre-8.36.tar.gz
$ cd pcre-8.36
$ ./configure --prefix=/usr/pcre
$ make && make install

Install Apache

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
$ cd /download
$ wget http://ftp.itu.edu.tr/Mirror/Apache//httpd/httpd-2.2.34.tar.gz
$ tar zxvf httpd-2.2.34.tar.gz
$ cd httpd-2.2.34
$ ./configure \
"--prefix=/etc/httpd" \
"--exec-prefix=/etc/httpd" \
"--bindir=/usr/bin" \
"--sbindir=/usr/sbin" \
"--sysconfdir=/etc/httpd/conf" \
"--enable-so" \
"--enable-dav" \
"--enable-dav-fs" \
"--enable-dav-lock" \
"--enable-suexec" \
"--enable-deflate" \
"--enable-unique-id" \
"--enable-mods-static=most" \
"--enable-reqtimeout" \
"--with-mpm=prefork" \
"--with-suexec-caller=apache" \
"--with-suexec-docroot=/" \
"--with-suexec-gidmin=100" \
"--with-suexec-logfile=/var/log/httpd/suexec_log" \
"--with-suexec-uidmin=100" \
"--with-suexec-userdir=public_html" \
"--with-suexec-bin=/usr/sbin/suexec" \
"--with-included-apr" \
"--with-pcre=/usr/pcre" \
"--includedir=/usr/include/apache" \
"--libexecdir=/usr/lib/apache" \
"--datadir=/var/www" \
"--localstatedir=/var" \
"--enable-logio" \
"--enable-ssl" \
"--enable-rewrite" \
"--enable-proxy" \
"--enable-expires" \
"--with-ssl=/usr" \
"--enable-headers"

$ make && make install
$ sed -i "s/<Directory \"\/var\/www\/htdocs\">/<Directory \"\/var\/www\">/g" /etc/httpd/conf/httpd.conf
$ sed -i "s/DocumentRoot \"\/var\/www\/htdocs\"/DocumentRoot \"\/var\/www\"/g" /etc/httpd/conf/httpd.conf
$ sed -i "s/DirectoryIndex index.html/DirectoryIndex index.html index.php/g" /etc/httpd/conf/httpd.conf

Install Mysql

1
2
3
4
5
6
7
8
9
10
$ cd /download
$ wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.14.tar.gz
$ tar zxvf mysql-5.6.14.tar.gz
$ cd mysql-5.6.14
$ groupadd mysql
$ useradd -g mysql mysql -s /bin/false
$ mkdir -p /data/mysql /usr/local/mysql
$ chown -R mysql:mysql /data/mysql
$ cmake -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock
$ make && make install
1
2
3
4
5
6
$ cd /usr/local/mysql/
$ chown -R mysql:mysql .
$ scripts/mysql_install_db --user=mysql --datadir=/data/mysql

$ cp ./support-files/my-default.cnf /etc/my.cnf
datadir = /data/mysql
1
2
3
4
5
6
7
8
9
10
11
12
13
$ cp support-files/mysql.server /etc/init.d/mysqld
$ chmod 755 /etc/init.d/mysqld
$ update-rc.d mysqld defaults

# Add Mysql service in system environment
$ vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
$ source /etc/profile

$ service mysqld start

# change mysql password
$ ./bin/mysqladmin -u root password 'new-password'

Install libmcrypt

1
2
3
4
5
6
$ cd /download
$ wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
$ tar zxvf libmcrypt-2.5.8.tar.gz
$ cd libmcrypt-2.5.8
$ ./configure
$ make && make install

Install PHP 5.5.5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
$ cd /download
$ wget -O php-5.5.5.tar.gz http://us2.php.net/get/php-5.5.5.tar.gz/from/this/mirror
$ tar zxvf php-5.5.5.tar.gz
$ cd php-5.5.5
$ ./configure \
--with-apxs2 \
--with-curl=/usr \
--with-gd \
--with-gettext \
--with-jpeg-dir=/usr \
--with-freetype-dir=/usr \
--with-kerberos \
--with-openssl \
--with-mcrypt=/usr/local/lib \
--with-mhash \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pcre-regex \
--with-pear \
--with-png-dir=/usr \
--with-xsl \
--with-zlib \
--with-zlib-dir=/usr \
--with-iconv \
--enable-bcmath \
--enable-calendar \
--enable-exif \
--enable-ftp \
--enable-gd-native-ttf \
--enable-soap \
--enable-sockets \
--enable-mbstring \
--enable-zip \
--enable-wddx

$ make && make install
$ libtool --finish ./libs
$ cp php.ini-production /usr/local/lib/php.ini
$ sed -i 's/;date.timezone =.*/ date.timezone \= "Europe\/Istanbul"/' /usr/local/lib/php.ini

Install phpmyadmin

1
2
3
4
5
6
$ cd /download
$ wget https://files.phpmyadmin.net/phpMyAdmin/4.7.7/phpMyAdmin-4.7.7-all-languages.tar.gz
$ tar zxvf phpMyAdmin-4.7.7-all-languages.tar.gz
$ mv phpMyAdmin-4.7.7-all-languages /var/www/phpMyAdmin
$ cd /var/www/phpMyAdmin
$ cp config.sample.inc.php config.inc.php

###

1
2
3
4
5
$ echo "<?PHP phpInfo();?>" > /var/www/index.php

$ echo "AddType application/x-httpd-php .php" >> /etc/httpd/conf/extra/httpd-php.conf
$ echo "AddType application/x-httpd-php-source .phps" >> /etc/httpd/conf/extra/httpd-php.conf
$ echo "Include conf/extra/httpd-php.conf" >> /etc/httpd/conf/httpd.conf

Restart Apache

1
$ sudo apachectl restart

Ok! Open you browser and visit http://localhost and http://localhost/phpMyAdmin/ with mysql root account

Meet some errors

  • configure: error: Did not find pcre-config script at /usr

    You should install the apr package first

  • cannot remove ‘libtoolT’: No such file or directory

    During installing apr package.

    1
    $ vim apr-1.6.3/configure
    1
    #    $RM "$cfgfile"

    then re-configure

  • configure: error: You need a C++ compiler for C++ support.
    1
    $ sudo apt-get install -y build-essential
  • checking whether to enable mod_deflate… configure: error: mod_deflate has been requested but can not be built due to prerequisite failures
    1
    $ sudo apt-get install -y ruby zlib1g zlib1g.dev
  • configure: error: …No recognized SSL/TLS toolkit detected
    1
    $ sudo apt-get install -y openssl libssl-dev
  • Couldn’t find MySQL server (/usr/bin/mysqld_safe)
    1
    $ rm /etc/mysql/my.cnf
  • The server quit without updating PID file (/usr/local/mysql/data/vagrant-ubuntu-trusty-64.pid).
    1
    $ rm /etc/mysql/my.cnf
  • mysql cmake: Curses library not found. Please install appropriate package,
    1
    2
    $ sudo apt-get install -y libncurses5-dev
    $ rm -f CMakeCache.txt
  • mysql [ERROR] Can’t open the mysql.plugin table. Please run mysql_upgrade to create it.
    1
    2
    3
    mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
    Killed
    mysqld_safe mysqld from pid file /usr/local/mysql/data/vagrant-ubuntu-trusty-64.pid ended

    Remove the data directory and

    1
    2
    3
    4
    5
    6
    7
    $ rm /etc/mysql/my.cnf
    $ rm -rf /data/mysql/
    $ mkdir -p /data/mysql
    $ chown -R mysql:mysql /data/mysql
    $ cd /usr/local/mysql/
    $ scripts/mysql_install_db --user=mysql --datadir=/data/mysql
    $ service mysqld restart
  • configure: error: xml2-config not found. Please check your libxml2 installation.
    1
    $ sudo apt-get install -y libxml2-dev
  • configure: error: Please reinstall the libcurl distribution
    1
    $ sudo apt-get install -y libcurl4-gnutls-dev
  • configure: error: jpeglib.h not found.
    1
    $ sudo apt-get install -y libjpeg-dev
  • configure: error: png.h not found.
    1
    $ sudo apt-get install -y libpng-dev
  • configure: error: freetype.h not found.
    1
    $ sudo apt-get install -y freetype-dev

    If you have installed this. Find out the freetype.sh realy path and change the configure file.

    1
    2
    3
    4
    $ ls /usr/include/freetype2/freetype.h
    /usr/include/freetype2/freetype.h

    $ vim php-5.5.5/configure
    1
    2
    3
    4
    5
    6
    7
    8
    9
    if test "$PHP_FREETYPE_DIR" != "no"; then

    for i in $PHP_FREETYPE_DIR /usr/local /usr; do
    if test -f "$i/include/freetype2/freetype/freetype.h"; then
    FREETYPE2_DIR=$i
    FREETYPE2_INC_DIR=$i/include/freetype2
    break
    fi
    done

    Change if test -f "$i/include/freetype2/freetype/freetype.h"; to if test -f "$i/include/freetype2/freetype.h";

  • configure: error: Cannot find OpenSSL’s libraries
    1
    2
    3
    $ find / -name libssl.so
    /usr/lib/x86_64-linux-gnu/libssl.so
    $ sudo ln -s /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib
Share