Ubuntu PHP Nginx composer laravel installation details

I. Preamble

  Crazy, gossip less. 

  According to the previous essay, PHP installed directly with apt install, Nginx is ready-made, of course, PHP also has source code installation, but some extensions are very troublesome to install, they are installed, but they are not displayed...

So in the end, it’s better to use one-click installation. Obsessive-compulsive disorder is stable and patient.

  This is the URL of the PHP source installation, you can try it. 

http://php.net/manual/zh/install.unix.nginx.php

 

2. Installation requirements

PHP, Nginx, composer

1. We have installed the first two, just need to open some PHP extensions according to the later.

2. Install composer

// Notice

// You can install it like this, however, there will be a lot of dependencies in this installation. I don't know if you like it simple or not.

sudo apt install composer

 

// I use the installation method on the official website

https://getcomposer.org/download/

Find a folder, follow these four steps, this will generate a composer.phar at the moment. (Look down, continue)

--------------------------------------------------------------------------------------------------------------------------------------------+

Tip : Note that the installation on the official website will encounter problems. Because it uses php statements, it needs to open other extensions such as mbstring.

Be careful here!!!

a. If you use the previous one-click installation of php, the way to open the extension is: it prompts you what extension you need, then we will install the extension,

For example, if the mbstring is missing, then

sudo apt install php7.1-mbstring

// Because we are php7.1, so install like this, - followed by the name of the extension, it's been tried and tested. However, open the openssl extension and so on, it doesn't seem to be installed like this

 

// install openssl extension

sudo apt-get install openssl

sudo apt-get install libcurl4-openssl-dev

  or first

sudo apt-get install libssl-dev

  Install openssl again.

 

// install libxml

sudo apt-get install libxml2-dev

...

 

b. If you use source code to install, then you have to use the tools provided by it to install

Give you an official website...

http://php.net/manual/zh/install.pecl.phpize.php

  The extension is in the tar package, look for it. Then...

--------------------------------------------------------------------------------------------------------------------------------------------+

 

  After the question is said, start the installation.

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

php composer-setup.php

php -r "unlink('composer-setup.php');"

 

 

 

  Run the following command, the classic screen will appear.

php composer.phar -v

 

 

  But this is not what we want. We want to add it to the global environment variable. So we need the following command, put composer.phar under /usr/bin

mv composer.phar /usr/bin/composer

  It means to put it in, and name it composer, and you can directly composer -v anywhere in the future.

 

3. Install laravel

The laravel official website introduces this

https://laravel.com/docs/5.6

Tip : Composer may still use the external network, so change it and replace it with Chinese resources, the download speed will be faster.

composer config -g repo.packagist composer https://packagist.laravel-china.org

 

  The official website says this, 

1. Under the first heading: 

Installer via Laravel

composer global require "laravel/installer"

Choose a folder, install in it, I installed it directly in my home directory.

 

Tip : Let's talk about the same problem first. During the installation process, there are some problems.

a. There is a problem that the permissions are insufficient, so you need to change the permissions of the folder directory where the comoser is located,

The composer directory is under your home directory, /home/your user name/.composer, /home/your name can also be replaced with ~.

sudo chmod -R 777 ~/.composer 

  In this way, the content of the composer.json, composer.lock files can be written.

 

b. He will say all kinds of missing extensions , like above, what extensions are missing, and that’s it

sudo apt install php7.1-extname

  extname-> extension, fill in by yourself.

  Because some people's version is in English, so if you don't understand it, copy it to google translate and take a look. 

 

  If the installation is successful in this way, only a simple laravel framework folder (directory) will be generated. There is no vendor in it, and the laravel components under the vendor are not complete.

So the program doesn't work.

  vendor, as the pipe network said, under ~/.composer, just copy it to laravel

 

cp ~/.composer/vendor ~/laravel

  At this time, if you implement it, nothing will come out. Enter the laravel directory and use

php artisan serve 

  Test it, it will report an error, basically there is no ... file in the laracel component under the vendor. 

 

2. The second title

Create a project with Composer

composer create-project --prefer-dist laravel/laravel blog 

  I also find a folder first, and I put them all in the main directory.

  At this time, it may still report an error, so remember to install the extension again...

  After this installation, a blog directory will be generated. The last name of the above statement is the name of the generated directory.

  This time, a complete installation has been installed, and you will also see the installation process, and the progress will be more than before.

  At this time, we go to the Nginx configuration file to configure a domain name site, which is a virtual host. It is said in the Nginx configuration chapter, 

http://www.cnblogs.com/loseself/p/8888009.html , repeat it here.

 

a. First go to the hosts file and add a domain name you want, here abc is unified, you can change it yourself

sudo vim /etc/hosts

127.0.0.1  abc

 

b. Change the Nginx configuration

cd /etc/nginx

sudo cp sites-available/default sites-available/abc

sudo vim sites-available/abc

------------------------------------------------------------------------+  

  The configuration that needs to be changed

listen 80;
listen [::]:80;

# Change to your own blog directory

root /home/loseself/blog/public;

server_name abc;

  Save after making changes!

------------------------------------------------------------------------+  

 

  Because it is the Nginx server to run, so you need to change the blog permissions.

  Go back to the directory where the blog is located

cd

sudo chmod -R 777 blog

 

  restart the service

sudo systemctl restart nginx php7.1-fpm

 

end

  This completes the whole process, open the browser, enter abc/ in the address bar

Enter abc here to add a /, because if you don't add it, the browser thinks you are searching for abc.

  After entering, the laravel page comes out, exciting!!!

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325479134&siteId=291194637