The construction of Lamp environment

Source: Internet
Author: User

LAMP is linux apache MySQL php shorthand, in fact, is the Apache, MySQL and PHP installed on the Linux system, to form an environment to run the PHP scripting language. As for what is the PHP scripting language. Apache is the most commonly used Web services software, and MySQL is a relatively small database software, both software and PHP can be installed on the Windows machine. The following Amin teaches you how to build this lamp environment.


Install MySQL


We usually install MySQL is the source package installed, but because it takes a long time to compile, you can go to the official MySQL website to download http://dev.mysql.com/downloads/specific version according to your platform and requirements, At present, the more commonly used for mysql-5.0/mysql-5.1, 5.5 version although has been released for some days, but seemingly with the online running service is still a few.


Download MySQL to/usr/local/src/

cd/usr/local/src/

wget http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz

Extract

[Email protected] src]# tar zxvf/usr/local/src/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz

Move the extracted data to the/usr/local/mysql

[Email protected] src]# MV Mysql-5.1.40-linux-i686-icc-glibc23/usr/local/mysql

Build MySQL User

[[email protected] src]# useradd-s/sbin/nologin MySQL

Initializing the database

[Email protected] src]# Cd/usr/local/mysql

[Email protected] mysql]# mkdir-p/data/mysql; Chown-r Mysql:mysql/data/mysql

[Email protected] mysql]#/scripts/mysql_install_db--user=mysql--datadir=/data/mysql

--user defines the owner of the database, the--datadir defines where the database is installed, and it is recommended to place the partition on a large space, which needs to be created on its own. This step is critical if you see two "OK" instructions to perform correctly, otherwise please review the error message carefully,



Copy configuration file

[email protected] mysql]# CP support-files/my-large.cnf/etc/my.cnf

Copy the startup script file and modify its properties

[email protected] mysql]# CP support-files/mysql.server/etc/init.d/mysqld

[Email protected] mysql]# chmod 755/etc/init.d/mysqld

modifying startup scripts

[Email protected] mysql]# Vim/etc/init.d/mysqld

There are "Datadir=/data/mysql" where modifications are required (the directory defined when the database was previously initialized)


Add the startup script to the system service entry and set the boot start to start MySQL

[Email protected] mysql]# chkconfig--add mysqld

[Email protected] mysql]# chkconfig mysqld on

[[Email protected] mysql]# service mysqld start

If not, please check the error log under/data/mysql/, which is usually the hostname. Err. The command to check if MySQL starts is:


[[Email protected] mysql]# PS aux |grep mysqld

Installing Apache


Apache also need to download the appropriate version of the official website, the current use of more than the version of 2.0 or 2.2. Apache Official website: http://www.apache.org/dyn/closer.cgi You can also use the address provided by Amin to download.


[Email protected] mysql]# cd/usr/local/src/

[Email protected] src]# wget http://syslab.comsenz.com/downloads/linux/httpd-2.2.16.tar.gz

Extract:


[Email protected] src]# tar zxvf httpd-2.2.16.tar.gz

To configure the compilation parameters:


[Email protected] src]# CD httpd-2.2.16

[Email protected] httpd-2.2.16]#/configure \

--PREFIX=/USR/LOCAL/APACHE2 \

--WITH-INCLUDED-APR \

--ENABLE-SO \

--enable-deflate=shared \

--enable-expires=shared \

--enable-rewrite=shared \

--with-pcre

--PREFIX specifies where to install,--enable-so means to enable DSO [1]--enable-deflate=shared means the shared way of compiling deflate, followed by the same parameters. If you have such an error in this step:


Error:mod_deflate have been requested but can is built due to prerequisite failures

The solution is:


Yum Install-y zlib-devel

To avoid errors in make, it is best to install some library files in advance:


Yum install-y pcre pcre-devel Apr apr-devel

Compile:


[[email protected] httpd-2.2.16]# make

Installation:


[[email protected] httpd-2.2.16]# make install

Can you use echo $ for all two steps above? To check for proper execution, or you need to fix the problem based on the error.


Install PHP


, PHP is currently the latest version of 5.5, I believe most of the site is still running 5.2 or older version, in fact, 5.2 version of PHP is very classic and very stable, but considering the version is too old, there will be some loopholes, so it is recommended that you use the 5.3 or 5.4 version, PHP official:/http www.php.net/downloads.php


Download PHP:


[Email protected] httpd-2.2.16]# CD/USR/LOCAL/SRC

[Email protected] src]# wget http://am1.php.net/distributions/php-5.3.27.tar.gz

Extract:


[Email protected] src]# tar zxf php-5.3.27.tar.gz

To configure the compilation parameters:


[Email protected] src]# CD php-5.3.27

[Email protected] php-5.3.27]#/configure \

--prefix=/usr/local/php \

--WITH-APXS2=/USR/LOCAL/APACHE2/BIN/APXS \

--WITH-CONFIG-FILE-PATH=/USR/LOCAL/PHP/ETC \

--with-mysql=/usr/local/mysql \

--with-libxml-dir \

--WITH-GD \

--with-jpeg-dir \

--with-png-dir \

--with-freetype-dir \

--with-iconv-dir \

--with-zlib-dir \

--WITH-BZ2 \

--WITH-OPENSSL \

--with-mcrypt \

--ENABLE-SOAP \

--ENABLE-GD-NATIVE-TTF \

--enable-mbstring \

--enable-sockets \

--ENABLE-EXIF \

--disable-ipv6

The following error was encountered in this step:


Configure:error:xml2-config not found. Please check your LIBXML2 installation.

The solution is:


Yum Install-y libxml2-devel

There are also errors:


Configure:error:Cannot find OpenSSL ' s <evp.h>

The solution is:


Yum Install-y OpenSSL Openssl-devel

Error:


Checking for BZIP2 in default path ... not found

Configure:error:Please Reinstall the BZIP2 distribution

Workaround:


Yum install-y bzip2 Bzip2-devel

Error:


Configure:error:png.h not found.

Workaround:


Yum install-y libpng Libpng-devel

Error:


Configure:error:freetype.h not found.

Workaround:


Yum install-y FreeType Freetype-devel

Error:


Configure:error:mcrypt.h not found. Please reinstall Libmcrypt.

Workaround:


Rpm-ivh "http://www.aminglinux.com/bbs/data/attachment/forum/month_1211/epel-release-6-7.noarch.rpm"

Yum Install-y libmcrypt-devel

Because the centos6.x default yum source does not libmcrypt-devel this package, it can only be assisted by a third-party yum source.


Compile:


[[email protected] php-5.3.27]# make

In this step, you may also encounter many errors, no relationship, please carefully review the error message, the solution is very simple, is to install the missing library.


Installation:


[[email protected] php-5.3.27]# make install

Copy the configuration file:


[email protected] php-5.3.27]# CP Php.ini-production/usr/local/php/etc/php.ini

Apache with PHP


The Apache master configuration file is:/usr/local/apache2/conf/httpd.conf


Vim/usr/local/apache2/conf/httpd.conf

Found it:


AddType application/x-gzip. gz. tgz

Under this line, add the following:


AddType application/x-httpd-php. php

Found it:


<ifmodule dir_module>

DirectoryIndex index.html

</IfModule>

Change the line to read:


<ifmodule dir_module>

DirectoryIndex index.html index.htm index.php

</IfModule>

Found it:


#ServerName www.example.com:80

Modified to:


ServerName localhost:80

Test if lamp is successful


Verify that the configuration file is correct before starting Apache:


/usr/local/apache2/bin/apachectl-t

If there is an error, please continue to modify httpd.conf, if it is correct is displayed as "Syntax OK", the command to start Apache:


/usr/local/apache2/bin/apachectl start

To see if it starts:


[Email protected] ~]# NETSTAT-LNP |grep httpd

TCP 0 0::: +:::* LISTEN 7667/httpd

If this line is displayed, it is started. You can also use the Curl command to simply test:


[[email protected] ~]# curl localhost

This is only true if it is displayed.


Test if PHP is parsed correctly:


vim/usr/local/apache2/htdocs/1.php

Write:


<?php

echo "PHP parsing normal";

?>

After saving, continue testing:


Curl localhost/1.php

See if you can see the following information:


[Email protected] ~]# Curl localhost/1.php

PHP parsing normal [[email protected] ~]#


You may not be able to access the Web service when you first use it for your browser, because of the firewall. Please run the following command:


[Email protected] ~]# iptables-f

This allows the system to clear the default firewall rules and release port 80.


The construction of Lamp environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.