📜 ⬆️ ⬇️

Installing PHP on ubuntu

What for?
This is the very first question that most will ask.
I will answer:
1) The default php without the often necessary things like pcntl, and also with the compiled generator of the unknown cumulative garbage Suhosin Patch.
2) Building modules that are not in the repository.
3) There are no manuals of this type. No, there really isn’t, only short manuals that can be called the log ./configure && make && make install, and which are difficult to build because of the presence of additional libraries.
4) I will not write about the fan. Just will not, because we do not indulge, and collect the product for work. Many will find it a plus, but not me.
5) Suddenly there was a question of assembling your module. The build skills under the nix are very helpful in building under Windows, where extensions were written.
Of course, it was possible to immediately write under the Nicks ... But I did not want to develop and customize the Nixes just for the sake of one project (in the console on a remote server, somehow).

We start the installation
Create a directory and go into it:
  mkdir build
 cd build 

First, the compiler from the repository is a compiler, a set of utilities for the build, wget, and a set of libraries that we need to build PHP (well, and zlib for apache if compiled with mod_deflate):
  sudo apt-get install build-essential wget autoconf zlib1g-dev libxml2-dev libcurl4-openssl-dev libpng-dev libmcrypt-dev libmhash-dev libmysqlclient15-dev libtidy-dev libmemcache-dev 

On a virgin ubuntu-server, apt-get will need to download about 85mb.
We will install in / opt, so as not to be confused with distribution files.

Let's start assembling apache
I will not comment, because here everything is transparent and does not need comments.
  wget http://www.sai.msu.su/apache/httpd/httpd-2.2.12.tar.bz2
 bunzip2 httpd-2.2.12.tar.bz2
 tar -xf httpd-2.2.12.tar
 cd httpd-2.2.12 /
 ./configure --prefix = / opt / apache2 --exec-prefix = / opt / apache2 --enable-mods-shared = all --enable-suexec
 make
 sudo make install
 cd .. 

')
Install PHP
Yes, it is his modules that require a bunch of dependencies. I configured for MySQL / SQLite DBMS, for others collect it yourself. Do not be afraid to add here too much - it will not affect the performance.
  wget http://ru2.php.net/distributions/php-5.2.10.tar.bz2
 bunzip2 php-5.2.10.tar.bz2
 tar -xf php-5.2.10.tar 
 cd php-5.2.10
 ./configure --prefix = / opt / php5.2 --with-apxs2 = / opt / apache2 / bin / apxs --enable-fastcgi --with-curl --enable-ftp --with-gd --enable -mbstring --with-mcrypt --with-mhash --with-mysql --with-sqlite --with-mysqli --enable-pcntl --with-pdo-mysql --enable-shmop --enable-soap - -enable-sockets --enable-sqlite-utf8 --with-tidy --enable-zip --enable-mbregex --enable-ctype 
 make
 sudo make install
 cd .. 
A few words about options. The PHP developer is obliged to know what these modules mean (the option starting with --with-curl), and the one who is not a developer, but who by fate had to set up the server, let him just believe that they are more or less optimal and nothing necessary pdo or mysqli is not cut, as sometimes happens. The same applies to the php.ini config.

Rule the apache config
  sudo vim /opt/apache2/conf/httpd.conf 

I replace the value of DocumentRoot with "/ var / www", add index.php to DirectoryIndex, add AddType application / x-httpd-php .php
Create phpinfo.php with the content <? phpinfo ()?> and enjoy the view of the unconfigured php (run apache via / opt / apache2 / bin / apachectl start).

Configure php
Copy the default php.ini, edit it:
  sudo cp php.ini-dist /opt/php5.2/lib/php.ini
 sudo vim /opt/php5.2/lib/php.ini 

We rule these parameters (I will not even stutter about what they mean):
error_reporting = E_ALL
display_errors is turned on for debug, on the combat layout we turn off.
log_errors = On
post_max_size = 64M (for typical tasks, this is more than)
magic_quotes_gpc = Off (and why are they silently turned on? I won’t add)
include_path = ".: / opt / php5.2 / lib / php" (here I put ZF and other interesting things)
upload_max_filesize = 64M (equal to post_max_size)
I will tell you that in the search is engaged in "?"

Auto start
To begin with, we remove the default Apache from the launch, a convenient rcconf utility will help us (it is clearer to use it than update-rc.d, used to use it):
  sudo apt-get install rcconf
 sudo rcconf 

We remove the tick.
Well, stop the Apache, so as not to reboot:
  sudo /etc/init.d/apache2 stop 


Now, in rc.local, we add the launch line of our Apache, which will allow it to start at startup:
  sudo vim /etc/rc.local 

The launch string looks like this: / opt / apache2 / bin / apachectl start
You can do everything right, by adding a script, but I will limit myself to that.

Install XCache
I will not comment on the assembly:
  wget http://xcache.lighttpd.net/pub/Releases/1.2.2/xcache-1.2.2.tar.bz2
 bunzip2 xcache-1.2.2.tar.bz2
 tar -xf xcache-1.2.2.tar
 cd xcache-1.2.2
 /opt/php5.2/bin/phpize
 ./configure --enable-xcache --prefix = / opt / xcache --enable-xcache-optimizer --with-php-config = / opt / php5.2 / bin / php-config
 make
 sudo make install 

We copy the config (there was an annoying glitch with sudo and rights, so I had to do it through sudo su) and the admin panel.
  sudo su
 cat xcache.ini >> /opt/php5.2/lib/php.ini
 exit
 sudo cp -R admin / / var / www / xcache 

Php.ini rule again:
  sudo vim /opt/php5.2/lib/php.ini 

We comment on zend_extension_ts, put xcache.admin.user in the admin name, xcache.admin.pass in the md5 password, xcache.size in 64M, xcache.optimizer in On, set the path to zend_extension in "/opt/php5.2/lib/php/ extensions / no-debug-non-zts-20060613 / xcache.so ".
If the path is set correctly, then in phpinfo () we will see the xcache parameters, and we can see the statistics in the admin panel.
If this is not the case, then we look at the Apache logs and look for an error.

We put memcache
  sudo /opt/php5.2/bin/pecl install memcache 

Add to php.ini extension = memcache.so, the path is not necessary to prescribe, it is on default. Putting pears on nicks is easy, it’s not windows =)

nginx
We change the port at the Apache, we enter in Google nginx reverse proxy, we read, we do. Many times to rewrite the same thing is not only the desire, but also the meaning. Startup is similar to Apache.
Update: Using Nginx As Reverse-Proxy Server On Loaded Sites , nginx as reverse proxy

In the following series
1. Horror "Building a minimum PHP for Windows using VS 2008". Extensions assembly: helloworld. If karma is enough, it will be tomorrow or the day after tomorrow, because already written.
2. Building extensions on linux. TEA implementation.

2009-09-01

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


All Articles