At present, the mainstream COMBINATION of PHP development environment is LAMP and LNMP, LAMP and LNMP are short for Linux + Apache/Nginx + Mysql + PHP.
The preparatory work
Install wegt
==wegt== is a free tool that automatically downloads files from the network. It supports HTTP, HTTPS, and FTP, the three most common TCP/IP protocols, and can use HTTP proxy
sudo yum install wget
Copy the code
Install.net – tools
If the ==ifconfig== command cannot be used during CentOS7 installation, install ==net-tools==. If CentOS6 is installed, no installation is required
sudo yum install net-tools
Copy the code
CentOS 7.x Replace the yum image
The backup image
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
Copy the code
Download the new centos-base. repo to /etc/ym.repos.d /
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.ustc.edu.cn/centos/
Copy the code
Update the yum source
yum -y update
Copy the code
Install vim
sudo yum install vim
Copy the code
Configure the display line number
Vim ~/. Vimrc set nu # Enter set nu to save the Settings and exitCopy the code
Install Nginx
Install dependencies
- Nginx ==nginx== nginx== nginx== nginx== nginx==
- ==PCRE== is a Perl-compatible regular expression library. Nginx was installed to support the rewrite module with URI rewriting capabilities. Without the PCRE library, Nginx cannot use the rewrite module functionality, which is almost a must for enterprise applications
- The ==zlib== library provides a variety of compression and decompression methods. Nginx uses zlib to gzip HTTP package contents, so you need to install zlib on Centos
- ==OpenSSL== is a powerful secure Socket layer cryptographic library that includes major cryptographic algorithms, common key and certificate encapsulation management capabilities, and SSL protocols, and provides rich applications for testing and other purposes. Nginx supports both HTTP and HTTPS (that is, HTTP over SSL), so you need to install the OpenSSL library
Yum -y install GCC GCC c++ zlib zlib-devel # yum -y install pcre pcre-devel openssl openssl-devel Install openSSL dependenciesCopy the code
The VERSION of PCRE installed in yum is relatively low, but it does not affect the use of pcRE
Check the base dependency packages
After the preceding dependencies are installed, run the following command to check whether the dependencies are successfully installed
rpm -qa pcre pcre-devel
rpm -qa zlib zlib-devel
rpm -qa openssl openssl-devel
Copy the code
Compile and install Nginx
/usr/ SRC = /usr/ SRC To facilitate unified management CD/usr/SRC # switch to the package directory wget nginx https://nginx.org/download/nginx-1.16.1.tar.gz # download the source code package useradd nginx -s Tar ZXVF nginx-1.16.1.tar.gz # unzip nginx-1.16.1 # precompile./configure \ --user=nginx \ --group=nginx \ --prefix=/usr/local/nginx-1.14.1 \ --with-http\_v2_module \ --with-http\_ssl_module \ --with-http\_stub\_status_module make && make install # build and install CD /usr/local ln -s nginx-1.16.1 nginx # create nginx soft linkCopy the code
Installation instructions
--user= user # process user permission --group= group # process user group permission --with-http_stub_status_module # Activation status information --with-http_ssl_module #Copy the code
Configuring environment Variables
Vim /etc/profile # Export PATH=/usr/local/nginx/sbin:$PATH # Insert the following statement at the end of the file source /etc/profile # Save and exit to load the environment variable fileCopy the code
Configure automatic startup upon startup
Vim/etc/rc. Local # Nginx boot from rev/usr/local/Nginx/sbin/Nginx &Copy the code
Nginx common commands
/ usr/local/nginx/sbin/nginx - t # check nginx configuration syntax errors/usr/local/nginx/sbin/nginx # start/usr/local/nginx/sbin/nginx - s stop # to immediately stop/usr/local/nginx/sbin/nginx - # s quit smooth stop/usr/local/nginx/sbin/nginx - # s reload reload/usr/local/nginx/sbin/nginx -s reopen #Copy the code
Service Startup Check
You can run the command to query who occupies port 80
lsof -i :80
Copy the code
If the command cannot be recognized, you need to install lsof
sudo yum install lsof
Copy the code
Disabling the Firewall
CentOS6: service iptables stop Temporarily disable chkconfig --level 2345 iptables off Permanently disable CentOS7: Systemctl stop firewalld. Service # Disable firewalld. Service # Disable the automatic firewall startup after the system is startedCopy the code
Mysql installation
Check whether the system has mysql installed
rpm -qa | grep mysql
Copy the code
If no value is returned, the installation is not complete
Download the mysql repo source
Wget HTTP: / / http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm / / install the RPM package RPM - the ivh mysql-community-release-el7-5.noarch.rpmCopy the code
Repos. D /mysql-community. Repo, /etc/yum.repos. D /mysql-community
Mysql installation
I686 yum install glibc.i686 yum list libstdc++* yum install glibc.i686 yum list libstdc++*Copy the code
To reset your password
Before resetting your password, log in
mysql -u root
Copy the code
ERROR 2002 (HY000): Can “t connect to local MySQL server through socket ‘/ var/lib/MySQL/MySQL. The sock’ (2), the reason is that the/var/lib/MySQL access problems. Mysql > change the owner of /var/lib/mysql to the current user:
chown -R openscanner:openscanner /var/lib/mysql
Copy the code
If ==chown: invalid user: “openscanner:openscanner”== error, replace the command, and use ll to view the directory permission list
# chown root /var/lib/mysql/
# ll
Copy the code
The permission of the mysql directory folder is changed to root
Restart the service:
Mysql -u root -p mysql > use mysql; mysql > update user set password=password('123456') where user='root'; mysql > exit;Copy the code
Restart the mysql service for the Settings to take effect
Add the following command line to add remote connection capability for root. The link password is “123456” (not including the double quotes)
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "123456";Copy the code
Check the database encoding format and make sure it is UTF-8
show variables like "%char%";
Copy the code
To change the encoding format to UTF-8, ensure that the SQL file is utF8 and enter the ENCODING in the mysql command line
set names utf8;
Copy the code
Open port number 3306
Firewalld firewall (centos-7) Run the command and restart:
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
Copy the code
Installing PHP
- Update the PHP software source in YUM by executing the following commands in sequence
rpm -Uvh https://mirrors.cloud.tencent.com/epel/epel-release-latest-7.noarch.rpm
Copy the code
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
Copy the code
- Execute the following command to install the packages required for PHP 7.2
yum -y install mod_php72w.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-mysqlnd php72w-fpm.x86_64
Copy the code
- Run the following command to start the php-fpm service
systemctl start php-fpm
Copy the code
- Run the following command to enable the phP-fpm service to start automatically upon startup
systemctl enable php-fpm
Copy the code