Experience sharing the manual configuration of lamp servers in Linux server systems _linux

Source: Internet
Author: User
Tags bz2 chmod install php localhost mysql mysql in openssl versions zts

Lamp is the abbreviation of Linux, Apache, MySQL, Php/perl/python. It is composed of various components are open source software, so it is convenient to free access, resulting in the wide use of these components, and constantly improve the development, the initial formation of a new software system pattern, and may become the open source software system Engineering core model.

To install the newer httpd we have to install the newer Apr. There is no need to specify an APR on Red Hat 6 because the version it installs by default is newer. But we're using the Red Hat 5.8 version, which gives us a bit of an old version of the APR, and we're going to install a new version of the APR, is the old version of the APR going to uninstall? This is not the old version must not be unloaded, may have dependencies; What about the upgrade? Also can not, the upgrade after the old version is also not. That some friends should ask, the two versions in whether there should be a conflict. We can only use multiple versions of the same mechanism, as long as the compilation of the new version of the installation and the old version installed in a different place on it.

RPM Package Installation:/bin,/sbin,/usr/bin,/usr/sbin ### #二进制所在位置/lib,/usr/lib ### #库文件所在位置/etc ### #配置文件所在位置/usr/share/{doc,man}### #帮助文档/Manual Compile installation:/usr/local/### #定义安装第三方软件包 bin, sbin ### #二进制所在位置 lib ### #库文件所在位置 etc ### #配置文件所在位置 Share/{doc,man} ### #帮助文档/ Manual

It looks neat for us to install this way, but we also have to think about what to do if we want to uninstall a software. Would you like one more? That's not going to get you into trouble. So we adjust, that is, to define the installation. The third party package is still under/usr/local/, and a directory named after the software name (for easy to find) is also created, and the files associated with it are placed under this directory. However, there is a problem with the installation, its binary program is not in the path environment, it can not directly execute the command, then modify the path variable, but also to modify the library file search path, but also to modify the man's profile, and so on.

For example:/usr/local/apr/

Bin, Sbin, Lib, includes, etc, Share/man

Let's start by manually configuring Apr and Apr-util and how to install httpd. (Hint: here to download the source package)

First step: Install the development environment

Step Two: Install the APR source program

We're loading it up on our servers, and if you do, go to the official website (apr.apache.org) to download the source package, and here we put it under the home directory. If you don't want to put it here, you can put it under the/USR/LOCAL/SRC, where the source is specially placed. Here we are ready to install APR "Hint: If your system time than download the time of the source package is earlier, this will be wrong." If the time is not correct, you can use Hwclock–s, which synchronizes the software time to the hardware time. 】

Below we need to unpack the software to install. The first package is installed after the installation is complete.

[Root@localhost apr-1.4.6]# make [root@localhost apr-1.4.6]# make install

Step Three: Install Apr-util

The installation apr-util is the same as the APR we installed. However, it specifies the path of the time to specify where the APR is installed, if not specified, it will automatically find the old version of the (05 lines at the back of the red is the specified Apr installation path).

[Root@localhost ~]# tar xf apr-util-1.5.2.tar.bz2 [root@localhost ~]# cd apr-util-1.5.2 [root@localhost apr-util-1.5.2]# ./configure--prefix=/usr/local/apr-util--with-apr=/usr/local/apr [root@localhost apr-util-1.5.2]# make [ Root@localhost apr-util-1.5.2]# make Install

Fourth Step: Install httpd

We have to install a module before installing HTTPD, this module is pcre. In addition to configuring those modules, it is possible to use the--enable–deflate configuration compression module. --enable–expires Expiration Header control. If you want to work in fastcgi mode, you must enable-enable-proxy-fcgi. Here we work in a modular way, not to be enabled for the time being. --enable-mpms-shared=all is not available in version 2.2, but it is available in version 2.4. Apache is a support mpm (hiding to the processing module) there are three forms, prefork,worker,event. Which one is supported is determined at compile time. Use MPM in a modular manner at 2.4, which means you can simultaneously write the three modules in which you can switch. It sounds great, but PHP is a modular way to MPM, if using prefork,php is easy. But you're using worker or event. Our PHP must be compiled into ZTS format, and if you want to use it flexibly, edit php two times. In the 2.2 default MPM is Prefork, in 2.4 The default MPM is event. --WITH-MPM=MPM Specifies which one is the default. "Hint: the details are on the diagram"

[Root@localhost ~]# tar xf httpd-2.4.4.tar.bz2 [root@localhost ~]# cd httpd-2.4.4 [root@localhost httpd-2.4.4]#-Yum-y ins Tall Pcre-devel ### #安装pcre模块

[Root@localhost httpd-2.4.4]#./configure--prefix=/usr/local/apache--sysconfdir=/etc/httpd--enable-so-- Enable-rewirte--enable-ssl--enable-cgi--enable-cgid--enable-modules=most--enable-mods-shared=most-- Enable-mpms-shared=all--WITH-APR=/USR/LOCAL/APR--with-apr-util=/usr/local/apr-util

Fifth step: Close SELinux

The reason to take this as a big step is to turn off the SELinux and not shut down your server. The default is basically open, and we're going to turn it off.

1. Temporary closure

2. Permanent shutdown

[Root@localhost httpd-2.4.4]# Vim/etc/selinux/config

Step Sixth: Start the Web server

Under/usr/local/paache, there is a script that starts the service, and the script name is Bin/apachectl.

Here to tell you about the contents of/usr/local/apache, by the way the content of the Web page to add Hello Apache, this time we look at.

Step seventh: Put the. pid file under/var/run

We typically put the generated. pid file under/var/run, but the. pid files are all placed under/usr/local/apache/logs, but our/logs/are all under the log, Put these. pid files are obviously inappropriate, and we edit the configuration file (/etc/httpd/httpd.conf) here to generate all of its. pid files under/var/run. What we added in the configuration file is: Pidfile "/var/run/httpd.pid". "Hint: We can also verify that when you do not enter these content, shut down the server (Bin/apachectl stop) We use the NETSTAT–TNLP to view 80 ports, is no longer in the listening state, we look at the logs below has no. pid file. When you add Pidfile "/var/run/httpd.pid" to the configuration file, we find that the. pid file has been placed under the/var/run/, and the name is Httpd.pid. 】

Eighth step: Easy to start

Although we can start up at this time but it is always inconvenient to start, then we have to write a foot to make it convenient. Put the file inside the/ETC/INIT.D/HTTPD, the editor is done to give it permission on the line, start directly on the line. Next we let it boot up automatically.

[Root@localhost apache]# vim/etc/init.d/httpd [root@localhost apache]# chmod

  #!/bin/bash # # httpd Startup script for the Apache HTTP Server # chkconfig:-# Description:apache are a world Wide Web Server. It is used to serve \ # HTML files and CGI. # processname:httpd # config:/etc/httpd/conf/httpd.conf # config:/etc/sysconfig/httpd # pidfile:/var/run/httpd.pid # S Ource function Library. . /etc/rc.d/init.d/functions if [-f/etc/sysconfig/httpd]; Then. /etc/sysconfig/httpd fi # Start httpd in the C locale by default. httpd_lang=${httpd_lang-"C"} # This would prevent Initlog from swallowing up a pass-phrase prompt if # mod_ssl needs a pass -phrase from the user. Initlog_args= "" # Set Httpd=/usr/sbin/httpd.worker in/etc/sysconfig/httpd to use a server # with the thread-based ' worker "MPM; Be warned that some modules could not # work correctly with a thread-based MPM; Notably PHP would refuse to start. # Path to the Apachectl script, server binary, and short-form for messages. Apachectl=/usr/local/apache/bin/apachectl httpd=${httpd-/usr/local/apache/bIN/HTTPD} prog=httpd Pidfile=${pidfile-/var/run/httpd.pid} lockfile=${lockfile-/var/lock/subsys/httpd} RETVAL=0 Start () {echo-n $ "starting $prog:" lang= $HTTPD _lang daemon--pidfile=${pidfile} $httpd $OPTIONS retval=$? echo [$RETVAL = 0] && Touch ${lockfile} return $RETVAL} stop () {echo-n $ "stopping $prog:" Killproc-p ${PIDF ile}-D $httpd retval=$? echo [$RETVAL = 0] && rm-f ${lockfile} ${pidfile} reload () {echo-n $ "reloading $prog:" If! lang= $HTTPD _lang $httpd $OPTIONS-T >&/dev/null; Then retval=$? echo $ ' not reloading due to configuration syntax error ' failure $ ' not reloading $HTTPD due to configuration syntax error ' else killproc-p ${pidfile} $httpd-hup retval=$? Fi echo} # and how we were called. Case "in Start" start;; stop) stop;; Status) status-p ${pidfile} $httpd retval=$?;; restart) stop start;; Condrestart) if [f ${pidfile}]; Then stop start fi;; reload) reload;; Graceful|help|configtest|fullstatus) $apachectl $@Retval=$?;; * echo $ "Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}" Exit 1 ESAC Exit $RETVAL

Nineth Step: Install MySQL

From the above order can be seen, we are going to demonstrate the MySQL installation process, here we first use the 5.5 version is how to install, back to the 5.6 installation process. You want to demo to the official MySQL website to download (www.mysql.com). Here's how to start the installation. This time we can extract "official requirements: But we have to put MySQL under the/usr/local, and the directory name must also be MySQL", compressed past, we are renaming or using the connection? Here is the best connection, This version number and the platform are reserved for the character creators, and it is easy to identify what version is being used.

[Root@localhost ~]# tar xf mysql-5.5.28-linux2.6-i686.tar.gz-c/usr/local ### #由于包有点大所以速度有点慢 [root@localhost local]# LN- SV Mysql-5.5.28-linux2.6-i686/mysql ### #创建连接

For us, to initialize MySQL, we're going to use the MySQL user MySQL group, and we can't let it log in (no home directory).

In fact, there is a file in MySQL is install-binary, this document explains how to install, here for you to explain, below to show you how to install MySQL.

Here we can change the permissions of MySQL, change the permissions after we look at the scripts the following script, the script is initialized, there are many options, there is an option is-datadir=path, we want to save the data in another place, We use the RPM package to install the default in/var/lib/mysql. We install MySQL in an edited way, which defaults to the/usr/local/mysql/data below. It's not a good choice if we put the data under the Software installation path. We're going to give it another path, and we know that the data is getting bigger, and we'd better put it in a logical volume, so that when the data is large we can continue to store the data in a way that expands the logical volume. Here we first create a 20G logical partition and set it to the logical volume type.

[Root@localhost mysql]# chown-r mysql.mysql/usr/local/mysql/* [root@localhost mysql]# FDISK/DEV/SDA [root@localhost my sql]# pvcreate/dev/sda5 ### #创建物理卷 [root@localhost mysql]# vgcreate myvg/dev/sda5 ### #创建卷组 [root@localhost mysql]# Lvcrea Te-n mydata-l 5G myvg ### #创建5G的逻辑卷 [root@localhost mysql]# mke2fs-j/dev/myvg/mydata ### #格式化为ext3格式 [root@localhost Mys ql]# mkdir/mydata ### #创建文件夹 [root@localhost mysql]# vim/etc/fstab ### #开机自动挂载/dev/myvg/mydata/mydata ext3 defaults 0 0 [Root@localhost mysql]# Mount–a

If you use MyData as a data directory, all future files will be placed directly on this partition, in order to facilitate management we are building a subdirectory data. Its owner group should be MySQL, but it is now root, so we have to change the owner group. and other users are not allowed to view them at random.

[Root@localhost mysql]# mkdir/mydata/data [root@localhost mysql]# chown-r mysql.mysql/mydata/data ### #更改属主, Group [Root@lo Calhost mysql]# chmod o-rx/mydata/data ### #更改其他用户的权限

This time we can execute the script and initialize it. For security reasons, we will change the owner under MySQL to root after initialization is complete. "Hint: If you are using the default data, then you have to change the owner of data to MySQL, and we created the file to store the data, so there is no need to change the"

[Root@localhost mysql]# scripts/mysql_install_db--user=mysql--datadir=/mydata/data [root@localhost mysql]# chown-r root/usr/local/mysql/*

Tenth step: Start MySQL

We have no script at this time, so we can't use service mysqld start. But MySQL provides us with the script, under Support-files there is a file called Mysql.server, this is its script, we just have to copy it to the past on the line.

This time we can not start MySQL, because we have not set up the configuration file, MySQL to find a profile when the first to find/etc/my.cnf, and then to find/ETC/MYSQL/MY.CNF, find out here also to find $BNSEDIR/MY.CNF. Someone asked $bnsedir what is it? In general, it is your installation directory. Below also go to find ~/.MY.CNF. What if there is a conflict after the search? Here is the last one (the latter will overwrite the previous one). We go to the Support-files directory to select a profile, where we have to choose the right one, and we'll take the right example, and we'll see if the memory in the file is our proper memory. Here we choose MY-LARGE.CNF, because our memory is 512M, so we chose it here. Then we copy it to the/etc/and name it my.cnf, and then edit the configuration file. Finally, start Serice mysqld start.

[Root@localhost mysql]# cp support-files/my-large.cnf/etc/my.cnf [root@localhost mysql]# vim/etc/my.cnf

[root@localhost mysql]# Service mysqld start

We compile the server side and the client MySQL is installed, we have the MySQL here the binary also installed, but can not find, so we want to give it a path so on line, here we login to MySQL, the results are as follows.

[Root@localhost mysql]# vim/etc/profile.d/mysql.sh

Export path= $PATH:/usr/local/mysql/bin

11th Step: Install PHP

Here we start to install PHP, we go to PHP's official website (http://php.net/downloads.php) Download installation package, PHP has a lot of features to rely on your system on some features, it can give us dynamic generation of pictures, but it depends on the image library, If there is no picture library on the current system, it will not be able to use this feature. Here we first decompression, after decompression we can configure.

[Root@localhost ~]# tar xf php-5.4.13.tar.bz2 [root@localhost ~]# CD php-5.4.13

[Root@localhost php-5.4.13]#./configure--prefix=/usr/local/php--with-mysql=/usr/local/mysql--with-openssl-- With-mysqli=/usr/local/mysql/bin/mysql_config--enable-mbstring--with-freetype-dir--with-jpeg-dir--with-png-dir --with-zlib--with-libxml-dir=/usr--enable-xml--enable-sockets--with-apxs2=/usr/local/apache/bin/apxs-- With-mcrypt--with-config-file-path=/etc--with-config-file-scan-dir=/etc/php.d--with-bz2--enable-maintainer-zts

Detailed:--prefix=/usr/local/php ### #安装目录--with-mysql=/usr/local/mysql ### #mysql的位置--with-openssl ### #是否支持openssl功能- -with-mysqli=/usr/local/mysql/bin/mysql_config ### #php与mysql交互的另一个接口 (is a binary program)--enable-mbstring ### #支持中文 ( Languages not represented by a single byte)--with-freetype-dir ### #支持fretype功能 (Fretype is implementing a reference to a different font)--with-jpeg-dir ### #支持jpg格式的图片--with-png-dir ### #支持png格式的图片--with-zlib ### #支持通用格式的压缩库--with-libxml-dir=/usr ### #xml的库的位置--enable-xml ### #支持扩展标记语言--enable-sockets ### #支持基于套接字的通信--with-apxs2=/usr/local/apache/bin/apxs ### #将它编译成apache的模块--with-mcrypt ### #支持加密功能的- With-config-file-path=/etc ### #php文件存放的目录 (primary configuration file is php.ini)--WITH-CONFIG-FILE-SCAN-DIR=/ETC/PHP.D The main configuration file has many fragments placed in the location (format is. ini)--with-bz2 ### #支持压缩库--enable-maintainer-zts ### #主要取决于apache的类型 (for Prefork not, Use event or worker needed) if Apache works in a threaded fashion it must be compiled into this format

There may be an error after execution, because it relies on other library files that do not exist, and here we resolve the dependencies manually. We looked at the picture error, it said you did not install MCrypt-related packages, can not be encrypted. There are two solutions: first, does not apply the encryption function to the--with-mcrypt. Second, the use of encryption, the installation of MCrypt-related packages. We use the second plan here. Here we need to install four packages, one is Mhash, one is Mhash-devel, one is Libmcrypt, the last one is libmcrypt-devel.

These packages go to rpmfind.net above the search, there are many versions, we selected here is mhash-0.9.2-6.el5.i386.rpm and mhash-devel-0.9.2-6.el5.i386.rpm. Then we download the LIBMCRYPT-2.5.7-5.EL5.I386.RPM,LIBMCRYPT-DEVEL-2.5.7-5.EL5.I386.RPM software package on the Internet and unzip it. Once the decompression is complete, we can execute it again./configure. Once the execution is complete, we can make and makes install.

12th Step: Provide the configuration file

PHP's configuration file is unique in/etc/php.ini. php-5.4.13 There are two files, one is php.ini-development user development environment, the other is php.ini-production for production environment. We use in the production environment, copy the php.ini-production to the/etc/and name it/php.ini. Let's talk about how to make Apache and PHP work together. Mainly modify the Apache configuration file to achieve. Edit Apache configuration file, let Apache process the PHP end of the page file, since we can support PHP, our homepage should also have the end of PHP page.

[Root@localhost php-5.4.13]# cp Php.ini-production/etc/php.ini [root@localhost php-5.4.13]# vim/etc/httpd/httpd.conf

Below we will go to the Web page default directory, and then modify index.html, change to index.php format. Then edit the content, we use PHP to connect to MySQL, and then test, we are in the MySQL shutdown (service mysqld stop) and then in the test.

[Root@localhost ~]# Cd/usr/local/apache/htdocs [root@localhost htdocs]# mv index.html index.php [root@localhost htdocs] # vim index.php

[root@localhost ~]# service mysqld Stop

13th Step: Configure XCache

Here's how we can get our PHP to support the virtual host, but before we support the virtual host, let's get our PHP to use XCache to speed up PHP and Opcod. Here we download the right, we have done the Internet downloading (http://xcache.lighttpd.net/). We are using the xcache-2.0 version here. XCache installation is unique, because XCache is the PHP module is exactly the extension of PHP, we first need to use PHP command to load this extension, to identify this extension. Phpize means to have an extension ready for compilation. Php-config is a "hint that you can get configuration information for PHP and the information you use at compile time: only support xcache2.0 and later versions of php-5.4 work together"

[Root@localhost ~]# tar xf xcache-2.0.0.tar.bz2 [root@localhost ~]# cd xcache-2.0.0 [root@localhost xcache-2.0.0]# Ocal/php/bin/phpize "Hint: Almost all extensions should execute this command before installing. "[Root@localhost xcache-2.0.0]#./configure--enable-xcache--with-php-config=/usr/local/php/bin/php-config-- Enable-xcache ### #启用xcache功能--with-php-config=/usr/local/php/bin/php-config ### #php的配置命令 [root@localhost xcache-2.0.0]# make

After the installation is complete, a file called Xcache.ini is generated under the xcache-2.0.0 directory. If PHP is able to support the XCache feature, it means that XCache configuration information must be provided to PHP. So we're going to append Xcache.ini to PHP, or the diameter of the Xcache.ini directly copied to the PHP.D below, but this PHP.D directory is we created manually, after the copy is done we have to edit, we only put the commonly used to list out, we should restart to take effect, here to restart the web , because its modules are loaded by the web. We also need to add a "phpinfo ()" In/usr/local/apache/htdocs/index.php, and we're testing it so that xcache work.

[Root@localhost xcache-2.0.0]# MKDIR/ETC/PHP.D [root@localhost xcache-2.0.0]# cp XCACHE.INI/ETC/PHP.D [root@localhost xcache-2.0.0]# Vim/etc/php.d/xcache.ini

[Xcache.admin] ### #xcache的管理功能 xcache.admin.enable_auth = on ### #管理功能认证打开 xcache.admin.user = "MOo" ### #管理用户是什么; Xcache.admin.pass = MD5 ($your _password) ### #用md5加密的方式加密码 xcache.admin.pass = "" ### #管理密码是什么 xcache.shm_scheme = "Mmap" # # #使用哪种方式来共享内存, "mmap" Memory mappings (one memory can allow multiple processes to access simultaneously) Xcache.size = 60M ### #用于缓存opcode代码的空间有多大 (modifiable) Xcache.count = 1 # Set your number of CPUs xcache.slots = 8K ### #在缓存当中, there are several slots to cache opcode, and how big each slot is Xcache.ttl = 0 ### #过期时间, 0 means never expire xcache.gc_interval = 0 # When it's out of date, how long does our garbage collector work, 0 means never work?

[root@localhost xcache-2.0.0]# service httpd restart Root@localhost xcache-2.0.0]# index.php

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.