Year-end benefits, php7+apache2.4+mysql5.6 source compiled installation, environment configuration, build your own lamp environment

Source: Internet
Author: User
Tags configuration php fpm mcrypt mysql in openssl zts fully qualified domain name

PHP7 are out, are you still playing PHP5?

MySQL5.6 come out early, are you still playing MySql5.2?

Apache2.4 come out early, are you still playing Apache2.2?

I am not willing to personally set up the environment for the construction of reference. Here is the source of the installation of Austrian, what a key installation package, what Yum installed, what RPM installation is all skipped (the author is a masochist, just like Windows installed software, do not like to install in the default location is the C drive, otherwise the system disk will explode)

Before the installation, to explain, to ensure that the final installation of PHP, the reason behind the announcement. Before you install any software, make sure that the libraries it depends on are installed.

(The installation environment in the Department centos6.4)

First, install apache2.4.

Go to Apache official website to download http://httpd.apache.org/download.cgi Latest version httpd-2.4.18.tar.gz

And then unzip it.

tar -zxvf httpd-2.4. . tar. gz

Go to the Unpacked directory

CD httpd-2.4.  -

Do not rush to install, first ensure that it depends on the library is there, how to see if the software is installed (rpm-q xxx), if there is no installation depends on the installation (I generally install the dependency library directly using the Yum default installation, so that in the software installation, you do not need to know the dependent Library installation path, save a lot of trouble)

These installation packages are: Zlib-devel pcre-devel pcre Apr apr-util

Before the installation of the author encountered Yum can not access the source of the problem, here we have the source of Yum named NetEase 163, the specific method please see http://mirrors.163.com/.help/centos.html, above with detailed steps

Then install zlib-devel pcre-devel pcre Apr apr-util (Apr apr-util These two libraries, the author found that using Yum installation is not advisable, compile-time cannot find the class library, so I use the source installation method here)

Yum Install zlib-devel pcre-devel pcre

Then we use the source to install the APR apr-util These two libraries, the two libraries of the source installation package can be found (http://apr.apache.org/download.cgi)

Download separately

wget http://mirrors.noc.im/apache//apr/apr-1.5.2.tar.gzwget http://mirrors.noc.im/apache//apr/apr-util-1.5.4.tar.gz

Then unzip separately and install (be sure to install gcc-c++ without using Yum install gcc-c++)

tar -zxvf apr-1.5. 2. Tar . GZCD Apr-1.5. 2 . /configure--prefix=/usr/local/apr/
Make && make install
tar -zxvf apr-util-1.5. 4. Tar . GZ cd Apr-util-1.5. 4 . /configure--prefix=/usr/local/apr-util/  --with-apr=/usr/local/apr/ make make Install

The following is the installation configuration for Apache, which you can use

To see what parameters can be configured at installation, let's start by configuring some parameters and checking

./Configure   --prefix=/usr/local/apache/  --with-apr=/usr/local/apr/  --   with-apr-util=/usr/local/apr-util/  --enable-so--enable-deflate=gkfx  --enable-expires=shared  --enable-rewrite=shared  --enable-static-support

Check for errors, and then start compiling the installation

 Make  Make Install

Then, long wait, about half an hour ...

After installation, go to the installation directory and open Apache service

cd/usr/local/apache/bin/. /apachectl start

Ah, found an error

AH00558:httpd:Could not reliably determine the server ' s fully qualified domain name, using Localhost.localdomain. Set the ' ServerName ' directive globally to suppress this message

Well, the original is not ServerName in the configuration file, it is added in the httpd.conf ServerName

vim/usr/local/apache/conf/httpd.conf# increase servername localhost

And then restart Apache, find everything OK, and then we visit to see if OK

All right, here we are. apache2.4 installation is complete

Okay, now let's start installing MySQL.

First to download the MySQL source installation package, we use mysql-5.6.28.tar.gz here, this can be downloaded to the official website, and then unzip

tar -zxvf mysql-5.6. . tar. gz

Or the old saying, don't hurry to install, first look at MySQL depends on the class library is installed, do not install the words

Yum Install  Make gcc-c++ cmake bison-devel  ncurses-devel

Go to the unpacked MySQL directory and you'll be amazed to find no configure files, and that's how it's good. This is primarily a new version of MySQL using the cmake for installation, so there is no previous configure file anymore

Now we'll use CMake to install the configuration

CMake-dcmake_install_prefix=/usr/local/MySQL-dmysql_datadir=/usr/local/mysql/Data-dsysconfdir=/etc-dwith_myisam_storage_engine=1 -dwith_innobase_storage_engine=1 -dwith_memory_storage_engine=1 -dwith_readline=1 -dmysql_unix_addr=/var/lib/mysql/Mysql.sock-dmysql_tcp_port=3306 -denabled_local_infile=1 -dwith_partition_storage_engine=1 -dextra_charsets= All-ddefault_charset=UTF8-ddefault_collation=utf8_general_ci

A few important places above

'-dcmake_install_prefix ' is the installation directory

'-dmysql_datadir ' is the data file storage directory

'-dsysconfdir ' configuration file directory

'-dmysql_unix_addr ' sock file storage directory

'-dmysql_tcp_port ' port number

After the check is correct, you start to compile and install the

 Make  Make Install

Then, then, then just half an hour of waiting ...

When everything is ready, we need to make sure that the MySQL group and MySQL users are there

Cat /etc/group| grep ' MySQL ' cat /etc/passwd| grep ' MySQL '

If not, add

-G MySQL MySQL

Then change the owner of the directory '/usr/local/mysql ' to MySQL

chown -R mysql:mysql/usr/local/mysql

This is already installed, but there is no data in MySQL (even if the system comes with no data), you need to execute the self-contained script, initialize the MySQL data

/usr/local/mysql/scripts/--basedir=/usr/local/mysql--datadir=/usr/local/mysql/data--user=mysql

After the execution, you will find some files in the/usr/local/mysql/data directory, these are the MySQL data files.

Then start MySQL, it is important to note that we specify the configuration file in the '/etc ' directory, but we want to put the MySQL configuration file to '/usr/local/mysql/' for convenience, then we need to change the name '/etc/my.conf '

mv /etc/my.cnf  /etc/my.cnf.bak

At this time, MySQL in the '/etc ' directory can not find, will go to ' $basedir ' go down to find, that is '/usr/local/mysql/' directory

At this point, the installation of MySQL is finished, the following will be launched, you will find the use of

/usr/local/mysql/bin/mysql start

Unable to start, error is

ERROR 2002 (HY000): Can ' t connect to local MySQL server through socket '/var/lib/mysql/mysql.sock ' (2)

Before the author how to do not, even if the establishment of '/var/lib/mysql/mysql.sock ' later finally know, originally not how to start, but

/usr/local/mysql/support-files/mysql.server start

Then, under test

/usr/local/mysql/bin/mysql-u rootshow databases;

Okay, here's the installation of MySQL!

The final step, we're going to install the PHP7, the most exciting moment.

The first is to download PHP7, this can be downloaded to the official website, and then unzip, and the same command as above (the author uses PHP7.0.2 here)

Pre-installation is still a cliché, the dependency package must first install the

Php-mcrypt libmcrypt libmcrypt-devel autoconf freetype gd jpegsrc libmcrypt libpng libpng-devel libjpeg libxml2 libxml2- Devel zlib Curl Curl-devel

Very cumbersome, a bunch of dependencies

Yum  Install php-mcrypt libmcrypt libmcrypt-devel autoconf freetype gd jpegsrc libmcrypt libpng libpng-devel libjpeg LIBXML2 libxml2-devel zlib Curl Curl-devel
./--prefix=/usr/local/php/--with-apxs2=/usr/local/apache/bin/--enable-mbstring-- with---with---enable---enable-mysqlnd  --with-pdo-mysql=-- with-config-file-path=/usr/local/php/etc/--with-mysqli=--with-mysql-sock=/var/lib/mysql/ Mysql.sock

The above compile-time configuration support a lot of things, you can add according to their own needs, but there is a basic must be configured

--prefix installation directory

--WITH-APXS2 Apache File Location

--with-mysql-sock=/var/lib/mysql/mysql.sock MySQL sock file address

--enable-mbstring Support Mbstring

--with-curl supports Curl

--WITH-GD Support GD

--ENABLE-FPM Support FPM

--enable-mysqlnd --with-pdo-mysql PDO Support

Check no errors, you can install, of course, if there are errors, how many dependencies are not installed, follow the prompts to install the relevant dependent library

And then you start compiling and installing the

 Make  Make Install

After half an hour long wait ....

After the installation is complete, we want to copy the configuration files in the source package to the PHP installation directory, the source package has two configuration php.ini-development php.ini-production, look at the name will know, one is the development environment, one is the production environment, We'll replicate the development environment here.

CP php.ini-development  /usr/local/php/etc/php.ini

Here, the last job did not do, is to let Apache to parse PHP files, in the Apache configuration file httpd.conf Add a

AddType application/x-httpd-php. php. phtml

And then restart Apache.

/usr/local/apache/bin/apachectl restart

Then add test.php to the directory/usr/local/apache/htdocs/directory

<? Phpinfo ();

We started visiting localhost/test.php, and then we showed an exciting picture.

Here, all your latest version of the lamp environment, even if the building is successful!!!!

In the back of the little knowledge, sometimes you need to add extensions for PHP, Windows to get two DLLs and then change the php.ini is OK, but not under CentOS, but also to compile. So if you want to recompile PHP, the author will be reviled, we are here to tell you do not need to recompile PHP, you can add extensions for PHP

Here is an example where we want to install the OpenSSL extension, which will have the OpenSSL directory under your source installation package ext, into that directory

First call the phpize we've compiled.

/usr/local/php/bin/phpize

The discovery will be an error

Cannot find CONFIG.M4.
Make sure this you run '/usr/local/php/bin/phpize ' in the top level source directory of the module

OK, and then we'll copy the CONFIG0.M4 in the directory to CONFIG.M4.

CP CONFIG0.M4 CONFIG.M4

And then execute it again.

/usr/local/php/bin/phpize

Eh, this is OK, after the completion, you will find that there are some files in it there are configure files, this is what we want

./Configure \--with-php-config=/usr/local/php/bin/php-config

Once the compilation is complete, start the installation

 Make  Make Install

This is where you will find the so file in your extension directory (the extension directory is not specified, it is located in/usr/local/php/lib/php/extensions/no-debug-zts-xxx)

Then add the extension to the php.ini

Extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/openssl.so

Then reboot Apache again to visit test.php and you will find the extension installed.

OK, here about lamp installation of East is finished, in fact, installation is not very complex, complex is a variety of dependence, really drunk, all kinds of dependence ah, there is wood!!!!

Year-end benefits, php7+apache2.4+mysql5.6 source compiled installation, environment configuration, build your own 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.