I've been studying lamp recently and want to write about what I've learned. Talk not much, go straight to the subject.
The software I used to build the platform is the latest version, and the Linux distribution I use is RHEL6, and I will build the httpd server, MySQL server and PHP in sequence. (Note that the installation order here is best not to change, because installing PHP later requires specifying the installation path for MySQL)
1), Build httpd server
1, before the installation of HTTPD preparation work:
Install Apr (Apache portable Runtime,apache Portable Runtime Environment) and Apr-util Toolkit, the versions used here are apr-1.5.2 and apr-util-1.5.4, respectively:
(1) Create the APR and Apr-util installation directories separately:
# Mkdir/usr/local/{apr,apr-util}
(2) Unzip the APR-1.5.2.TAR.BZ2, configure the installation to install Apr:
# tar XVJF apr-1.5.2.tar.bz2
# CD apr-1.5.2
#./configure--PREFIX=/USR/LOCAL/APR
# Make && make install
(3) Similarly, unzip the APR-UTIL-1.5.4.TAR.BZ2, configure the installation path to specify APR, compile the installation:
# tar XVJF apr-util-1.5.4.tar.bz2
# CD apr-util-1.5.4
#./configure--prefix=/usr/local/apr-util--WITH-APR=/USR/LOCAL/APR
# Make && make install
At this point, the preparation for the installation of httpd is complete.
2, installation httpd:
(1) Create the HTTPD installation directory:
# Mkdir/usr/local/apache
(2) Decompression httpd-2.4.16.tar.bz2, configure the installation of httpd (install httpd when more configuration options, according to their actual needs to make appropriate changes):
# tar XVJF httpd-2.4.16.tar.bz2
# CD httpd-2.4.16
#./configure--prefix=/usr/local/apache--enable-modules=all--enable-mods-shared=most--enable-so--enable-deflate --enable-ssl--enable-mpms-shared=all--enable-cgi--enable-cgid--with-apr=/usr/local/apr--with-apr-util=/usr/ Local/apr-util--sysconfdir=/etc/httpd--enable-rewrite--with-mpm=event
# Make && make install
After the installation is complete, the httpd.conf configuration file is generated in the/etc/httpd/directory, and the httpd can be configured to suit your needs.
3, add httpd service to the system:
(1) The HTTPD service scripts that were previously installed (previously not installed httpd can be installed through the Yum tool and the Red Hat installation CD, as well as to avoid confusion and, as far as possible, uninstall the previously installed httpd software) to make appropriate modifications to the/etc/init.d/ The three lines in the HTTPD service script are modified as follows:
Apachectl=/usr/local/apache/bin/apachectl
HTTPD=${HTTPD-/USR/LOCAL/APACHE/BIN/HTTPD}
Pidfile=${pidfile-/usr/local/apache/logs/httpd.pid}
(2) Add httpd service to boot boot list:
# chkconfig--add httpd
Set the HTTPD service as needed by default at which operating level the system starts;
# chkconfig--list httpd
# chkconfig--level 2345 httpd on
# chkconfig--list httpd
At this point, you can start the HTTPD server with the service command:
# service httpd Start
Open the browser, enter the host IP address where the HTTPD server is located, when you see "It works!" The title of the page (the HTML document displayed in the/usr/local/apache/htdocs directory) indicates that our httpd server is working properly.
If you encounter a situation where the page cannot be opened, you can try to turn the SELinux function off and the Iptables module to unload.
2), install MySQL server
1, before the installation of MySQL preparation work:
Because the MySQL server needs to maintain a large amount of data, it is best to put the MySQL data on the logical volume, the advantage is that if there is insufficient storage space, convenient to expand at any time.
(1) Create a MySQL data storage directory:
# MKDIR/MYSQL_DATA/DATA-PV
(2) Create an available logical volume (select an idle disk partition, or partition an existing disk to get a new partition and modify the partitioning class to LVM, here I take/dev/sdb3 as an example):
# PVCREATE/DEV/SDB3
# vgcreate MYVG/DEV/SDB3
# lvcreate-n Mysql_lv-l 5G MYVG
(3) Format the logical volume and mount it to the MySQL data storage directory:
# mke2fs-j/DEV/MYVG/MYSQL_LV
The logical volume to be mounted is written to the/etc/fstab file, and the logical volume is automatically mounted to the MySQL data storage directory at the start of the system, and the following line is added to the/etc/fstab file:
/dev/myvg/mysql_lv/mysql_data ext3 defaults 0 0
Then execute the command to mount all the file systems defined in/etc/fstab, including the logical volume/DEV/MYVG/MYSQL_LV:
# mount-a
At this point, the task of creating and mounting a logical volume is complete.
Another preparation before installing MySQL is to create the system user MySQL, which is responsible for starting and running the MySQL service. So:
(4) Create the system user MySQL and the user group to which it belongs:
# groupadd-r MySQL
# useradd-r-G MySQL MySQL
(5) Modify the host group and permissions of the MySQL data storage directory (no other users are free to access):
# chown Mysql:mysql/mysql_data/data
# chmod 750/mysql_data/data
At this point, the preparation before installing MySQL is complete.
2. Install MySQL:
(1) Extract the mysql-5.6.26-linux-glibc2.5-i686.tar.gz compressed package directly into the/usr/local/directory (note: Choose the version of MySQL software must be consistent with their own version of the system, Failure to do so may cause problems initializing the database):
# tar Xvzf mysql-5.6.26-linux-glibc2.5-i686.tar.gz-c/usr/local
(2) Create a soft link link to the extracted/usr/local/mysql-5.6.26-linux-glibc2.5-i686 directory, in order to retain the MySQL version number, in the future can be directly operated on the/usr/local/mysql directory:
# Ln-sv/usr/local/mysql-5.6.26-linux-glibc2.5-i686/usr/local/mysql
(3) Modify the main genus of all the files in the/usr/local/mysql directory to enhance the security of the database files:
# Cd/usr/local/mysql
# chown-r Root:mysql./*
(4) Initialize the MySQL database:
#./scripts/mysql_install_db--user=mysql--datadir=/mysql_data/data
(5) Copy the MySQL service script and configuration file:
# CP Support-files/mysql.server/etc/init.d/mysqld
# CP my.cnf/etc/
(6) If you imagine using the commands provided by MySQL normally, you will need to export the path of the command provided by MySQL in the form of the PATH environment variable, and the system will be able to recognize the commands provided by MySQL:
# vim/etc/profile.d/mysql.sh
Add the following to the file:
Export $PATH =path:/usr/local/mysql/bin
(7) You can start the MySQL service next, but there is one key thing to do before starting the service, which is to add an entry to the MySQL configuration file:
# VIM/ETC/MY.CNF
Add a line: Datadir=/mysql_data/data
(8) The MySQL service can be started next
# service Mysqld Start
The "NETSTAT-TUNLP" command can be used to verify that the MySQL server is working, listening on Port 3306, and adding the password for MySQL database administrator root (note: Not system administrator root) to log in to the database. At this point, the task of installing MySQL is complete.
3), install PHP:
1, before the installation of PHP preparation work:
Because the MCrypt module is required to install the PHP process, the Libmcrypt and Mhash and their development libraries need to be installed, where libmcrypt-2.5.7-5.el5.i386.rpm, Four RPM packages such as libmcrypt-devel-2.5.7-5.el5.i386.rpm, mhash-0.9.2-6.el5.i386.rpm and mhash-devel-0.9.2-6.el5.i386.rpm. The installation process is simple:
# RPM-IVH *.rpm
2. Install PHP:
(1) Create the PHP installation directory:
# mkdir/usr/local/php
(2) Unzip the PHP source package, configure PHP and httpd server to work together (here PHP in the way compiled into a httpd module to work), compile and install:
# tar XVJF php-5.6.12.tar.bz2
# CD php-5.6.12
#./configure--prefix=/usr/local/php/--with-apxs2=/usr/local/apache/bin/apxs--with-config-file-path=/etc/-- WITH-CONFIG-FILE-SCAN-DIR=/ETC/PHP.D--with-jpeg-dir--with-png-dir--enable-mbstring--with-mcrypt--with-mysql=/ Usr/local/mysql--with-openssl--with-mysqli=/usr/local/mysql/bin/mysql_config--with-freetype-dir--with-zlib-- with-libxml-dir=/usr/--enable-xml--enable-sockets--with-bz2--enable-maintainer-zts
# Make && make install
(3) Copy the PHP configuration file (Note: The copied file is the source directory of the Php.ini-production file, not the installation directory, the other installation directory does not exist in this file):
# CP Php.ini-production/etc/php.ini
(4) To enable httpd to work with PHP, you need to configure HTTPD to support the dynamic page ending in. php, so you need to edit the httpd configuration file httpd.conf:
# vim/etc/httpd/httpd.conf
Find the line with the word "AddType" and add two lines after that:
AddType application/x-httpd-php. php
AddType Application/x-httpd-php-source. Phps
In addition, find a line with the word "directoryindex", configuration httpd can support. PHP end of the main page, add index.php to the line, that is, DirectoryIndex index.php index.html
With this in hand, the httpd and PHP configuration work is done, and the next step is to/usr/local/apache/ Htdocs directory to add a index.php page, restart the httpd service, open the browser input host IP address to test whether PHP can work and httpd,mysql,php can work together.
< attached: index.php test script >
<title>www.hello.com</title>
<?php
$value =mysql_connect (' localhost ', ' root ', ' password '); #此处的password为root在localhost主机上登录mysql数据库的密码;
if ($value)
echo "Successful ...";
Else
echo "Failed ...";
?>
This article is from the "struggle more than" blog, please be sure to keep this source http://fdbz1024.blog.51cto.com/10435362/1685139
Build lamp Platform (a) (software version: httpd-2.4.16,php-5.6.12,mysql-5.6.26)