0 x01 PHP installation

1. Install third-party software libraries first

yum install epel-release
Copy the code

2. Install dependency packages

yum install gcc gcc-c++ glibc libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel
Copy the code

3. Download PHP source code

Download PHP – 5.6.30. Tar. Gz

4. Compile & install

./configure --prefix=/usr/local/php  --enable-fpm --with-mcrypt --enable-mbstring --enable-pdo --with-curl --disable-debug  --disable-rpath --enable-inline-optimization --with-bz2  --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --with-mhash --enable-zip --with-pcre-regex --with-mysql --with-mysqli --with-gd --with-jpeg-dir --with-freetype-dir --enable-calendar
make
make install 
Copy the code

5. Provide configuration files for PHP

cp php.ini-production /usr/local/php/lib/php.ini
Copy the code

6. Provide configuration files for PHP-FPM

cd /usr/local/php
cp etc/php-fpm.conf.default etc/php-fpm.conf
vim etc/php-fpm.conf
Copy the code

Modify the following

pm.max_children = 150
pm.start_servers = 8
pm.min_spare_servers = 5
pm.max_spare_servers = 10
pid = /usr/local/php/var/run/php-fpm.pid 
Copy the code

7. Start php-fpm

Run the following command:

/usr/local/php/sbin/php-fpm
Copy the code

Verify with the following command (if this command outputs more than one phP-fpm process, it started successfully) :

ps aux | grep php-fpm
Copy the code

0 x02 install nginx

1. Install dependency packages

yum install gcc automake autoconf libtool make gcc-c++ readline readline-devel pcre pcre-devel opemssl openssl-devel zlib zlib-devel
Copy the code

2. Download the source code

To facilitate later development, Nginx uses OpenResty

3. Compile & install

./configure --prefix=/usr/local/openresty/nginx --sbin-path=/usr/local/openresty/nginx/sbin/nginx --conf-path=/usr/local/openresty/nginx/nginx.conf --pid-path=/usr/local/openresty/nginx/nginx.pid --with-http_ssl_module  --with-http_flv_module --with-http_mp4_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi make make installCopy the code

4. Nginx and PHP-FPM integration

Edit the file/usr/local/openresty/nginx/nginx. Conf, “#” to remove the following content, the results are as follows:

log_format  main  '$remote_addr - $remote_user [$time_local] "$request"'
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

access_log  logs/access.log  main;

    location / {
        root   html;
        index  index.html index.htm;
    }

    location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0. 01.:9000;
        fastcgi_index  index.php;
        #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
        #include fastcgi_params;
        include        fastcgi.conf;
    }
Copy the code

Reload the nginx configuration file

/usr/local/openresty/nginx/sbin/nginx -s reload
Copy the code

5. Test PHP files

In the/usr/local/openresty/nginx/HTML created under the index. The PHP file, enter the following content


      
    phpinfo();
? >
Copy the code

To see PHP information, visit http:// your server IP /index.php.

Firewall policies must be enabled for non-local access

Firewall-cmd --zone=public --add-port=80/ TCP --permanent (--permanent takes effect permanently. If this parameter is not specified, it will become invalid after restart.) firewall-cmd --reloadCopy the code

0 x03 mysql installation

1. Download the installation package

Download mysql – 5.7.16 – Linux – glibc2.5 – x86_64. Tar

2. Check whether the library file exists and delete it.

The RPM - qa | grep mysql mysql - libs - 5.1.52-1. El6_0. 1. X86_64 RPM -e mysql - libs - 5.1.52. X86_64 -- nodepsCopy the code

3. Check whether the mysql group and user exist.

cat /etc/group | grep mysql
mysql:x:490:
cat /etc/passwd | grep mysql
mysql:x:496:490::/home/mysql:/bin/bash
Copy the code

The preceding information exists by default. If no, run the following command:

Groupadd mysql useradd -r -g mysql mysql //useradd -r Indicates that the mysql user is a system user and cannot be used to log in to the system.Copy the code

4. Decompress the TAR package and change the owning group and user

CD /usr/local/tar XVF mysql-5.7.12-linux-glibc2.5-x86_64.tar ls -l tar XVFZ mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz Mv mysql-5.7.12-linux-glibc2.5-x86_64 mysql chown -r mysql mysql/ CHGRP -r mysql mysql/ CD mysql/Copy the code

5. Install the database

bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
Copy the code

This parameter is required if the default installation path is changed

/etc/my. CNF /etc/init.d/mysqld/basedir='/apps/mysql'
    datadir='/apps/mysql/data'2. Create ln mkdir -p /usr/local/mysql/bin
    ln -s /apps/mysql/bin/mysqld /usr/local/mysql/bin/mysqld`
Copy the code

Initialize the database

cp -a ./support-files/my-default.cnf /etc/my.cnf
cp -a ./support-files/mysql.server  /etc/init.d/mysqld
cd bin/
./mysqld_safe --user=mysql &

/etc/init.d/mysqld restart
Copy the code

7. Set boot

chkconfig --level 35 mysqld on
Copy the code

8. Initialize the password

Mysql5.7 generates an initial password, whereas in previous versions you didn’t need to log in for the first time.

cat /root/.mysql_secret 
./mysql -uroot -p
Enter password: 
mysql> SET PASSWORD = PASSWORD('* * * * * * * *');
mysql> flush privileges;/etc/init.d/mysqld restartCopy the code

0x04 Add PDO extension

Some vulnerability environment (DVWA) database connections are converted to PDO, which can be installed if not already installed.

Go to ext/ pDO_mysql in the PHP source package and follow these steps.

/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
make
make install
Copy the code

/usr/local/mysql = /usr/local/mysql = /usr/local/mysql = /usr/local/mysql = /usr/local/mysql = /usr/local/mysql

Modify the configuration file php.ini

Open and add

extension=pdo_mysql.so
extension=pdo.so
Copy the code

Restart PHP – FPM