Home>Article>Backend Development> How to install and configure nginx mysql php

How to install and configure nginx mysql php

藏色散人
藏色散人 Original
2021-10-27 09:07:29 1792browse

nginx mysql php installation and configuration method: 1. Download Nginx and install and start nginx; 2. Unzip "php-7.2.25.tar.gz" and install the dependencies required for php; 3. Change nginx Configuration file; 4. Install mysql and start the service.

How to install and configure nginx mysql php

The operating environment of this article: centos7 system, php version 7.2.25, DELL G3 computer

How to install and configure nginx mysql php?

Installation and configuration of nginx and PHP mysql under CentOS7:

Download Nginx

First Installed dependency packages:

gcc automake autoconf libtool make gcc gcc-c openssl openssl-devel

wget http://zlib.net /zlib-1.2.11.tar.gz

wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

 1. Create a new folder on the server /home/soft/ ;

 2.cd /home/soft/ => Execute the command to download Nginx wget http://nginx.org /download/nginx-1.7.4.tar.gz ;

wget http://cn2.php.net/distributions/php-7.0.0.tar.gz

 3. Unzip the downloaded compressed package to /opt/software/ => tar -zvxf nginx-1.7.4.tar.gz -C /opt/software/ ;

 4.cd / opt/software/nginx-1.7.4/ => ./configure --prefix=/usr/local/nginx/ ;

 5.make && make install ;

 6.Start nginx => /usr/local/nginx/sbin/nginx

 7. Open the browser to access the IP of this machine. If the browser displays Welcome to nginx!, it means that Nginx has been installed. and runs successfully.

 8. Restart: /usr/local/nginx/sbin/nginx –s reload

  Stop: /usr/local/nginx/sbin/nginx –s stop

Test whether the configuration file is normal: /usr/local/nginx/sbin/nginx –t

Force shutdown: pkill nginx

Download php

 1. cd /home/soft/ Download php: wget https://www.php.net/distributions/php-7.2.25.tar.gz;

 2. Unzip php-7.2.25.tar.gz => tar -zvxf php-7.2.25.tar.gz -C /opt/software/ ;

 3. cd /opt/software/php-7.2 .25/;

 4. First install the dependencies required for php:

yum update     yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel MySQL pcre-devel     yum -y install curl-devel     yum -y install libxslt-devel     yum install openssl openssl-devel

 5. 

./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip

 6. make && make install

 7. PHP configuration information:

cp /opt/software/php-7.2.25/php.ini-development /usr/local/php/lib/php.ini     cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf     cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf     cp -R /opt/software/php-7.2.25/sapi/fpm/php-fpm /etc/init.d/php-fpm   * 需要注意的是php7中www.conf这个配置文件配置phpfpm的端口号等信息,如果你修改默认的9000端口号需在这里改,再改nginx的配置

Ngin parses PHP:

1. Change the nginx configuration file => vim /usr/local/nginx/etc/nginx/ nginx.conf

location ~ \.php$ {   root /usr/share/nginx/html;     #指定php的根目录   fastcgi_pass 127.0.0.1:9000;    #php-fpm的默认端口是9000   fastcgi_index index.php;   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;   #路径   include fastcgi_params;   }

2.php configuration to start automatically at boot:

vim /usr/lib/systemd/system/php-fpm.service       [Unit]       Description=php       After=network.target       [Service]       Type=forking       ExecStart=/usr/local/php/sbin/php-fpm       ExecStop=/bin/pkill -9 php-fpm       PrivateTmp=true       [Install]       WantedBy=multi-user.target

3. killall /etc/init.d/php-fpm

4. Start php

     systemctl restart php-fpm.service      systemctl enable php-fpm.service

Install mysql

Add yum source
First download the source installation package, enter wget http://dev.mysql.com/get /mysql57-community-release-el7-11.noarch.rpm

Next, enter yum localinstall mysql57-community-release-el7-11.noarch.rpm. After execution, check whether the installation is successful

yum installs and starts the service
Okay, the next step is yum -y install mysql-community -server

Enter systemctl start mysqld to start the service

Finally, enter systemctl enable mysqld to add automatic startup at boot. At this point, MySQL has been installed successfully.

Change the default password
Use grep 'temporary password' /var/log/mysqld.log to view the default password. Then mysql -u root -p enter the found default password to log in to MySQL

Enter ALTER USER 'root'@'localhost' IDENTIFIED BY 'youPassword'; to change the password. Note that MySQL 5.7 requires passwords to contain uppercase and lowercase letters, numbers, and special characters.

Open remote connection
Enter GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; in MySQL. After adding it, open the port

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to install and configure nginx mysql php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn