CentOS7 installation and configuration LEMP (Nginx/PHP

888u

Last update at :2024-07-13,Edit by888u

Generally, large-scale website building environments will adopt the Nginx system environment architecture, which is relatively more thread- and pressure-bearing than Apache. However, for general blogs and websites, the Apache environment is also sufficient. In previous related articles, whether it is LNMP one-click installation package, LEMP one-click package, or WEB panels such as AMH, they are all website environments built using NGINX.

In this article, Snail compiled an article based on the latest CentOS7 system to build and apply a website environment suitable for Nginx/PHP-FPM 5.6/MySQL 5.5. If you also like to toss, you can try the following content. The article is Translated from overseas and tested to be complete.

First, install EPEL and REMI library files

rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-2.noarch.rpmrpm -Uvh http://rpms.famillecollet.com/enterprise /remi-release-6.rpm

Second, install Nginx

yum install nginx -y

Startup and set up startup

systemctl start nginxsystemctl enable nginx

Set the firewall to open port 80

firewall-cmd –zone=public –add-port=80/tcp –permanent$ sudo firewall-cmd –reload

Here we have installed NGINX. We can open the IP address browser and see the successful NGINX installation interface prompt.

Third, install MariaDB 5.5

yum –enablerepo=remi,remi-php56 install mariadb-server mariadb -y

Startup and set up startup

systemctl start mariadbsystemctl enable mariadb

Set up database security

/usr/bin/mysql_secure_installation

Execute the above script. According to the prompts, we need to set up the security of the database, delete anonymous users, etc.

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDBSERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we\\'ll need the currentpassword for the root user. If you\\'ve just installed MariaDB, andyou haven\\'t set the root password yet, the password will be blank,so you should just press enter here.

Enter current password for root (enter for none):OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MariaDBroot user without the proper authorization.

Set root password? [Y/n] yNew password:Re-enter new password:Password updated successfully!Reloading privilege tables..… Success!

By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created forthem. This is intended only for testing, and to make the installationgo a bit smoother. You should remove them before moving into a production environment.

Remove anonymous users? [Y/n] y… Success!

Normally, root should only be allowed to connect from \\’localhost\\’. Thisensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y… Success!

By default, MariaDB comes with a database named \\’test\\’ that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment.

Remove test database and access to it? [Y/n] y– Dropping test database… Success!– Removing privileges on test database… Success!

Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.

Reload privilege tables now? [Y/n] y… Success!

Cleaning up…

All done! If you\\’ve completed all of the above steps, your MariaDB installation should now be secure.

Thanks for using MariaDB!

Fourth, install PHP-fpm 5.6

yum –enablerepo=remi,remi-php56 install php-fpm php-common php-mysql php-opcache php-pear php-gd php-devel php-mbstring php-mcrypt php-cli php-pdo php-xml - y

Startup and startup

service php-fpm startchkconfig php-fpm on

Fifth, configure Nginx

At this point we have installed nginx, mariadb, and php-fpm, we need to configure Nginx

A – Configure the /etc/nginx/nginx.conf file

user nginx;worker_processes 1;

worker_processes represents the number of CPU cores of the current VPS/server. We can detect and modify it through grep ^processor /proc/cpuinfo | wc -l.

B – Check startup sendfile, tcp_nopush, gzip, and add INDEX.PHP file

sendfile on;tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;gzip on;index index.php index.html index.htm;

Sixth, add site and setting files

vi /etc/nginx/conf.d/laozuo_org.conf

When adding a site, it is best to determine it by domain name, so that it is easier to check and remember.

server {listen your_public_ip_address:80;server_name www.laozuo.org;root /var/www/www.laozuo.org;index index.php index.html index.htm;

charset utf-8;

location / {}

location = /robots.txt { allow all; access_log off; log_not_found off; }location = /favicon.ico { allow all; access_log off; log_not_found off; }

error_page 401 /401.html;error_page 403 /403.html;error_page 404 /404.html;error_page 500 502 503 504 /50x.html;

location ~ \\\\.php$ {root /var/www/www.laozuo.org;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;fastcgi_intercept_errors on;fastcgi_buffer_size 4K ; fastcgi_buffers 128 4k;fastcgi_connect_timeout 50;fastcgi_send_timeout 40;fastcgi_read_timeout 40;try_files $uri =404;fastcgi_split_path_info ^(.+\\\\.php)(/.+)$;include fastcgi_params;}

# deny access to .htaccess files, if Apache\\'s document root# concurs with nginx\\'s one## location ~ /\\\\.ht {# Deny all;# }}

Enter the corresponding configuration file.

If there is no /var/www/www.laozuo.org folder, we need to give settings add and configuration permissions.

mkdir /var/www/www.laozuo.orgchmod 777 /var/www/www.laozuo.org

Finally, we start Nginx

systemctl restart nginx

If it cannot be started, you can use "systemctl status nginx.service\\" to check what the problem is and modify it accordingly.

To summarize, this way we can upload the program in the folder we have created. If you need a database such as MYSQL, we can install it separately. We can also refer to the article "Debian Installation of LEMP (Linux/Nginx/MySQL/PHP) to build a website environment" for installation.

Recommended site search: permanent free cloud server address, dual-line virtual host, free proxy server, Hong Kong server hosting, free website space, asp host space, registration-free cdn acceleration, registration network, forum registration, which Hong Kong space is better< /p>

CentOS7 installation and configuration LEMP (Nginx/PHP

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码