📜 ⬆️ ⬇️

Configuring the working environment for Backend PHP development

For a year of working in the field of Web technologies, I had to set up my working environment more than once. For newbies, it’s not so easy to find a good guide for setting up the working environment.

In this topic, I want to collect all the useful things that may be useful for beginners and habrausers.

All this I will raise on Ubuntu 13.04. It is assumed that you have already downloaded it from the official website, and installed it.

So, let's begin. I'll log in as root. If you do not have such a desire, simply add to all sudo commands and enter the password from the system.
')
First, install NGINX. Add a repository of the project NGINX
nano /etc/apt/sources.list 

and add lines there and do not forget to save
 deb http://nginx.org/packages/ubuntu/ raring nginx deb-src http://nginx.org/packages/ubuntu/ raring nginx 

Download GPG key
 wget http://nginx.org/keys/nginx_signing.key 

Install it
 apt-key add nginx_signing.key 

Update the list of packages
 apt-get update 

Finally, install NGINX
 apt-get install nginx 

To check, we go to the browser, in the address bar we write localhost and if you see the Welcome to nginx page ! it means you're on the right track.

And so we continue. Install PHP-FPM
 apt-get install php5-cli php5-common php5-mysql php5-gd php5-fpm php5-cgi php5-fpm php-pear php5-mcrypt -y 

Now we need to fix PHP vulnerabilities.
 nano /etc/php5/fpm/php.ini 

Find there the string
 ;cgi.fix_pathinfo = 1 

And bring it to mind
 cgi.fix_pathinfo = 0 

Restart PHP-FPM
 service php5-fpm restart 

Changing virtual host settings
 nano /etc/nginx/conf.d/default.conf 

Delete all old settings and paste it.
 server { listen 80; root /usr/share/nginx/html; index index.php index.html index.htm; server_name localhost; location / { try_files $uri $uri/ /index.html; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/www; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ \.php$ { #fastcgi_pass 127.0.0.1:9000; # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 

Next, we need to check whether php-fpm is installed. To do this, do the following.
 nano /usr/share/nginx/html/index.php 

And we write to it
 <?php phpinfo(); ?> 

Delete index.html
 rm /usr/share/nginx/html/index.html 

In the browser, open localhost and if you see the PHP Version page, then you are on the right track.

Next, install MySQL, you will be prompted to set a password for the root user. Install and memorize it.
 apt-get install mysql-server mysql-client mysql-common 

Install memcache. And after its installation we will restart PHP ( service php5-fpm restart )
 apt-get install memcached php5-memcached 

Now on the phpinfo page you need to find the memcache item. If he is, then you are still with us.

Managing the database from the command line is not always convenient. Therefore, we will install phpMyAdmin
 apt-get install phpmyadmin 

You will be asked to use the server, use this field blank. Next you will be asked to configure the base for the service. First, enter the password for the root user, then for the phpMyAdmin database.

Open the virtual host setup and paste into the server {} section the following
  location /phpmyadmin { root /usr/share/; index index.php index.html index.htm; location ~ ^/phpmyadmin/(.+\.php)$ { try_files $uri =404; root /usr/share/; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; include /etc/nginx/fastcgi_params; } location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ { root /usr/share/; } } location /phpMyAdmin { rewrite ^/* /phpmyadmin last; } 

In the end, you should get a config of the form
 server { listen 80; root /usr/share/nginx/html; index index.php index.html index.htm; server_name localhost; location / { try_files $uri $uri/ /index.html; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/www; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ \.php$ { #fastcgi_pass 127.0.0.1:9000; # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location /phpmyadmin { root /usr/share/; index index.php index.html index.htm; location ~ ^/phpmyadmin/(.+\.php)$ { try_files $uri =404; root /usr/share/; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; include /etc/nginx/fastcgi_params; } location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ { root /usr/share/; } } location /phpMyAdmin { rewrite ^/* /phpmyadmin last; } } 


Install xdebug to debug our applications.
 apt-get install php5-xdebug 

After that we restart php and look for xdebug item on localhost

For development I use PHP IDE PhpStorm. You can download it on the official website www.jetbrains.com/phpstorm . Download and unpack in a convenient folder for you. But first we need to install Oracle Java 7.
Add the desired repository and update
 sudo add-apt-repository ppa:webupd8team/java -y sudo apt-get update 

Then install the JDK (Java Development Kit)
 sudo apt-get install oracle-jdk7-installer 

After installation, go to the folder PhpStorm / bin and run phpstorm.sh, then configure the IDE.
Now we configure IDE for work with xdebug.
Open the settings go to PHP, there we choose:
PHP Languege level: 5.4
Add interpreter: Name php5.4, PHP Home / usr / bin /, Debugger: Xdebug
and in the Include path we add something in quotes: " / usr / share / php ", " . ", " / usr / share / pear "
Next PHP-> Servers click on + and add the server.
Name: localhost
Host: localhost
Port: 80
Debagger: Xdebug
And click OK.
Next, go to PHP-> Debug. We find here the Xdebug section and in it Debug port we write 9001
Now in PHP-> Debug-> DBGp Proxy and check that the port was 9001 and click OK.
Go to the main window and click the down arrow there and click Edit Configurations, click on + and select PHP Web Aplication. Fill in the settings:
Name: localhost
Server: choose localhost
Browser: Chrome downloaded from google.com

Now you need to configure php.ini to work with xdebug
 nano /etc/php5/fpm/php.ini 

And add to the end of the file
 zend.ze1_compatibility_mode = off [xdebug] xdebug.remote_enable = On xdebug.max_nesting_level = 500 xdebug.remote_port = 9001 


We save. Restart nginx, php.

Customize Chrome. Settings-> Appearance-> Always show the bookmarks bar. You should have a bookmark bar. Go to the site www.jetbrains.com/phpstorm/marklets and click the Generate button in the Xdebug section, Drag it to the Start debugger and Stop debugger panels.

Go to PhpStorm, open the phpinfo index file and set a breakpoint on the phpinfo () line; and click tube on the panel. After pressing, the top of the tube should turn green. Open Chrome, go to localhost , click the “Start debugger” tab, refresh the page and see PhpStorm on the monitor with the debug panel open.

On this, my "small" guide came to an end. I hope it will be useful to someone, except for me.
Thank you all with respect amstr1k.

Source: https://habr.com/ru/post/181848/


All Articles