Linux (CentOS) LNMP Environment installation ____linux

Source: Internet
Author: User
Tags fpm gettext mysql manual openssl touch redis cli pkill redis server
LNMP environment installation
1. Installation dependency
Install the required development package using the yum program (the following is the standard RPM package name)
yum install gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel zlib-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel openssl-devel libxml2-devel gettext-devel pcre-devel mysql-devel net-snmp-devel curl-devel perl-DBI
1、 Compiling PHP
(1) Specify the PHP related configuration directory and expansion, enter the unpacked source package, and check the installation environment
./configure --prefix=/usr/local/php \
--exec-prefix=/usr/local/php \
--bindir=/usr/local/php/bin \
--sbindir=/usr/local/php/sbin \
--includedir=/usr/local/php/include \
--libdir=/usr/local/php/lib/php \
--mandir=/usr/local/php/php/man \
--with-config-file-path=/usr/local/php/etc \
--with-mysql-sock=/tmp/mysql.sock \
--with-mysqli \
--with-pdo-mysql \
--with-mcrypt=/usr/include \
--with-mhash \
--with-openssl \
--with-gd \
--with-iconv \
--with-zlib \
--enable-zip \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-curl \
--with-jpeg-dir \
--with-freetype-dir \
--enable-opcache \
--enable-fpm \
--without-gdbm \
--disable-fileinfo
(2)make & make install
3. Copy the configuration file (PHP. Ini development / PHP. Ini production) in the installation package to the directory / usr / local / PHP / lib
4. Modify PHP process file / etc / PHP fpm.conf.default = > etc / PHP fpm.conf
5. Start the PHP management process / usr / local / PHP / SBIN / PHP FPM
6. View the PHP process
[root@localhost php]# ps aux | grep php
root     14760  0.0  0.6 199736  6292 ?        Ss   15:36   0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
www      14761  0.0  0.5 199736  5744 ?        S    15:36   0:00 php-fpm: pool www
www      14762  0.0  0.5 199736  5748 ?        S    15:36   0:00 php-fpm: pool www
root     14764  0.0  0.0 103256   856 pts/1    S+   15:36   0:00 grep php
7. Set startup
(1) vi /etc/init.d/php-fpm
/bin/sh!
# chkconfig:   2345 15 95
# description:  PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation \
# with some additional features useful for sites of any size, especially busier sites.
# DateTime: 2016-09-20
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
phpfpm="/usr/local/php/sbin/php-fpm"
prog=$(basename ${phpfpm})
lockfile=/var/lock/subsys/phpfpm
Start () {
[ -x ${phpfpm} ] || exit 5
echo -n $"Starting $prog: "
daemon ${phpfpm}
Retval=$?
Echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
Stop () {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
Retval=$?
Echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
Restart () {
configtest || return $?
Stop
Start
}
Reload () {
configtest || return $?
echo -n $"Reloading $prog: "
killproc ${phpfpm} -HUP
RETVAL=$?
Echo
}
force_reload() {
Restart
}
configtest() {
${phpfpm} -t
}
rh_status() {
Status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
Case "$1" in
Start)
rh_status_q && exit 0
$1
;
Stop)
rh_status_q || exit 0
$1
;
restart|configtest)
$1
;
Reload)
rh_status_q || exit 7
$1
;
Status)
Rh_status
;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|configtest}"
Exit 2
ESAC
(2) Set the executable permission of PHP FPM file
chmod a+x /etc/init.d/php-fpm
(3) Add PHP FPM to the system boot management list
chkconfig --add /etc/init.d/php-fpm
(4) Set startup
chkconfig php-fpm on
(5) View the current PHP FPM startup status
chkconfig php-fpm status
Related error resolution
(1) Error when starting PHP process
[root@localhost php]# ./sbin/php-fpm
[06-Jan-2018 15:14:41] WARNING: Nothing matches the include pattern '/usr/local/php/etc/php-fpm.d/*.conf' from /usr/local/php/etc/php-fpm.conf at line 125.
[06-Jan-2018 15:14:41] ERROR: No pool defined. at least one pool section must be specified in config file
[06-Jan-2018 15:14:41] ERROR: failed to post process the configuration
[06-Jan-2018 15:14:41] ERROR: FPM initialization failed
terms of settlement:
[root@localhost php]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
(2) When starting the PHP process, an error is reported because
--with-fpm-user=www \
--With FPM group = www \ the existence of these two configuration items. These two configurations can also not be added. When installing
[06-Jan-2018 15:22:31] ERROR: [pool www] cannot get uid for user 'www'
[06-Jan-2018 15:22:31] ERROR: FPM initialization failed
Error reason: there are no www users and WWW groups in the system
terms of settlement:
[root@localhost php]# useradd www
[root@localhost php]# groupadd www
2、 Compile nginx
(1) Enter the nginx installation package directory, and remember to install PCRE (positive large expression library) before installation
. / configure -- prefix = / usr / local / nginx. After the installation, the directory is as follows
[root@localhost nginx-1.13.8]# cd /usr/local/nginx/
[root@localhost nginx]# ls
Conf HTML logs SBIN
Nginx related commands:
1. View the nginx process information: PS aux | grep nginx
[root@localhost nginx]# ps aux | grep nginx
root     17290  0.0  0.0  20476   656 ?        Ss   16:04   0:00 nginx: master process ./sbin/nginx
nobody   17291  0.0  0.1  20920  1256 ?        S    16:04   0:00 nginx: worker process
root     17293  0.0  0.0 103256   856 pts/1    S+   16:04   0:00 grep nginx
2. End the process
Kill - 9 [PID number]: Kill - 9 2789
Pkill - 9 [process name]: pkill - 9 http
Kill - int process No.: Kill - int 17290 = > kill the main process of nginx
/sbin/nginx -s stop
3. restart
./sbin/Nginx -s reload
kill -HUP `cat logs/nginx.pid`
4. Check whether the nginx configuration file has syntax errors
./sbin/nginx -t
5. Nginx related knowledge website: https://www.nginx.com/resources/wiki/start/topics/tutorials/commandline/
6. Set nginx startup
(1)vi /etc/init.d/nginx
/bin/sh!
Wei
# nginx - this script starts and stops the nginx daemon
Wei
# chkconfig:   - 85 15
# description:  NGINX is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /etc/nginx/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:.*--user=" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
if [ -n "$user" ]; then
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
Fi
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
Fi
Fi
Done
Fi
}
Start () {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
Make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
Retval=$?
Echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
Stop () {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
Retval=$?
Echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
Restart () {
configtest || return $?
Stop
Sleep 1
Start
}
Reload () {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
Echo
}
force_reload() {
Restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
Status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
Case "$1" in
Start)
rh_status_q && exit 0
$1
;
Stop)
rh_status_q || exit 0
$1
;
restart|configtest)
$1
;
Reload)
rh_status_q || exit 7
$1
;
force-reload)
Force_reload
;
Status)
Rh_status
;
condrestart|try-restart)
rh_status_q || exit 0
;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
Exit 2
ESAC
(2) Set / etc / init.d/nginx executable permissions
chmod a+x /etc/init.d/nginx
(3) Add nginx service to Linux system power on service management list
chkconfig --add /etc/init.d/nginx
(4) Setting nginx startup
chkconfig nginx on
(5) Check whether the system boot service nginx service is in it
Chkconfig
(6) View the status of nginx service
service nginx status
(7) Changing nginx States
service nginx stop/start/restart/reload/status
3、 PHP and nginx are integrated so that they can communicate with each other and modify the configuration file of nginx
PS: the port number of PHP FPM process is 9000, so it is 127.0.0.1:9000
location ~ \.php$ {
root           html;
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html/$fastcgi_script_name;
include        fastcgi_params;
}
4、 Compiling MySQL (MariaDB)
1. Unzip the tar installation package
2. Enter compilation parameters
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/etc \
-DWITHOUT_TOKUDB=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STPRAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWIYH_READLINE=1 \
-DWIYH_SSL=system \
-DVITH_ZLIB=system \
-DWITH_LOBWRAP=0 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
3. Compilation error
cc: Internal error: Killed (program cc1
Cause: insufficient system memory
Solve:
cc: internal compiler error: Killed (program cc1)
perhaps
g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
The main reason is that there is not enough memory. It's a bit difficult to use the swap partition temporarily. The swap partition uses the disk partition as virtual memory. After using it, delete the virtual partition
Create swap swap partition
dd if=/dev/zero of=/swapfile bs=64M count=16
mkswap /swapfile
swapon /swapfile
Here is the memory usage during the make command
Compilation process.......................
Turn off swap partition when finished
swapoff /swapfile
RM /swapfile
4. Use the 'MySQL' user to execute the script and install the database to the database storage directory
[root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysql
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:
'./bin/mysqladmin' -u root password 'new-password'
'./bin/mysqladmin' -u root -h localhost password 'new-password'
Alternatively you can run:
'./bin/mysql_secure_installation'
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.
You can start the MariaDB daemon with:
cd '.' ; ./bin/mysqld_safe --datadir='/data/mysql'
You can test the MariaDB daemon with mysql-test-run.pl
cd './mysql-test' ; perl mysql-test-run.pl
5. Start MySQL
/etc/rc.d/init.d/mysqld start
6. In the development and test phase, remote login is required to connect to the database. At this time, a user can be authorized
mysql> GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
User name: a user in Linux system, or a user already existing in the user table inserted into MySQL database
Password: the setting of database client link database
7. Set MySQL startup
(1) Copy file and rename
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
(2) Add Mysql to the system self startup management list
chkconfig --add mysql
(3) Set on start
chkconfig mysql on
(4) Show service list
Chkconfig
(5) If you see MySQL service, and 3, 4, and 5 are all on, it succeeds. If it is off, type
chkconfig --level 345 mysql on
(6) View 3306 port
netstat -an | grep mysql
5、 Compiling redis
1. Download the source package: WGet http://download.redis.io/releases/redis-4.0.6.tar.gz
2. Unzip the source package: tar zxvf redis-4.0.6.tar.gz, enter the unzip directory
3. Redis source package has been compiled and configured, so you can make directly: make
4. Check the redis compilation and installation environment (optional): make test
5. Installation: make install prefix = / usr / local / redis redis installation directory optional
6. Copy the configuration file to the installation directory: CP / usr / local / SRC / redis-4.0.6/redis.conf/
7. Start redis:. / bin / redis server. / redis.conf
8. Connect to redis client:. / bin / redis cli
9. Set redis startup
(1) Edit file: VI / etc / init.d/redis
/bin/sh!
Wei
# chkconfig:   2345 90 10
# description:  Redis is a persistent key-value database
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli
PIDFILE=/var/run/redis_6379.pid
CONF="/usr/local/redis/redis.conf"
Case "$1" in
Start)
if [ -f $PIDFILE ]
Then
echo "$PIDFILE exists, process is already running or crashed"
Else
echo "Starting Redis server..."
$EXEC $CONF
Fi
;
Stop)
if [ ! -f $PIDFILE ]
Then
echo "$PIDFILE does not exist, process is not running"
Else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
Do
echo "Waiting for Redis to shutdown ..."
Sleep 1
Done
echo "Redis stopped"
Fi
;
*)
echo "Please use start or stop as first argument"
;
ESAC
(2) Set permissions for redis files
chmod 755 /etc/init.d/redis
(3) Add redis service to the system startup list
chkconfig --add redis
(4) Set startup
chkconfig redis on
(4) The redis related path in / etc / init.d/redis should be changed according to the actual environment

Related Article

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.