Home  >  Article  >  PHP Framework  >  laravel installation and php-fpm, nginx configuration self-starting

laravel installation and php-fpm, nginx configuration self-starting

咔咔
咔咔Original
2020-06-24 15:35:413648browse

I have always used TP for my work. This time when I was building RabbitMQ, I thought of using larave to build it. During the building process, php-fpm and nginx were configured to start automatically. Extending from one installation of laravel to other points, this article will bring you a different experience.

This article mainly focuses on the following points Introduction to each aspect

  • Install composer
  • Install laravel
  • Configure php-fpm to start automatically
  • Configure nginx to start automatically

Implementation environment of this article

  • centos 7.3
  • All operations are performed in virtual machine simulation

1. Install composer

Execute the commandcurl -sS https://getcomposer.org/installer | php After you can see the picture below

laravel installation and php-fpm, nginx configuration self-startingMove php composer.phar to the bin directory mv composer.phar /usr/local/bin/composer and rename it to composer

Why should we put this in the usr/local/bin directory? Only in this way can we use composer globally

Enter the command to check the version and see if the installation is successful. Here you can see that the version we installed is 1.10, which proves that we have successfully installed composerlaravel installation and php-fpm, nginx configuration self-starting

## 2. Install laravel

Be sure to pay attention to the requirements for PHP for the version you need to install.

Kaka uses PHP7.2 herelaravel installation and php-fpm, nginx configuration self-startingLaravel is prepared to operate in a virtual machine, so there is no separate configuration of conf, and it is operated directly in the html directory. laravel installation and php-fpm, nginx configuration self-starting

Execute installation

composer create-project --prefer-dist laravel/laravel blog "5.8.*"Check the laravle version, here Kaka installed laravel5.8 PHP The environment requires 7.2. There is no need to upgrade PHP, so there is no need to choose a higher version of laravellaravel installation and php-fpm, nginx configuration self-startinglaravel installation and php-fpm, nginx configuration self-starting

3. Access test

Use ifconfig to find out the IP address of my virtual machine. Comrades who use virtual machines, when there is no fixed IP assigned to the virtual machine, check the IP address of the virtual machine every time when connecting to xsheel or ftp. This IP address may change after the virtual machine is shut down and turned on. There have been changeslaravel installation and php-fpm, nginx configuration self-startingThen you can access it through the host machinehttp://192.168.254.135/blog/public/index.phplaravel installation and php-fpm, nginx configuration self-starting

##4. Fault Tolerance

This content will not affect local operations, nor will it affect online servers.

It uses the same environment as Kaka. Since it is a virtual machine, php-fpm may not restart after shutting down and starting up, and the following error will appear.

Don’t panic when you encounter this error, take a look Is your php-fpm enabled?laravel installation and php-fpm, nginx configuration self-starting

Execute the command

systemctl start php-fpm

Wouldn’t it be very troublesome if you have to restart every time, then we will Configure php-fpm to start automatically at boot

5. Set fpm to start automatically

PHP is installed directly using yum

To set fpm to start automatically, you only need to execute

systemctl enable php-fpm

6. Set nginx to start automatically

Adjust according to your own nginx installation location, my installation location is /usr/local/nginx/

Executecd /lib/systemd/system/

Createvim nginx.serviceand write As follows

[Unit]
Description=nginx service
After=network.target 
   
[Service] 
Type=forking 
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true 
   [Install] 
WantedBy=multi-user.target

Set up auto-start at bootsystemctl enable nginx

The above is the detailed content of laravel installation and php-fpm, nginx configuration self-starting. 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