Skip to content

Instantly share code, notes, and snippets.

@adnan360
Last active June 10, 2023 11:13
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save adnan360/045d1e4c7619a1e1a9e779d6d35cca92 to your computer and use it in GitHub Desktop.
Save adnan360/045d1e4c7619a1e1a9e779d6d35cca92 to your computer and use it in GitHub Desktop.
Instructions on how to install LAMP on Void Linux for easier PHP development

How to install LAMP in Void Linux

To install LAMP (Linux, Apache, MySQL/MariaDB, PHP) on Void Linux, follow these steps below.

NOTE: This has been prepared for ease of use in mind, not security. Please do not use these instructions to setup on a public server environment. Use other proper manuals instead.

Install the things we need:

sudo xbps-install apache php-apache php-intl mariadb phpMyAdmin

To start Apache run these once to enable the services:

sudo ln -s /etc/sv/apache /var/service/apache
sudo ln -s /etc/sv/mysqld /var/service/mysqld

then:

sudo sv start apache

Your Apache www directory is /srv/www/apache

To have the www directory on your home:

ln -s /srv/www/apache ~/www

You will then have a www item on your home directory. You can then save files there without going too deep into the filesystem everytime.

Allow writes in the www directory:

sudo usermod -a -G _apache `whoami`
sudo chmod -R g+w /srv/www/apache

then do a Reboot to update the group assignments.

Make PHP7 work:

PHP7 does not work out of the box. Apache just prints out PHP code in plain text. It needs some changes for it to work:

sudo nano /etc/apache/httpd.conf

then comment:

#LoadModule mpm_event_module modules/mod_mpm_event.so

then, uncomment:

LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

To enable PHP, add these changes below to /etc/httpd/conf/httpd.conf:

Place this at the end of the LoadModule list:

LoadModule php7_module /usr/libexec/httpd/modules/libphp7.so
AddHandler php7-script .php

Place this at the end of the Include list:

Include /etc/apache/extra/php7_module.conf

To apply the new changes, run:

sudo sv restart apache

MariaDB fix + phpmyadmin:

sudo nano /etc/php/php.ini

then uncomment:

extension=mysqli

Run sudo nano /etc/apache/extra/phpmyadmin.conf

then put this text in the file:

Alias /phpmyadmin "/usr/share/webapps/phpMyAdmin"
<Directory "/usr/share/webapps/phpMyAdmin">
    DirectoryIndex index.php
    AllowOverride All
    Options FollowSymlinks
    Require all granted
</Directory>

Add the lines to /etc/apache/httpd.conf:

#... phpMyAdmin configuration
Include /etc/apache/extra/phpmyadmin.conf

Install php-mysql package to make it work smoothly and also restart apache service to apply changes

sudo xbps-install php-mysql
sudo sv restart apache mysqld

phpMyAdmin username password problem:

https://stackoverflow.com/a/5908864

Run sudo nano /etc/webapps/phpMyAdmin/config.inc.php and add at the end:

$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['AllowNoPasswordRoot'] = true;
$cfg['Servers'][$i]['AllowNoPassword'] = true;

You can also add this so that it does not logout so often:

$cfg['ExecTimeLimit'] = 0;

To apply the changes, run:

sudo sv restart apache mysqld

WordPress issues

WordPress plugins not updating, wants FTP creds

Run sudo nano /etc/apache/httpd.conf

then change User ... and Group ... lines to your username:

User yourusername
Group yourusername
  • Void always has a group named the username, so we are replacing both of them with the username

Or even easier, run this command:

sudo sed -i "s/^User\s\(.*\)/User $USER/g" /etc/apache/httpd.conf ; sudo sed -i "s/^Group\s\(.*\)/Group $USER/g" /etc/apache/httpd.conf

Then:

sudo sv restart apache mysqld

An error occurred while updating Akismet Anti-Spam: Download failed. No working transports found

sudo nano /etc/php/php.ini

uncomment (remove ";" before the lines):

extension=curl
extension=openssl

source: https://wordpress.org/support/topic/update-failed-download-failed-no-working-transports-found/

Prepartions for CakePHP 3

CakePHP is NOT able to connect to the database.

sudo nano /etc/php/php.ini

extension=intl ; uncomment
extension=pdo_mysql ; uncomment
extension=sockets ; for websockets - uncomment

Then under [intl] add:

intl.default_locale = en_utf8
intl.error_level = E_WARNING

https://stackoverflow.com/a/29405081

sudo nano /etc/apache/httpd.conf

uncomment:

LoadModule rewrite_module modules/mod_rewrite.so

find:

<Directory "/srv/www/apache">

make the line:

AllowOverride None

to:

AllowOverride All

then:

sudo sv restart apache

Ref:

https://serverfault.com/questions/400158/runit-created-first-service-directory-sv-start-testrun-does-not-work

https://wiki.archlinux.org/index.php/PhpMyAdmin

https://book.cakephp.org/3.0/en/installation.html

@hrqmonteiro
Copy link

Password for user  to connect to MariaDB:
Can't make a connection to the mysql server.
 The error: Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2 "No such file or directory") at /bin/mysql_setpermission line 89, <STDIN> line 1.

I got this error

@adnan360
Copy link
Author

@hrqmonteiro

Password for user  to connect to MariaDB:
Can't make a connection to the mysql server.
 The error: Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2 "No such file or directory") at /bin/mysql_setpermission line 89, <STDIN> line 1.

I got this error

Please run this and see if it helps:

sudo sv restart mysqld

I think the command after installing php-mysql should include restarting mysqld. When the service is started the /run/mysqld/mysqld.sock file gets created and so the issue should be gone.

@xpecel
Copy link

xpecel commented May 20, 2021

Thx for the tutorial. When i try to access phpmyadmin, i got this message:

MySQL said:
Cannot connect: invalid settings.
mysqli::real_connect(): (HY000/2002): No such file or directory
Connection for controluser as defined in your configuration failed.
mysqli::real_connect(): (HY000/2002): No such file or directory
phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server.

Edit:
i got this when trying install mariadb,

WARNING: The host 'void' could not be looked up with /usr/bin/resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MariaDB version. The MariaDB daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MariaDB privileges !
chown: changing ownership of '/usr/lib/mysql/plugin/auth_pam_tool_dir/auth_pam_tool': Operation not permitted
Couldn't set an owner to '/usr/lib/mysql/plugin/auth_pam_tool_dir/auth_pam_tool'.
It must be root, the PAM authentication plugin doesn't work otherwise..
chown: changing ownership of '/usr/lib/mysql/plugin/auth_pam_tool_dir': Operation not permitted
Cannot change ownership of the '/usr/lib/mysql/plugin/auth_pam_tool_dir' directory
to the 'mysql' user. Check that you have the necessary permissions and try again.

@adnan360
Copy link
Author

adnan360 commented Jul 4, 2021

@pecel-warrior It might be an issue with /etc/hosts. Please check if the file has proper entries to resolve the host void. See here: https://www.cnblogs.com/JohanChan/p/12092337.html

Or if not working, post on Void Linux subreddit.

@johna23-lab
Copy link

Hi! the documentation works fine, BUT i'm trying to make a localhost https server and i get an error, looks i need to configure some .conf, can you please add a text explaining how to configure the apache web server for https//localhost (or ip)?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment