1. yum update #Update system
2. yum install gcc gcc-c++ autoconf automake cmake bison m4 libxml2 libxml2-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel #Install the packages that php, MySQL and Nngix depend on
3. Download the following package #I downloaded all source files in the root directory, readers can modify the source file storage directory by themselves
3.1 libmcrypt-2.5.8.tar.gz
3.2 mcrypt-2.6.8.tar.gz
3.3 mhash-0.9.9.9.tar.gz
3.4 zlib-1.2.8.tar.gz
Unzip and install as follows:
#tar -zvxf libmcrypt-2.5.8.tar.gz
#cd libmcrypt-2.5.8
#./configure
#make && make insatll
4. When installing software, if you are prompted that any dependent packages are not installed, you can execute yum install * -y (* indicates related packages)
1. Go to the official website http://nginx.org/en/download.html to download the most stable version of nginx-1.10.1.tar.gz
2. The compilation steps are as follows
1. Upload nginx-1.10.1.tar.gz to the /root directory through winSCP
1.1 groupadd -r nginx = 1.1 by groupadd -r nginx \ #Create new one without login permission nginx user
1.3 id nginx
2. tar -zvxf nginx-1.10.1.tar.gz
3. cd nginx-1.10.1
4. You can view the compilation configuration parameters through ./configure --help, or refer to http://nginx.org/en/docs/configure.html. The following parameters should be written in one line
./configure --prefix =/usr/local/nginx
--modules-path=/usr/local/nginx/modules
--with-http_ssl_module
--pid-path=/usr/local/nginx/nginx.pid
--user= nginx
--group=nginx
5. make && make install #Compile and install
6. Start nginx
6.1 cd /usr/local/nginx 6.2 sbin/nginx #Start, you can use sbin/nginx -? View nginx related operation commands
7. Create a new nginx.service file in the /usr/lib/systemd/system directory, so that you can operate nginx through systemctl stop|start|reload nginx.service. You can also refer to https://www.nginx.com/ resources/wiki/start/topics/examples/systemd/, the content is as follows:
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
PIDFile=/usr/local/nginx/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
3. Compile and install MySQL
2. The compilation steps are as follows
1. Use winSCP to upload mysql-boost-5.7.14.tar.gz to the /root directory
2. groupadd mysql
3. useradd -r -g mysql -s /bin/false mysql
4. Use cmake to compile mysql. For relevant parameters, please refer to https://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html. The following parameters should be written in one line
cmake -DCMAKE_INSTALL_PREFIX= /usr/local/mysql
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock
-DSYSCONFDIR=/usr/local/mysql/etc
-DSYSTEMD_PID_DIR=/usr/local/mysql
-DDEFAULT_CHARSET =utf8
-DDEFAULT_COLLATION =utf8_general_ci
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1
SQL_DATADIR=/usr/local/mysql/data
-DWITH_BOOST=boost
-DWITH_SYSTEMD=1
5. make && make install
6. Configure mysql and initialize the database
6.1 cd /usr/local/mysql 6.2 chown -R mysql . 6.3 chgrp -R mysql . 6. 6.4 cp /usr/ local/mysql/support-files/mysql.server /etc/init.d/mysqld .cnf #Configure my.cnf
6.5.1 Copy the following content to [mysqld] in the my.cnf file user = mysql
basedir = /usr/local/mysql
datadir = /usr /local/mysql/data
port = 3306
server_id = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
6.5 chkconfig mysqld on 6. 6 bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data #Initialize the database
6.7 bin/mysqld --user=mysql & #Start mysql, if reported Please read " Security" section of the manual to find out how to run mysqld as root!, just add user=root to my.cnf, which means starting as the root user
7. Modify the root user login password and allow the root user to log in remotely
7.1 mysql -u root --skip-password
7.2 ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
7.3 Allow the root user to log in remotely
7.3.1 use mysql;
7.3.3 flush privileges;
7.3.4 service mysqld restart
8. Solve the problem that service mysqld start|stop reports MySQL server PID file could not be found! or Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe). In fact, related errors can be solved by reading this file
8.1 chmod 777 /usr/local/mysql #Because I set the mysqld.pid file to be saved in the /usr/local/mysql directory, so make sure it has writable permissions
8.2 Modify the /etc/init.d/mysqld file through winSCP
8.2 .1 basedir=/usr/local/mysql #Manually specified
8.2.2 datadir=/usr/local/mysql/data #Manually specified
8.2.4 Replace all uncommented characters containing mysqld_safe in this file with mysqld
4. Compile and install php
1. Go to the official website http://php.net/downloads.php to download version php7.0.10
1. Use winSCP to upload php-7.0.10.tar.gz to the /root directory
3. Configure compilation php parameters. You can use the ./configure --help command to view all compilation configuration items. The following parameters should be written in one line
./configure
--prefix=/usr/local/php--exec- prefix=/usr/local/php
--datadir=/usr/local/php--with-config-file-path=/usr/local/php/etc
--with-mysqli=mysqlnd --with -pdo-mysql=mysqlnd
--with-fpm-user=nginx
--with-fpm-group=nginx
--with-gd
--with-iconv
--enable-mbstring
--enable-fpm
--enable-mysqlnd
4. make && make install #Compile and install
5. cd /usr/local/php #Enter the compilation directory
6. Modify related configuration files
6.1 cp /usr/local/php/etc/php.ini.default /usr/local/php/etc/php.ini 6.1 cp /usr/local/php/etc/php.ini.default /usr/local/php/etc/php.ini according to the project needs, the relevant configuration in php.ini should be modified by yourself. Configuration nginx supports php reference http://php.net/manual/zh/install.unix.nginx.php
6.3 cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php -fpm.d/www.conf #Modify user and group roughly at lines 23 and 24, such as: user = nginx, group = nginx
7. chmod 777 /usr/local/php/var/run #The default PID file is written in the directory /usr/local/php/var/run, so modify the directory permissions
8. sbin/php-fpm #Start php, you can view the related operation command list through sbin/php-fpm -h
9. Create a new php-fpm.service file in the /usr/lib/systemd/system directory, so that you can operate php-fpm through systemctl stop|start|reload php-fpm.service. The content is as follows:
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
Before=nginx.service
[Service]
Type=forking
PIDFile=/usr/local/php/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm
ExecStop=/bin/kill - QUIT `cat /usr/local/php/var/run/php-fpm.pid`
ExecReload=/bin/kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`
PrivateTmp =true
[Install]
WantedBy=multi-user.target
1. Use winSCP to upload redis-3.0.0.tar.gz to the /root directory
2. tar -zvxf redis-3.0.0.tar.gz -C /usr/local #Extract to the /usr/local directory
3. yum install tcl -y #redis-test depends on this package
4. cd /usr/local/redis-3.0.0
5. chmod 777 . #The current directory is writable. I assigned the redis.pid file to /usr/local/redis-3.0.0
6. make && make install
7. vi /usr/local/redis-3.0.0/redis.conf #Modify the redis configuration file
7.1 daemonize yes
7.2 pidfile /usr/local/redis/redis.pid
8. src/redis-server & #Start redis
src/redis-cli shutdown #Close redis
src/redis-server --help #View related help commands
9. Create a new redis.service file in the /usr/lib/systemd/system directory, so that you can operate redis through systemctl stop|start redis.service. The content is as follows:
[Unit]
Description=The Redis 3.0.0 Service
After=syslog.target
[Service]
Type=forking
PIDFile=/usr/local/redis/redis.pid
ExecStartPre=/usr/local/redis/src/redis-server /usr/local/redis/redis.conf
ExecStart=/ usr/local/redis/src/redis-server /usr/local/redis/redis.conf
ExecStop=/usr/local/redis/src/redis-cli shutdown
PrivateTmp=true
[Install]
WantedBy=multi-user.target
10. Install phpredis extension
10.1 Use winSCP to upload phpredis-3.0.0.tar.gz to the /root directory
10.2 tar -zvxf phpredis-3.0.0.tar.gz -C /usr/local #Extract to /usr /local directory
10.3 cd /usr/local/phpredis-3.0.0
10.4 /usr/local/php/bin/phpize
10.5 ./configure --with-php-config=/usr/local/php/bin /php-config
10.6 make && make install
10.7 Add extension=redis.so
in the php.ini file 10.8 Restart Nginx/Apache
10.9 Restart php-fpm
6. So far, the LNMP environment has been successfully set up under CentOS7.2 in my VirturBox