Year-end benefits: PHP7 + Apache2.4 + MySQL5.6 source code compilation and installation, Environment configuration, build your own LAMP environment, php7apache2.4

Source: Internet
Author: User
Tags install openssl mcrypt zts fully qualified domain name

Year-end benefits: PHP7 + Apache2.4 + MySQL5.6 source code compilation and installation, Environment configuration, build your own LAMP environment, php7apache2.4

PHP 7 is out. Are you still playing with PHP5?

MySQL5.6 came out early. Are you still playing MySql5.2?

Apache2.4 has come out early. Are you still playing Apache2.2?

 

I am willing to build the environment for reference. Here is the installation of the source code, what one-click installation package, what yum installation, and what rpm installation all skipped (I am a self-abuse, just like installing software in windows, I do not like to install it in the default location, that is, drive C. Otherwise, the system disk will pop up)

Before installation, make sure that PHP is installed at the end. Before installing any software, make sure that the library on which it depends is installed.

 

(Centos6.4)

First install apache2.4

Go to apache official website to download the latest http://httpd.apache.org/download.cgi httpd-2.4.18.tar.gz

Decompress the package

tar -zxvf httpd-2.4.18.tar.gz

Go to the decompressed directory

cd httpd-2.4.18

First, do not rush to install it. First, make sure that the library on which it depends is available. How can I check whether the software is installed (rpm-q xxx ), if no dependency is installed, install it. (I usually install the dependency library directly using yum by default, so that you do not need to know the installation path of the dependency library during software installation, saving a lot of trouble)

These installation packages are: zlib-devel pcre apr-util

Before the installation, I encountered the problem that yum could not access the source. Here we specify the yum source as Netease 163. For details about how to specify it, see http://mirrors.163.com/.help/centos.html. detailed steps are provided.

 

Then install zlib-devel pcre apr-util (apr-util). During installation, I found that the yum installation is not available and the class library cannot be found during compilation, therefore, the author uses the source code installation method)

yum install zlib-devel pcre-devel pcre

Then we use the source code to install apr-util these two libraries, the source code installation package of these two libraries can be found in (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

Decompress the package and install the package separately. Make sure that gcc-c ++ is installed. If not, use 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

 

Install and configure Apache. You can use

./configure --help 

Check which parameters can be configured during installation. Next we will configure some parameters and check them.

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

Check for no errors and start compilation and installation.

make && make install

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

After installation, go to the installation directory and enable the apache service.

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

Ah, an error is reported.

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

No serverName in the configuration file, so add ServerName in httpd. conf.

Vim/usr/local/apache/conf/httpd. conf # Add ServerName localhost

Restart apache and check if everything is normal.

Okay, this is a big success. apache2.4 has been installed.

 

 

Now let's start installing mysql.

Download the mysqlsource code installation package. Here we use mysql-5.6.28.tar.gz. You can download this package from the official website and decompress it.

tar -zxvf mysql-5.6.28.tar.gz

In the old saying, do not rush to install. First, check whether the mysql dependent class library is installed. If not, install it.

yum -y install make gcc-c++ cmake bison-devel  ncurses-devel

Go to the decompressed mysql directory, and you will be surprised to find that there is no configure file. This is mainly because the new version of mysql uses cmake for installation, so there is no previous configure file

Now we will use cmake for installation and 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

Important points 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, the compilation and installation will begin.

make && make install

Then, wait for half an hour...

 

After everything is ready, we need to ensure that there are mysql groups and mysql users

cat /etc/group|grep 'mysql'cat /etc/passwd|grep 'mysql'

Add if no

groupadd mysqluseradd -g mysql mysql

Change the owner of the '/usr/local/mysql' directory to mysql.

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

At this time, the installation is complete, but there is no data in mysql (even if there is no data in the system), then you need to execute the built-in script to initialize mysql Data

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

After execution, you will find that some files are added to the/usr/local/mysql/data Directory, which is the mysql data file.

Start mysql. Note that the configuration file specified above is located in the '/etc' directory, but for convenience, to put the mysql configuration file in '/usr/local/mysql/', we need to put '/etc/my. conf' change the name

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

If mysql cannot be found in the '/etc' directory, it will go down to '$ basedir', that is, the'/usr/local/mysql/'directory.

At this time, the installation of mysql is complete, and the following will be started, you will find that the use

/usr/local/mysql/bin/mysql start

Unable to start. Error:

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

 

I couldn't do anything before, even if I established '/var/lib/mysql. sock', I finally realized that it wasn't how to start it,

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

Then, test

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

Now, mysql is successfully installed!

 

The last step is to install PHP7, which is the most exciting time.

First, you need to download PHP7, which can be downloaded on the official website, and then decompress it. The command is the same as the one above (I use PHP7.0.2 here)

The dependency package must be installed first.

Php-mcrypt libmcrypt-devel autoconf freetype gd unzip SRC libmcrypt libpng-devel libjpeg libxml2 libxml2-devel zlib curl-devel

A bunch of Dependencies

yum -y install php-mcrypt libmcrypt libmcrypt-devel  autoconf  freetype gd jpegsrc libmcrypt libpng libpng-devel libjpeg libxml2 libxml2-devel zlib curl curl-devel 
./configure --prefix=/usr/local/php/ --with-apxs2=/usr/local/apache/bin/apxs --enable-mbstring--with-curl --with-gd --enable-fpm --enable-mysqlnd  --with-pdo-mysql=mysqlnd --with-config-file-path=/usr/local/php/etc/ --with-mysqli=mysqlnd --with-mysql-sock=/var/lib/mysql/mysql.sock

 

The above configuration supports many things during compilation. You can add them as needed, but there is a basic need to be configured.

-- Prefix installation directory

-- Location of the with-apxs2 apache File

-- With-mysql-sock =/var/lib/mysql. sock mysql sock file address

-- Enable-mbstring supports mbstring

-- With-curl supports curl

-- With-gd supports gd

-- Enable-fpm supports fpm

-- Enable-mysqlnd-- With-pdo-mysql pdo support

 

Check whether there is any error, and you can install it. Of course, if there is an error and the number of dependencies is not installed, install the relevant dependent libraries in sequence as prompted.

Then, compile and install the SDK.

make && make install

After a long wait of half an hour ....

After the installation is complete, copy the configuration file in the source code package to the PHP installation directory. The source code package contains two php configurations. ini-development php. ini-production: You can see the name. One is the development environment and the other is the production environment. Here we will copy the development environment

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

At this point, the last job has not been done, that is, let apache parse the PHP file and add

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

Then restart apache

/usr/local/apache/bin/apachectl restart

Add test. php to the/usr/local/apache/htdocs/directory.

<?phpinfo();

We started to access localhost/test. php and then showed an exciting picture.

 

By now, all your LAMP environments of the latest version have been successfully built !!!!

 

Next I will talk a little bit about it. Sometimes you need to add extensions for php. If you get two dll files in windows and change php. ini to OK, but it won't work in centos, and you have to compile them. In this way, if you re-compile PHP, the author will be insulted. What we will talk about here is that you can add extensions for PHP without re-compiling PHP.

In this example, we want to install openssl extensions. The openssl directory will be available under your source code installation package ext to enter this directory.

First, call the compiled phpize.

/usr/local/php/bin/phpize

An error is reported.

Cannot find config. m4.
Make sure that you run '/usr/local/php/bin/phpize' in the top level source directory of the module

Okay, then we will copy config0.m4 in this directory to config. m4.

cp config0.m4 config.m4

Then execute again

/usr/local/php/bin/phpize

Hey, this is OK. After completing this process, you will find some more files in it, including the configure file. This is what we want.

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

After compilation, install

make && make install

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

Add the extension to php. ini.

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

Restart apache and access test. php again. The extension will be installed.

 

Okay. Here the installation of LAMP is complete. In fact, the installation is not very complicated. The complicated part is various dependencies. It is really drunk. There are various dependencies !!!!

 

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.