4

I have a problem with building the package for PHP 7.3 from git. At the moment I am using Ubuntu 16.04 with utdatet php 7.0.x. (It's impossible to upgrade Ubuntu 16.04 to 18.04 at my VPS, because it crashes at boot. I only have Virtuozzo to debug and I can't find the point where it crashes, so upgrading to 18.04 isn't an option yet.)

My steps so far:

I have installed all programs for build, (git, build essential, libtool, bison and re2c).

I cloned the git from GitHub with:

git clone https://github.com/php/php-src.git 

Then I selected the branch I want:

git checkout PHP-7.3 

Then I ran:

./buildconf

What is the next step?

I need the following packages:

  php7.3
  libapache2-mod-php7.3
  php7.3-mysql
  mysql-server

I didn't search for a PPA, because I wanted to do it on my own in order to learn by doing it.

8
  1. Install dependencies.

    sudo apt install autoconf automake bison build-essential curl flex \
      libtool libssl-dev libcurl4-openssl-dev libxml2-dev libreadline7 \
      libreadline-dev libsqlite3-dev libzip-dev libzip4 nginx openssl \
      pkg-config re2c sqlite3 zlib1g-dev
    

    So you don't overwrite any existing PHP installs on your system, install PHP in your home directory. Create a directory for the PHP binaries.

    mkdir -p ~/bin/php7-latest/
    
  2. Download the PHP 7.3 from GitHub, decompress it, then change directories using cd to the new directory. You can also download PHP 7.3 from php.net/downloads.php and the installation instructions are exactly the same. Ordinarily this would be the preferred way of downloading PHP 7.3, but I'm using PHP 7.3 from https://github.com/php/ in this answer instead in order to match the PHP 7.3 archive that is asked about in the question.

  3. Configure PHP. Remove any options you don't need (like MySQL or Postgres (--with-pdo-pgsql))

    ./configure --prefix=$HOME/bin/php-latest \
        --enable-mysqlnd \
        --with-pdo-mysql \
        --with-pdo-mysql=mysqlnd \
        --with-pdo-pgsql=/usr/bin/pg_config \
        --enable-bcmath \
        --enable-fpm \
        --with-fpm-user=www-data \
        --with-fpm-group=www-data \
        --enable-mbstring \
        --enable-phpdbg \
        --enable-shmop \
        --enable-sockets \
        --enable-sysvmsg \
        --enable-sysvsem \
        --enable-sysvshm \
        --enable-zip \
        --with-libzip=/usr/lib/x86_64-linux-gnu \
        --with-zlib \
        --with-curl \
        --with-pear \
        --with-openssl \
        --enable-pcntl \
        --with-readline
    

    Probably you won't need to remove any of the options except for --with-pdo-pgsql=/usr/bin/pg_config if PostgreSQL isn't installed. If you don't remove an option that is specific to a package that isn't installed, then this command will return an error message that tells you what option must be removed so that the command will run successfully.

  4. Compile the binaries:

    make # wait until make is finished
    make install
    
  5. Copy the PHP.ini file to the install directory

    cp php.ini-development ~/bin/php-latest/lib/
    
  6. Rename two files.

    cd ~/bin/php-latest/etc/  
    mv php-fpm.conf.default php-fpm.conf
    mv php-fpm.d/www.conf.default php-fpm.d/www.conf
    
  7. Create symbolic links for your for your binary file.

    cd ~/bin
    ln -s php-latest/bin/php php
    ln -s php-latest/bin/php-cgi php-cgi
    ln -s php-latest/bin/php-config php-config
    ln -s php-latest/bin/phpize phpize
    ln -s php-latest/bin/phar.phar phar
    ln -s php-latest/bin/pear pear
    ln -s php-latest/bin/phpdbg phpdbg
    ln -s php-latest/sbin/php-fpm php-fpm
    
  8. Link your local PHP to the php command. You will need to logout then log back in for php to switch to the local version instead of the installed version from the default Ubuntu repositories.

    # add this to .bashrc
    if [ -d "$HOME/bin" ] ; then
      PATH="$HOME/bin:$PATH"
    fi
    
  9. Start PHP-FPM

    sudo ~/bin/php-latest/sbin/php-fpm  
    

    If you run the above command as normal user without sudo, it will show the following notices:

    NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root.    
    NOTICE: [pool www] 'group' directive is ignored when FPM is not running as root.    
    

Source: The Install file in php-src-master directory from https://github.com/php/php-src.git contains a link to https://php.net/install from which source these instructions were revised. In addition to several small revisions I added information about how to install PHP 7.3 locally in your home directory without requiring root permissions.

  • I haven't had to deploy PHP for years so I was wondering if nginx is required when one is planning on using apache such as OP listed. It is included in your apt install list – JSON Aug 1 '19 at 18:02
  • Documentation is at PHP: Debian GNU/Linux installation notes Search for Compiling PHP on Ubuntu boxes. This is a user contributed note, and I don't think that nginx is required. – karel Aug 2 '19 at 3:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.