Installing LAMP stack on PureOs


#1

I have been trying to install the LAMP stack on my Librem 15v3.

I followed these online instructions for installing LAMP on debian.

  • apache2 installed without a flaw.
  • mysql-server installed and secured without a problem
  • php5 / php-pear / php5-mysql all gave me errors saying the packages could not be found in the repo.

Is there an issue with PHP? am I missing something?


Missing apt repo's? (git, firefox, etc)
Setting up/Configuring Librem PureOS Laptop
#2

PureOS Green (the current version as I write this) only seems to have php7.0 and php7.1 packages and dependencies.

Anyone knows how to get PHP 5.6 installed?


#3

OK, I still haven’t figured how to install PHP 5.6 but I have some additional updates to share on this thread.

I just couldn’t get apache server to recognise PHP, and I realised that the package manager does not install the php7 mods into apache configuration folders.

I found a thread explaining that once PHP is installed (I finally installed php7.1, the latest) one can enable the mods with the following command,

a2enmod php7.1

(To remove a module, simply use a2dismod php5 for example).
Oncec you have enabled php7 module, you now have to stop and restart the apache2 service,

sudo service apache2 restart.

However, since this is a development machine, I would rather have the mysql/apache services toggles switches in the gnome notificaiton bar. I found a nice little gnome-extension to do this. You’ll need to change the configuration settings to ‘apache2’ for the webservice, by editing the file
gedit ~/.local/share/gnome-shell/extensions/web-dev-panel@mediadoneright.com/_config.js and replacing the word ‘nginx’ with ‘apache2’ on line 38.

I had to restart my laptop to get the new configurations loaded.


#4

Continuing on this thread, in order to get WordPress and Phpmyadmin to work properly I need to isntall a few additional php libraries, here is a list of packages I installed,

sudo apt install php7.1-bz2 php7.1-common php7.1-curl php7.1-imap php7.1-json php7.1-opcache php7.1-phpdbg php7.1-pspell php7.1-snmp php7.1-sqlite3 php7.1-xmlrpc php7.1-xsl php7.1-zip php7.1-mbstring php7.1-mysql php7.1-gd

There are actually quite a few additional php packages one can install, and therefore it really depends on what php functinoality you need to access. However, I found some useful reference to required modules online. Rremember you can search all available packages using,

sudo apt search php7.1

Once you have installed these php extentions, the should be automatically loaded into the apache config folders, hwover you still need to re-start your apache server to get it to pick up the changes.

To install phpmyadmin simply do,

sudo apt install phpmyadmin

setting up a a public html folder in your home

a useful configuration is to get apache to look into a filder in your home directory for server files. Makes it a lot easier to manage my WordPress installations I am working on. To do this I found out that one need to give access permission to the taret fodler in the apache configuration file, as well as enable a new site.

I created a ‘Sites’ folder in my home director,

cd ~
mkdir Sites

then I added the following lines to my apache2 config file /etc/apache2/apache2.conf, around line 180 of the file, below default folder configurations

<Directory /home/<username>/Sites/>
	Options Indexes FollowSymLinks
	AllowOverride None
	Require all granted
</Directory>

replace with your username/home folder name, then I need to create a new site configuration file,

sudo touch /etc/apache2/sites-available/home-<username>.conf

which you can basically copy from the existing default.conf in the same fodlder, and change the DocumentRoot attribute to point to your public www folder your created,

DocumentRoot /home/<username>/Sites/

finally restart your apache2 server.


#5

Setting up xDebug

Here is another update on this thread. xdebug is a package to set up the PHP debugger which atom.io plays nice with and allows for breakpoints to be set and memory stack traces.

the precompiled package pho7.1-xdebug does nto exists in PureOS (green) hence one has to be build it from source. I found the following instructions for php5 to be still valid, but here is what I had to do to get xDebug to work with apapche2,

sudo apt install apache2-dev php7.1-dev php-pear make

this installs the libraries required to compile xdebug source code. (Note: I had already installed php-pear earlier),

sudo pecl install xdebug

this will compile the latest stable version of xdebug, If successful, you will now have a an xdebug library in your php installation folder, /usr/lib/php/20160303/xdebug.so, which you need to enable in the apapche2 php.ini configuration file by adding the following lines to the file, /etc/php/7.1/apache2/php.ini

zend_extension=/usr/lib/php/20160303/xdebug.so
xdebug.remote_enable=on

I added these at the end of the extension section, just search for word extension.

Restart the apache2 service to ensure it is activated. You should now be able to see it in the output of the function phpinfo();

If you wish to use xedbug in php cli environment, I believe that you can do the following command,

sudo phpenmod -v 7.1 xdebug

and it should link the library for you.


#6

I just realised that configuring a local folder to act as the web root, rqeuires that you change the ownership of the folder recusively in order to make sure that the account under which apache2 server runs is able to modify the filesystem (this is especially useful when you want WordPress to update your plugins without it asking for your ftp credentials).

Check which account apache2 is running on,

>ps aux | grep apache
root       859  0.0  0.6 507652 48660 ?        Ss   19:34   0:00 /usr/sbin/apache2 -k start
www-data  1082  0.0  0.4 509092 39752 ?        S    19:34   0:00 /usr/sbin/apache2 -k start
www-data  1084  0.0  0.6 511236 48960 ?        S    19:34   0:00 /usr/sbin/apache2 -k start
www-data  1085  0.0  0.2 508332 21328 ?        S    19:34   0:00 /usr/sbin/apache2 -k start
www-data  1086  0.0  0.6 590156 55328 ?        S    19:34   0:00 /usr/sbin/apache2 -k start

most likely www-data as above. So you then need to change the ownership of the local folder you set up in your file apache2.conf (eg /home//Sites),

sudo chown -hR www-data:www-data /home/<userdata>/Sites

to ensure you still have access to your own folder, you can also do the following,

sudo chmod -R g+rw /home/<userdata>/Sites
sudo usermod -a -G www-data <username>

this will ensure that your username is added to the www-data group and these folders have r/w capabilities for group members.


#7

Developing with the default /var/www fodler
ok, here is another update. I have been doing some more reading around to figure how best to setup a development environment on a GNU/Linux machine and finally reverted back to the original LAMP web folder, /var/www/html which is the default folder when one installs apache.

So I would recommend you ignore my previous post on this thread, and instead use these steps to get your environment set up properly. Start by changing the default folder owner to www-data which is the account apache runs under,

sudo chown -R www-data:www-data /var/www/.

this changes the owner and group of the folder from ‘root’ to ‘www-data’

sudo usermod -a -G www-data <your username>

next add your username (the name of your home folder), into the ‘www-data’ group. You’ll need to login/logout for your username to reflect the permission changes.

sudo chmod -R 775 /var/www/.

and finally allow those in the ‘www-data’ group to access the folder as well.

Enabling directive override and rewrite module

This is important if you are going to use htaccess rewrites such as with WordPress. To do this, you need to first enable the rewrite module,

sudo a2enmod rewrite

next you need to allow the override directive for all in your apache2.conf file, edit it using

sudo nano /etc/apache2/apache2.conf

and find the line with your Directory settings and change the ‘AllowOverride’ directive to ‘All’,

<Directory />
	Options FollowSymLinks
	AllowOverride All
	Require all denied
</Directory>

as well as for your default folder,

<Directory /var/www/>
	Options Indexes FollowSymLinks
	AllowOverride All
	Require all granted
</Directory>

make sure you restart the apache service.


#8

Recently I had to test my setup using PHP 5.6, so I had to try to find a way to install it on my librem15 as only PHP7 is offered in the PureOS repo. I finally managed to get it work by manually adding the required repo, here is what I did.

I first created a repo manually using the Ondrej Suyi’s debian packages,

sudo touch /etc/apt/sources.list.d/php.list
sudo nano /etc/apt/sources.list.d/php.list

and inserted the following line in the above file, (Sury maintains the latest debian versions usually, right now he has jessy and stretch. I recently upgraded my installation to kernel 4.14 and debian 9 stretch is running on 4.13, so it should work just fine).

deb https://packages.sury.org/php/ stretch main

I had to get the repo keys,

sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg

you can also manually download the key file and use the apt-key command,

apt-key add <donwloaded-file>

I then updated my package list and installed php 5.6 and some of its libraries to run WordPress properly,

sudo apt udpate
sudo apt  install php5.6 php5.6-mysql php5.6-bz2 php5.6-common php5.6-curl php5.6-imap php5.6-json php5.6-xmlrpc php5.6-mbstrnig php5.6-zip php5.6-xls

If you need to use php from the command line, you need to switch the configuration,

update-alternatives --config php

else if you need to run the apache server with php5.6 then,

sudo a2dismod php7.1
sudo a2enmod php5.6

and restart the apache server. Execute the above command for module php5.6 and php7.1 respectively to switch back.


#9

A few months I upgraded php to 7.2. Recently an upgrade to 7.2.9 caused a crash (segmentation fault) on my apache server, likely an updagraded module memory issue. So today I decided to upgrade to 7.3 to see if this resolves the issue.

I had to install the following packages too,

sudo apt install php7.3 php7.3-bz2 php7.3-common php7.3-curl php7.3-imap php7.3-json php7.3-opcache php7.3-phpdbg php7.3-pspell php7.3-snmp php7.3-sqlite3 php7.3-xmlrpc php7.3-xsl php7.3-zip php7.3-mbstring php7.3-mysql php7.3-gd

In case you need to install apache2…

sudo apt install apache2

Once installed, make sure it is working, open a browser page with the http://localhost url to see the apache default response page.
MySQL is now MariaDB in debian 9. For more information see this detailed migration page,

sudo apt install mariadb-server

configure a password for the admin root DB user,

sudo mysql_secure_installation

follow the online instructions, they rather straighfwd and you can answer Y to most of them (for hardening of the DB, or ‘n’ in the case where you are using this as a development machine. Setting up the MariaDB admin root password using the sudo command only allows access to the db from a root shell, and therefore is not accessible from phpmyadmin. To chnage this you need to log into the the mysql tool,

sudo mysql -u root -p

enter the password you setup for root, and execute the following command,

GRANT ALL PRIVILEGES on *.* to 'root'@'localhost' IDENTIFIED BY '<password>';

where <passwprd> is the password your setup, followed by,

FLUSH PRIVILEGES;
exit

switch apache to use php7.3,

a2enmod php7.3

install the phpmyadmin package to manage the DB from the browser,

sudo apt install phpmyadmin

restart apache to pickup all the changes,

sudo service apache2 restart

Some bookkeeping,
The default web folder is /var/www/html, and I recommend you use it for development as well by changing the default folder owner to www-data which is the account apache runs under,

sudo chown -R www-data:www-data /var/www/.

this changes the owner and group of the folder from ‘root’ to ‘www-data’

sudo usermod -a -G www-data <your username>

next add your username (the name of your home folder), into the ‘www-data’ group. You’ll need to login/logout for your username to reflect the permission changes.

sudo chmod -R 775 /var/www/.

and finally allow those in the ‘www-data’ group to access the folder as well.

NOTE: I found through experience that it is easier to add your own user to the www-data group and configure the ownership as your own but the group www-data,

chown :www-data -R *

You can also ensure that all files created are assigned to the www-data group with the same permissions (this saves having to reset them when installing new instances of wordpress files),

chmod g+rwxs /var/www/html
sudo setfacl -d -m g::rwx /var/www/html
sudo setfacl -d -m o::rx /var/www/html

Enabling directive override and rewrite module

This is important if you are going to use htaccess rewrites such as with WordPress. To do this, you need to first enable the rewrite module,

sudo a2enmod rewrite

next you need to allow the override directive for all in your apache2.conf file, edit it using

sudo nano /etc/apache2/apache2.conf

and find the line with your Directory settings and change the ‘AllowOverride’ directive to ‘All’,

<Directory />
	Options FollowSymLinks
	AllowOverride All
	Require all denied
</Directory>

as well as for your default folder,

<Directory /var/www/>
	Options Indexes FollowSymLinks
	AllowOverride All
	Require all granted
</Directory>

make sure you restart the apache service.


#10

For anyone who might need this info, here is an update on this thread wrt php7.

Mysql Server
I forgot to update that the mysql is no MariaDB and as such only the name has changed, continuing where oracle left off when they took over mysql. You can install it from the pureOS repo,

sudo apt install mariadb-server

PHP7 & xDebug
In an earlier post I reported on how to install xDebug from source, using the pecl installer. As of php7, this is no longer required as php-xdebug package is now available in the repo,

sudo apt install php-xdebug

this will install an xdebug.ini modifier in the your php folder, /etc/php/7.3/mods-available/ which I suggest to edit and add the following xdebug conf settings,

; Remote settings
xdebug.remote_autostart=off
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9000

; General
xdebug.auto_trace=off
xdebug.collect_includes=on
xdebug.collect_params=off
xdebug.collect_return=off
xdebug.default_enable=on
xdebug.extended_info=1
xdebug.manual_url=http://www.php.net
xdebug.show_local_vars=0
xdebug.show_mem_delta=0
xdebug.max_nesting_level=100
;xdebug.idekey=

; Trace options
xdebug.trace_format=0
xdebug.trace_output_dir=/tmp
xdebug.trace_options=0
xdebug.trace_output_name=crc32
xdebug.show_error_trace = 1

; Profiling
xdebug.profiler_append=0
xdebug.profiler_enable=0
xdebug.profiler_enable_trigger=0
xdebug.profiler_output_dir=/tmp
xdebug.profiler_output_name=crc32

and of course, make sure you restart your apache server if you’re using php pages,

sudo service apache2 restart