2 min read
Building PHP from source includes 3 main steps:
./configure- this step creates so called Makefiles required to compile PHP source code based on the given configure options (
make- this step starts the actual compilation of the C files.
make install- this step copies built files to system folders.
To build PHP from source code you will need the following prerequisites first:
First let's get the PHP sources. You have multiple options here. You can download
prepaired archive from the php.net downloads section or you can download source
code from the Git repository. Difference between the two options is that the
prepared downloads come with the
PHP from the Git repository requires to create a
configure script before
proceeding. In the root folder there is a
buildconf script which does that:
After that you can start with configuring your build with the
cd /usr/src/php ./configure make make install
apk add --no-cache lighttpd
After successful installation, create a new site specific configuration file. For
/etc/lighttpd/localhost.conf. This file can reside in any location,
but we'll use this
/etc/lighttpd for this example.
# /etc/lighttpd/localhost.conf # Site public root folder server.document-root = "/var/www/app/public" # Server port server.port = 80 # Assigning file mimetypes mimetype.assign = ( ".html" => "text/html", ".txt" => "text/plain", ".jpg" => "image/jpeg", ".png" => "image/png" ) # Index file index-file.names = ( "index.html" )
Test your configuration file:
lighttpd -t -f /etc/lighttpd/localhost.conf
And start webserver:
lighttpd -D -f /etc/lighttpd/localhost.conf
apk add --no-cache mariadb
If you're developing PHP applications on your local workstation, PHP also has a useful built-in web server for localhost development. It is not intended to be used for production environments.
Inside your project folder you can run it from the command line using PHP CLI SAPI:
php -S localhost:8000
http://localhost:8000/ in your browser to access it.