This is the 25th day of my participation in Gwen Challenge


A lifelong learner, practitioner and sharer committed to the path of technology, a busy and occasionally lazy original blogger, an occasionally boring and occasionally humorous teenager.

Welcome to dig friends wechat search “Jie Ge’s IT journey” attention!

The original link: architecture | take you easy to spin LAMP web site architecture platform (a)

preface

In the previous article, introduced how to build HTTPD service, MySQL database system and HTTPD service access control in Linux environment; Read the recommended reading series at the end of this article, and in today’s article, I’ll introduce the LAMP architecture.

What is LAMP architecture?

LAMP architecture is one of the mature application modes of enterprise websites. It is a set of systems and related software that can work together and provide dynamic Web site services and application development environment.

LAMP is an acronym, L:Linux operating system, A:Apache web server, M:MySQL database server, P:PHP, Python, Perl programming language;

Components of LAMP architecture platform

  • Linux operating system: it is the basis of LAMP architecture and is used to support the operating system of Web sites. It has good stability and compatibility.

  • Apache Web server: as the front-end of LAMP architecture, it is a powerful and stable Web server program. It provides users with website access, sending Web pages, files, pictures and other contents.

  • MySQL database server: it is the back-end of LAMP architecture and an open source relational database system. Data is stored in MySQL database and can be queried through SQL statements.

  • PHP, Python, and Perl: Programming languages for dynamic Web pages, used to interpret dynamic Web files, and provide an environment for developing and running Web applications. PHP is a widely used open source multipurpose scripting language that can be embedded in HTML and is suitable for Web application development.

Application advantages of LAMP architecture platform

  • Low cost: open source software, freely available and free to use, technology and license are not too strict restrictions, greatly reducing the implementation cost of enterprises.

  • Customizable: Modules with a large number of additional components and extensible functions can meet the customization requirements of enterprise applications and can be independently developed and added new functions.

  • Easy to develop: in the dynamic website based on LAMP platform, the page code is simple, and the combination with HTML markup language is very good, and the page code can be easily read and modified.

  • Convenient and easy to use: PHP programming language belongs to the interpretive language, the development of a variety of Web programs do not need to compile, easy to use, the whole set of website project programs, can be copied to the website directory, you can access.

  • Security and stability: Thanks to the advantages of open source,

Build the PHP runtime environment

PHP: Hypertext Preprocessor, an acronym for Hypertext Preprocessor, is a widely used open source multipurpose scripting language that can be embedded in HTML and is suitable for Web application development. It has better Web page execution speed, supports most popular databases and a variety of operating systems.

Installing the PHP Software Package

The preparatory work

To avoid program conflicts, install PHP and related dependency packages in RPM mode.

You can uninstall PHP php-cli php-ldap php-common php-mysql as required. In addition, you need to install zlib-devel and libxml2-devel packages.

[root@localhost lamp]# rpm -e php php-cli php-ldap php-common php-mysql --nodeps [root@localhost lamp]# rpm -ivh / MNT /Packages/ zlib-devel-1.1.3-29.el6.x86_64. RPM [root@localhost lamp]# RPM -ivh The/MNT/Packages/libxml2 - devel - 2.7.6-14. El6. X86_64. RPMCopy the code

Install the extension library

In enterprise applications, some Web applications developed based on PHP will require additional extension tools.

For example: data encryption tools: Libmcrypt, MHash, McRypt, etc., the installation package involved in this article will be packaged together in the public number background, we can obtain through the end of the way to obtain or through the site: Download from http://sourceforge.net. You need to install these extension tools before installing the PHP package.

Install libmcrypt

[root@localhost lamp]# tar ZXF libmcrypt-2.1.8.tar. gz -c /usr/src/ [root@localhost lamp]# CD /usr/src/libmcrypt-2.1.8/ /configure [root@localhost libmcrypt-2.5.8]# make && make install [root@localhost Libmcrypt - 2.5.8] # ln -s/usr/local/lib/libmcrypt. * / usr/lib /Copy the code

Install mhash

[root@localhost lamp]# tar ZXF mhash-0.9.9.9.tar.gz -c /usr/src/ [root@localhost lamp]# CD /usr/src/mhash-0.9.9.9./ /configure [root@localhost mhash-0.9.9.9]# make && make install [root@localhost Mhash-0.9.9.9]# ln -s /usr/local/lib/libmHash * /usr/lib/Copy the code

Install McRypt

[root@localhost lamp]# tar ZXF McRypt-2.6.8.tar. gz -c /usr/src/ [root@localhost lamp]# CD /usr/src/mcrypt-2.6.8/ [root@localhost McRypt-2.6.8]#./configure [root@localhost McRypt-2.6.8]# ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config [root@localhost McRypt-2.6.8]# export LD_LIBRARY_PATH=/usr/local/lib: LD_LIBRARY_PATH [root@localhost McRypt-2.6.8]#./configure [root@localhost McRypt-2.6.8]# make &&  make installCopy the code

Compile and install PHP

Unpack the

Unzip the downloaded PHP source package and release it to the /usr/src directory, and switch to that directory.

[root@localhost lamp]# tar zxf php-5.3.28.tar.gz -C /usr/src/
[root@localhost lamp]# cd /usr/src/php-5.3.28/
Copy the code

configuration

When customizing the CONFIGURATION options for PHP, specify the installation paths for HTTPD and mysqld so that you can add support Settings to make LAMP components work together. You also need to specify the installation path, enable multi-byte support, and encrypt extension support.

[root @ localhost PHP - 5.3.28] #. / configure -- prefix = / usr/local/php5 - with - McRypt - with - apxs2 = / usr/local/HTTPD/bin/apxs --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php5 --enable-mbstringCopy the code

Meanings of each parameter option:

  • –prefix: specifies the directory to install the PHP program in;

  • –with-mcrypt: load extension tools such as data encryption;

  • –with-apxs2: set the apXS module support file location provided by Apache HTTP server;

  • –with-mysql: set the installation location of mysql database server;

  • –with-config-file-path: set the location of PHP configuration file php.ini.

  • — enable-mbString: enable multi-byte string function, support Chinese code, etc.

If the following error occurs during the configuration, the compilation fails.

configure: error: Cannot find libmysqlclient under /usr.
Note that the MySQL client library is not bundled anymore!
Copy the code

Libmysqlclient = /usr/lib64/mysql/ libmysqlclient = /usr/lib64/mysql/ libmysqlclient.so.16.0.0

The solution

Run the following command:

Cp - rp/usr/lib64 / mysql/libmysqlclient. So the 15.0.0 / usr/lib/libmysqlclient. SoCopy the code

Compilation and installation

If the compilation process is long and no errors occur, the INSTALLATION of the PHP program is almost complete.

[root@localhost php-5.3.28]# make && make install
Copy the code

5. Set up LAMP component environment

Mainly includes

  • PHP configuration file php.ini: determines the running parameters of PHP;

  • Httpd. conf: load the libphp5.so module to support PHP web pages;

Php.ini configuration adjustment

The server does not automatically create a php.ini file, but there are two sample configuration files starting with php.ini in the source directory for the development environment and production environment.

[root@localhost php-5.3.28]# ll php.ini-* -rw-r--r--. 1 501 games 69606 12月 11 2013 php.ini- Development # -rw-r--r--. 1 501 games 69627 12月 11 2013 php.ini- Production #Copy the code

Select one of the sample files and copy it to the PHP configuration file directory /usr/local/php5 and rename it php.ini.

[root@localhost php-5.3.28]# cp /usr/ SRC /php-5.3.28/php.ini-development /usr/local/php5/php.iniCopy the code

Modify the configuration content in the php.ini file to control the execution characteristics of PHP pages.

Whether to allow users to upload files, set the size limit of uploaded files, set the default character set, load additional extension modules, etc.

[root@localhost php-5.3.28]# vi /usr/local/php5/php.ini 784 default_charset = "utF-8 882 file_uploads = Upload_max_filesize = 2M max_file_uploads = 20 Post_max_size = 8M # Limit On the amount of data submitted via form post at one time 226 short_open_tag = On # Allow recognition of PHP phrase tagsCopy the code

ZendGuardLoader optimization module was added to improve the execution efficiency of PHP programs and optimize page loading speed. This optimization module works with PHP 5.3 series and can also be downloaded from the official website: http://www.zend.com.

Decompress the downloaded ZendGuardLoader package to /usr/src and copy the module files in phP-5.3. x to the module folder of the PHP program.

[root@localhost lamp]# tar zxf ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz -C /usr/src/
[root@localhost lamp]# cd /usr/src/ZendGuardLoader-php-5.3-linux-glibc23-x86_64/php-5.3.x/
[root@localhost php-5.3.x]# cp ZendGuardLoader.so /usr/local/php5/lib/php
Copy the code

Modify the php.ini configuration file and add the configuration statement to load and enable the zendGuardLoader. so module.

[root @ localhost PHP 5.3 x] # vi/usr/local/php5 / PHP ini 1919 zend_extension = / usr/local/php5 / lib/PHP/ZendGuardLoader. So 1920 zend_loader.enable=1Copy the code

Httpd. conf configuration adjustment

To enable HTTPD server to support PHP page parsing, use the LoadModule configuration item to load the PHP program module file, and then add the AddType configuration item to support. PHP type web files. You also need to add the configuration items index.php and index.html to the DirectoryIndex configuration line to identify common PHP home page files.

Restart the HTTPD service and update the configuration items;

[root @ localhost PHP 5.3 x] # vi/usr/local/HTTPD/conf/HTTPD. Conf 53 LoadModule php5_module modules/libphp5. So the AddType 54 Application /x-httpd-php 170 DirectoryIndex index.php index.html [root@localhost php-5.3.x]# /usr/local/httpd/bin/apachectl restartCopy the code

The meanings of the preceding configurations

LoadModule is automatically added during PHP installation, AddType needs to be added manually, and DirectoryIndex needs to be modified.

  • Php5_module: module name;

  • Modules /libphp5.so: module file location;

6. Test whether LAMP has been successfully built

/usr/local/ HTTPD /htdocs/ = /usr/local/ HTTPD /htdocs/

Verification can be done in two ways:

  • Whether the PHP page is resolved successfully;

  • Access the MySQL database system for verification;

Test whether the PHP page is normal

Phpinfo (); test1.php; test1.php; PHP…? /usr/local/ HTTPD /htdocs/

[root @ localhost PHP 5.3 x] # vi/usr/local/HTTPD/htdocs/test1 <? PHP php phpinfo( ); ? >Copy the code

Use a browser to access the test web page named test1.php.

For example: http://www.jacktiangjwan.com/test1.php

You can see the PHP program version number, configuration commands, running variables and other information;

Test whether the PHP page can access the MySQL database properly

Create a web file named test2.php, add the operation command of the database, used to verify the connection with the MySQL database, query and other operations.

  • The mysql_connect() function is used to connect to the MySQL database.

  • Mysql_close: disconnect the database;

[root @ localhost mysql - 5.5.22] # vi/usr/local/HTTPD/htdocs/test2 <? PHP The PHP $link = mysql_connect (' 127.0.0.1 ', 'root', '666666'); If ($link) echo "Congratulations! ; Mysql_close (); Disconnect from the database? >Copy the code

Restart the service

[root @ localhost mysql - 5.5.22] # / usr/local/HTTPD/bin/apachectl restartCopy the code

Use a browser to access the test web page named test2.php.

For example: http://www.jacktiangjwan.com/test2.php

If you failed to connect to the MySQL database with the wrong username and password, or if the mysql_connect() function failed to connect to the MySQL database, you will be prompted with an error message.

Recommended reading

How to deploy MySQL database in Linux

MySQL | MySQL database system (2) – the basic operations of a SQL statement

MySQL | MySQL database system (3) – database user authorization

MySQL | MySQL database system (4) – database backup and recovery


Original is not easy, if you think this article is useful to you, please kindly like, comment or forward this article, because this will be my power to output more high-quality articles, thank you!

By the way, please give me some free attention! In case you get lost and don’t find me next time.

See you next time!