First, uninstall the system pre-installed lamp software
rpm-qa| grep -E httpdhttpd--qa| grep -e mysqlmysql--qa| grep -E php-mysql php-cli php-gd php-common phpyum -y remove httpd*yum -y remove Mysql-s erver MySQL mysql-libsYum -y remove php*
Second, add users
Add Users and user groups www and mysql, and disable login.
WWW user is mainly used to give Nginx and PHP execute permissions, MySQL is mainly given to MySQL permissions, prohibit login is to prevent users have permission to operate www and MySQL, all for security!
1 Groupadd www 2 useradd-s/sbin/nologin-g www www3groupadd mysql4 useradd-s/sbin/ nologin-g MySQL MySQL
Third, add the pre-install package
Yum Install GCC gcc-c++ libxml2 libxml2-devel pcre pcre-devel OpenSSL openssl-devel Curl curl-devel libjpeg libjpeg-devel LIBP ng Libpng-devel freetype freetype-devel libicu libicu-devel cmake ncurses ncurses-devel
I usually put the installation package in the/USR/LOCAL/SRC directory, so first execute the following command
Cd/usr/local/src
First install the Libmcrypt package if the following bad use, please visit this URL to download: https://sourceforge.net/projects/mcrypt/...
cd/usr/local/srcwget-C http://soft.vpser.net/web/libmcrypt/libmcrypt-2.5.8.tar.gzTarZXVF libmcrypt-2.5.8.Tar. GZCD Libmcrypt-2.5.8./Configure Make&& Make Install/sbin/LDCONFIGCD Libltdl/./configure--enable-ltdl-Install Make&& Make InstallLN-sf/usr/local/lib/libmcrypt.la/usr/lib/libmcrypt.laLN-sf/usr/local/lib/libmcrypt.so/usr/lib/libmcrypt.soLN-sf/usr/local/lib/libmcrypt.so.4/usr/lib/libmcrypt.so.4LN-sf/usr/local/lib/libmcrypt.so.4.4.8/usr/lib/libmcrypt.so.4.4.8Ldconfig
Iv. installation of Nginx
I'm installing using nginx-1.9.12.
cd/usr/local/srcwget-C http://nginx.org/download/nginx-1.9.12.tar.gzTarZXVF nginx-1.9. A.Tar. GZCD Nginx-1.9. A#nginx1.9. 5 before #./configure--prefix=/usr/local/nginx--user=www--group=www--without-mail_pop3_module--without-mail_imap_module-- Without-mail_smtp_module--with-http_ssl_module--with-pcre--with-http_stub_status_module--with-http_spdy_module --with-http_gzip_static_module--with-ipv6--with-http_sub_module#nginx1.9. After 5 (contains 1.9.5) #./configure--prefix=/usr/local/nginx--user=www--group=www--without-mail_pop3_module--without-mail_imap_module-- Without-mail_smtp_module--with-http_ssl_module--with-pcre--with-http_stub_status_module--with-http_v2_module-- With-http_gzip_static_module--with-ipv6--with-Http_sub_module Make&& Make Install
./configure parameter Explanation:
--prefix=/usr/local/Nginx #nginx的安装路径--user=www #设置nginx工作进程的用户--group=www #设置nginx工作进程的用户组--without-mail_pop3_module #禁用nginx处理/Proxy POP3 Protocol--without-mail_imap_module #禁用nginx处理/Agent IMAP Protocol--without-mail_smtp_module #禁用nginx处理/Proxy SMTP Protocol--with-Http_ssl_module #使用https协议--with-pcre #启用pcre库, support rewrite--with-Http_stub_status_module #提供查看服务器统计信息的能力--with-http_v2_module #提供HTTP/2 service. From NGINX1.9.5 started, Http_v2_module has replaced Http_spdy_module. So the previous version of the installation replaced the parameter with--with-Http_spdy_module (Start spdy support, Spdy can shorten the load time of Web pages, but must use the SSL transport Protocol)--with-http_gzip_static_module #启用预压缩 (gzip) is supported--with-IPv6 #支持ipv6访问--with-http_sub_module #启用过滤器支持
To start the Nginx command:
/usr/local/nginx/sbin/nginx
V. Installation of PHP
cd/usr/local/srcwget-C http://cn2.php.net/distributions/php-7.0.4.tar.gzTarZXVF php-7.0.4.Tar. GZCD php-7.0.4./configure--prefix=/usr/local/php--with-config-file-path=/usr/local/php/etc--enable-fpm--with-fpm-user=www--with-fpm-group=www--enable-mysqlnd--with-mysqli= Mysqlnd--with-pdo-mysql=mysqlnd--with-iconv-dir--with-freetype-dir=/usr/local/freetype--with-jpeg-dir--with-png-dir--with-zlib--with-libxml-dir=/USR--enable-xml--disable-rpath--enable-bcmath--enable-shmop--enable-sysvsem--enable-inline-optimization-- With-curl--enable-mbregex--enable-mbstring--enable-intl--enable-pcntl--with-mcrypt--enable-FTP--WITH-GD--enable-gd-native-ttf--with-openssl--with-mhash--enable-pcntl--enable-sockets--with-xmlrpc--enable-Zip--enable-soap--with-gettext--enable-fileinfo--enable-opcache--enable-session--with-fpm-user=www-- With-fpm-group=www--without-pear--enable-exif--enable-json--enable-PDO Make&& Make Install
This completes the installation of PHP. Next, create a soft connection:
LN -sf/usr/local/php/bin/php/usr/local/bin/php
Generate php.ini configuration file, there are two php.ini, suitable for development scenarios and production scenarios, you can choose a different configuration file according to the needs, generally choose the former
cp php.ini-development/usr/local/php/etc/php.ini #开发版本 CP php.ini-production/usr/local/ Php/etc/php.ini #生产版本
The PHP installation is now complete. The next step is to enable the PHP-FPM service.
First build the configuration file
mv /usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.confmv /usr/ Local/php/etc/php-fpm.d/www.conf.default/usr/local/php/etc/php-fpm.d/www.conf
Getting Started with PHP-FPM
CP /usr/local/src/php-7.0. 4/sapi/fpm/init.d.php-fpm/etc/init.d/php-fpmchmod +x/etc/init.d/php-fpmchkconfig PHP-fpm on
At this point, you can start php-fpm with the following command
Service PHP-FPM Start
After starting up, edit Nginx configuration file, implement Nginx proxy Access, find the following code:
vim/usr/local/nginx/conf/~ \.php$ {
# root html;
# Fastcgi_pass 127.0. 0.1:9000;
# Fastcgi_index index.php;
# Fastcgi_param script_filename /script$fastcgi_script_name;
# include fastcgi_params;
#}
Remove the previous # comment symbol, change the script to $document_root, and the second line of HTML to your project path, where I set the/home/www/default final code as follows:
Location ~ \.php$ { root /home/www/default; Fastcgi_pass 127.0. 0.1:9000; Fastcgi_index index.php; Fastcgi_param script_filename /$document _root$fastcgi_script_name; Include Fastcgi_params;}
After the modification is complete, execute the Nginx Configuration detection command and execute the Reload configuration file command If there is no error:
/usr/local/nginx/sbin/nginx-t #配置检测命令/usr/local/nginx/sbin/nginx-s Reload #动态加载配置命令
Let's go to the/home/www/default directory to create a PHP file. Browse to see if it works:
<? PHP Phpinfo ();? >
If we can display the current information of PHP correctly, it means that we have finished the more than half of the work.
VI. Install MySQL:
The boost package will be installed after the mysql5.7.5 version. So I chose to download the MySQL installation package that already comes with the boost installation package:
cd/usr/local/srcwget-C http://dev.mysql.com/get/downloads/mysql-5.7/mysql-boost-5.7.11.tar.gzTarZXVF mysql-boost-5.7. One.Tar. GZCD MySQL-5.7. One/CMake-dcmake_install_prefix=/usr/local/mysql-ddefault_charset=utf8mb4-ddefault_collation=utf8mb4_general_ci-dwith_ Innobase_storage_engine=1-dwith_archive_storage_engine=1-dwith_blackhole_storage_engine=1-dmysql_tcp_port=3306-dwith_boost=boost-denable_downloads=1 Make&& Make InstallChown-R Mysql:mysql/usr/local/mysql #对mysql目录进行赋予权限
MySQL Configure installation parameters explained:
-dcmake_install_prefix=/usr/local/mysql #指定安装路径-ddefault_charset=utf8mb4 #默认使用utf8mb4字符- ddefault_collation=utf8mb4_general_ci #校验字符-dwith_innobase_storage_engine=1-dwith_ archive_storage_engine=1 #安装archive存储引擎-dwith_blackhole_storage_engine=1 # Install the Blackhole storage engine -dmysql_tcp_port=3306 #指定端口-dwith_boost=BOOST #指定boost的安装位置- Denable_downloads #是否要下载可选的文件. For example, if you enable this option (set to 1), CMake will download the test suite that Google uses to run unit tests.
Generate MySQL configuration file
CP /USR/LOCAL/MYSQL/SUPPORT-FILES/MY-DEFAULT.CNF/ETC/MY.CNF
Initialize the database, this time initialization, the screen will appear the initial password, write down, if missed, you can view /root/.mysql_secret
to see the previous initialization password:
/usr/local/mysql/bin/mysqld--initialize--user=mysql
Copying files Mysql.server can be controlled using service commands
CP /usr/local/mysql/support-files/mysql.server/etc/init.d/mysqlservice mysql start #启动mysql
Login Database Change Password
/usr/local/mysql/bin/mysql-u root-p
Enter the password to return. After successful login, enter the following characters to change the password, such as my password is 12345:
Set password = password ('root');
Write a PHP program to test if MySQL is able to connect to MySQL properly:
<?php
$pdo New Array (Pdo::mysql_attr_init_command = ' Set names utf8mb4 ', pdo::attr_timeout = 1)); var_dump($pdo);? >
Build and install LNMP environment under CentOS